commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-288-g1f1dca4


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-288-g1f1dca4
Date: Mon, 13 Dec 2010 09:15:56 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=1f1dca416897539ad734149945482fecf6f066e5

The branch, master has been updated
       via  1f1dca416897539ad734149945482fecf6f066e5 (commit)
      from  19e301167f703a708a41a275adc8d9fce0cb8b6b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 1f1dca416897539ad734149945482fecf6f066e5
Author: Sergey Poznyakoff <address@hidden>
Date:   Mon Dec 13 11:14:07 2010 +0200

    Re-implement iconv convertor as a regular filter.
    
    * include/mailutils/filter.h (mu_iconv_filter): New extern.
    * libmailutils/filter/iconvflt.c: New file.
    * libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Add iconvflt.c
    * libmailutils/filter/filter.c (mu_filter_get_list): Register
    mu_iconv_filter.

-----------------------------------------------------------------------

Summary of changes:
 include/mailutils/filter.h      |    3 +-
 libmailutils/filter/Makefile.am |    1 +
 libmailutils/filter/filter.c    |    1 +
 libmailutils/filter/iconvflt.c  |  251 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 255 insertions(+), 1 deletions(-)
 create mode 100644 libmailutils/filter/iconvflt.c

diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index d936688..b44964f 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -120,7 +120,8 @@ extern mu_filter_record_t mu_inline_comment_filter;
 extern mu_filter_record_t mu_header_filter;
 extern mu_filter_record_t mu_linecon_filter;
 extern mu_filter_record_t mu_linelen_filter;
-
+extern mu_filter_record_t mu_iconv_filter;
+  
 enum mu_iconv_fallback_mode
   {
     mu_fallback_none,
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index 2d5659b..9f0924e 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -29,6 +29,7 @@ libfilter_la_SOURCES =\
  fltchain.c\
  fromflt.c\
  header.c\
+ iconvflt.c\
  inline-comment.c\
  linecon.c\
  linelenflt.c\
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index 7a375fe..2709c6e 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -82,6 +82,7 @@ mu_filter_get_list (mu_list_t *plist)
       mu_list_append (filter_list, mu_header_filter);
       mu_list_append (filter_list, mu_linecon_filter);
       mu_list_append (filter_list, mu_linelen_filter);
+      mu_list_append (filter_list, mu_iconv_filter);
       /* FIXME: add the default encodings?  */
     }
   *plist = filter_list;
diff --git a/libmailutils/filter/iconvflt.c b/libmailutils/filter/iconvflt.c
new file mode 100644
index 0000000..54458f1
--- /dev/null
+++ b/libmailutils/filter/iconvflt.c
@@ -0,0 +1,251 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2004, 2005, 2007, 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+/* Iconv filter: converts input between two charsets.
+   
+   This filter operates in decode mode only.  Initialization sequence
+   requires two arguments: the name of the input encoding and that
+   of the output encoding.  Optional third argument specifies what
+   to do when an illegal character sequence is encountered on input.
+   Possible values are:
+ 
+     none       - return failure and stop further conversions;
+     copy-pass  - copy the offending character to the output verbatim;
+     copy-octal - represent it as a C octal sequence (\NNN).
+
+   The default is "copy-octal", unless overridden by mu_default_fallback_mode
+   setting (which see).
+*/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/stream.h>
+#include <mailutils/filter.h>
+#include <mailutils/errno.h>
+#include <mailutils/cstr.h>
+#include <mailutils/cctype.h>
+#include <mailutils/util.h>
+
+#ifdef HAVE_ICONV_H
+# include <iconv.h>
+#endif
+
+#ifndef ICONV_CONST
+# define ICONV_CONST
+#endif
+
+#ifndef HAVE_ICONV
+# undef iconv_open
+# define iconv_open(tocode, fromcode) ((iconv_t) -1)
+
+# undef iconv
+# define iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft) (errno = EILSEQ, 
(size_t) -1)
+
+# undef iconv_close
+# define iconv_close(cd) 0
+
+#endif 
+
+struct _icvt_filter
+{
+  char *fromcode;
+  char *tocode;
+  enum mu_iconv_fallback_mode fallback_mode;
+  iconv_t cd;           /* Conversion descriptor */
+};
+
+static enum mu_filter_result
+_icvt_decoder (void *xd,
+              enum mu_filter_command cmd,
+              struct mu_filter_io *iobuf)
+{
+  struct _icvt_filter *_icvt = xd;
+  char *ip, *op;
+  size_t ilen, olen;
+  int rc;
+    
+  switch (cmd)
+    {
+    case mu_filter_init:
+      if (mu_c_strcasecmp (_icvt->fromcode, _icvt->tocode) == 0)
+       _icvt->cd = (iconv_t) -1;
+      else
+       {
+         iconv_t cd = iconv_open (_icvt->tocode, _icvt->fromcode);
+         if (cd == (iconv_t) -1)
+           return mu_filter_failure;
+         _icvt->cd = cd;
+       }
+      return mu_filter_ok;
+
+    case mu_filter_done:
+      iconv_close (_icvt->cd);
+      free (_icvt->fromcode);
+      free (_icvt->tocode);
+      return mu_filter_ok;
+
+    default:
+      break;
+    }
+
+  if (_icvt->cd == (iconv_t) -1)
+    {
+      size_t len = iobuf->isize;
+      if (len > iobuf->osize)
+       len = iobuf->osize;
+      memcpy (iobuf->output, iobuf->input, len);
+      iobuf->isize = len;
+      iobuf->osize = len;
+      return mu_filter_ok;
+    }
+  
+  ip = (char*) iobuf->input;
+  ilen = iobuf->isize;
+  op = iobuf->output;
+  olen = iobuf->osize;
+ again:
+  rc = iconv (_icvt->cd, &ip, &ilen, &op, &olen);
+  if (rc == -1)
+    {
+      switch (errno) 
+       {
+       case E2BIG:
+         iobuf->osize += 16;
+         return mu_filter_moreoutput;
+       
+       case EINVAL:
+         /* An incomplete multibyte sequence is encountered in the input */
+         if (ilen == iobuf->isize)
+           {
+             iobuf->isize++;
+             return mu_filter_moreinput;
+           }
+         break;
+         
+       case EILSEQ:
+         switch (_icvt->fallback_mode)
+           {
+           case mu_fallback_none:
+             return mu_filter_failure;
+             
+           case mu_fallback_copy_pass:
+             *op++ = *ip++;
+             ilen--;
+             olen--;
+             break;
+             
+           case mu_fallback_copy_octal:
+             if (mu_isprint (*ip))
+               {
+                 *op++ = *ip++;
+                 ilen--;
+                 olen--;
+               }
+             else
+               {
+                 if (olen < 4)
+                   {
+                     iobuf->osize = 4;
+                     return mu_filter_moreoutput;
+                   }
+                 sprintf (op, "\\%03o", *(unsigned char*)ip);
+                 op += 4;
+                 olen -= 4;
+                 ip++;
+                 ilen--;
+               }
+           }
+         if (ilen && olen)
+           goto again;
+         break;
+             
+       default:
+         return mu_filter_failure;
+       }
+    }
+
+  iobuf->isize = ip - iobuf->input;
+  iobuf->osize = op - iobuf->output;
+  return mu_filter_ok;
+}
+
+static int
+alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
+{
+  struct _icvt_filter *flt;
+  const char *from;
+  const char *to;
+  enum mu_iconv_fallback_mode fallback_mode = mu_default_fallback_mode;
+  
+  if (argc < 3)
+    return EINVAL; /* FIXME: Provide some defaults? */
+  if (argc > 4)
+    return EINVAL;
+  
+  from = argv[1];
+  to = argv[2];
+
+  if (argc == 4)
+    {
+      const char *str = argv[3];
+      if (strcmp (str, "none") == 0)
+       fallback_mode = mu_fallback_none;
+      else if (strcmp (str, "copy-pass") == 0)
+       fallback_mode = mu_fallback_copy_pass;
+      else if (strcmp (str, "copy-octal") == 0)
+       fallback_mode = mu_fallback_copy_octal;
+      else
+       return EINVAL;
+    }
+
+  flt = calloc (1, sizeof (*flt));
+  if (!flt)
+    return ENOMEM;
+  flt->fromcode = strdup (from);
+  if (!flt->fromcode)
+    {
+      free (flt);
+      return ENOMEM;
+    }
+  flt->tocode = strdup (to);
+  if (!flt->tocode)
+    {
+      free (flt->fromcode);
+      free (flt);
+      return ENOMEM;
+    }
+  flt->fallback_mode = fallback_mode;
+  flt->cd = (iconv_t) -1;
+  *pret = flt;
+  return 0;
+}
+  
+static struct _mu_filter_record _iconv_filter = {
+  "ICONV",
+  alloc_state,
+  NULL,
+  _icvt_decoder  
+};
+
+mu_filter_record_t mu_iconv_filter = &_iconv_filter;


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]