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-266-gda9c204


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-266-gda9c204
Date: Tue, 07 Dec 2010 09:17:32 +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=da9c204ef4ff9b89863a15bd3346331acc7b5679

The branch, master has been updated
       via  da9c204ef4ff9b89863a15bd3346331acc7b5679 (commit)
       via  0138b981d9d05173a88898085afda109fd47089d (commit)
      from  f88a8d059027ab10e2b6f0bd0f59764a6947474c (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 da9c204ef4ff9b89863a15bd3346331acc7b5679
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Dec 7 10:09:37 2010 +0200

    comsat: minor changes
    
    * libmailutils/mailbox/mailbox.c (mu_mailbox_open): Fix error
    checking condition.
    * comsat/action.c (act_getline): Remove.
    (open_rc): Return mu_stream_t. Use linecon filter.

commit 0138b981d9d05173a88898085afda109fd47089d
Author: Sergey Poznyakoff <address@hidden>
Date:   Tue Dec 7 09:18:01 2010 +0200

    Implement a "line continuation" filter.
    
    Line continuation filter removes from its input any sequence of '\\\n'
    (a backslash followed by a newline).  It is useful for reading various
    UNIX configuration files.
    
    * include/mailutils/filter.h (mu_linecon_filter): New extern.
    * libmailutils/filter/linecon.c: New file.
    * libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Add linecon.c
    * libmailutils/filter/filter.c (mu_filter_get_list): Register 
mu_linecon_filter.
    * libmailutils/tests/linecon.at: New test.
    * libmailutils/tests/Makefile.am (TESTSUITE_AT): Add linecon.at
    * libmailutils/tests/testsuite.at: Include linecon.at

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

Summary of changes:
 comsat/action.c                                    |  111 ++++++++-----------
 include/mailutils/filter.h                         |    1 +
 libmailutils/filter/Makefile.am                    |    1 +
 libmailutils/filter/filter.c                       |    1 +
 libmailutils/filter/linecon.c                      |  112 ++++++++++++++++++++
 libmailutils/mailbox/mailbox.c                     |    2 +-
 libmailutils/tests/Makefile.am                     |    1 +
 .../url-mbox.at => libmailutils/tests/linecon.at   |   39 +++++--
 libmailutils/tests/testsuite.at                    |    1 +
 9 files changed, 191 insertions(+), 78 deletions(-)
 create mode 100644 libmailutils/filter/linecon.c
 copy maidag/tests/url-mbox.at => libmailutils/tests/linecon.at (59%)

diff --git a/comsat/action.c b/comsat/action.c
index 1ec5840..483b057 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -17,6 +17,7 @@
 
 #include "comsat.h"
 #include <mailutils/io.h>
+#include <mailutils/filter.h>
 #define obstack_chunk_alloc malloc
 #define obstack_chunk_free free
 #include <obstack.h>
@@ -39,52 +40,6 @@
                  number of characters and lines in the expansion.
                 When omitted, they default to 400, 5. */
 
-static unsigned
-act_getline (FILE *fp, char **sptr, size_t *size)
-{
-  char buf[256];
-  int cont = 1;
-  size_t used = 0;
-  unsigned lines = 0;
-  
-  if (feof (fp))
-    return 0;
-  
-  while (cont && fgets (buf, sizeof buf, fp))
-    {
-      int len = strlen (buf);
-      if (buf[len-1] == '\n')
-       {
-         lines++;
-         buf[--len] = 0;
-         if (buf[len-1] == '\\')
-           {
-             buf[--len] = 0;
-             cont = 1;
-           }
-         else
-           cont = 0;
-       }
-      else
-       cont = 1;
-
-      if (len + used + 1 > *size)
-       {
-         *sptr = realloc (*sptr, len + used + 1);
-         if (!*sptr)
-           return 0;
-         *size = len + used + 1;
-       }
-      memcpy (*sptr + used, buf, len);
-      used += len;
-    }
-
-  if (*sptr)
-    (*sptr)[used] = 0;
-
-  return lines;
-}
-
 static int
 expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
 {
@@ -331,12 +286,14 @@ action_exec (FILE *tty, int argc, char **argv)
     }
 }
 
-static FILE *
+static mu_stream_t
 open_rc (const char *filename, FILE *tty)
 {
   struct stat stb;
   struct passwd *pw = getpwnam (username);
-
+  mu_stream_t stream, input;
+  int rc;
+  
   /* To be on the safe side, we do not allow root to have his .biffrc */
   if (!allow_biffrc || pw->pw_uid == 0)
     return NULL;
@@ -357,21 +314,45 @@ open_rc (const char *filename, FILE *tty)
          return NULL;
        }
     }
-  return fopen (filename, "r");
+  rc = mu_file_stream_create (&input, filename, MU_STREAM_READ);
+  if (rc)
+    {
+      if (rc != ENOENT)
+       {
+         fprintf (tty, _("Cannot open .biffrc file: %s\r\n"),
+                  mu_strerror (rc));
+         mu_diag_output (MU_DIAG_NOTICE, _("cannot open %s for %s: %s"),
+                         filename, username, mu_strerror (rc));
+       }
+      return NULL;
+    }
+  rc = mu_filter_create (&stream, input, "LINECON", MU_FILTER_DECODE,
+                        MU_STREAM_READ);
+  mu_stream_unref (input);
+  if (rc)
+    {
+      fprintf (tty, _("Cannot create filter for your .biffrc file: %s\r\n"),
+              mu_strerror (rc));
+      mu_diag_output (MU_DIAG_NOTICE,
+                     _("cannot create filter for file %s of %s: %s"),
+                     filename, username, mu_strerror (rc));
+      return NULL;
+    }
+  return stream;
 }
 
 void
 run_user_action (FILE *tty, const char *cr, mu_message_t msg)
 {
-  FILE *fp;
+  mu_stream_t input;
   int nact = 0;
-  char *stmt = NULL;
-  size_t size = 0;
-  
-  fp = open_rc (BIFF_RC, tty);
-  if (fp)
+
+  input = open_rc (BIFF_RC, tty);
+  if (input)
     {
-      unsigned n;
+      char *stmt = NULL;
+      size_t size = 0;
+      size_t n;
       char *cwd = mu_getcwd ();
       char *rcname;
       struct mu_locus locus;
@@ -380,20 +361,20 @@ run_user_action (FILE *tty, const char *cr, mu_message_t 
msg)
       free (cwd);
       if (!rcname)
         {
-          mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
-          fclose (fp);
-          return;
+         mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
+         locus.mu_file = BIFF_RC;
         }
-        
-      locus.mu_file = rcname;
+      else
+       locus.mu_file = rcname;
       locus.mu_line = 1;
       locus.mu_col = 0;
-      while ((n = act_getline (fp, &stmt, &size)))
+      while (mu_stream_getline (input, &stmt, &size, &n) == 0 && n > 0)
        {
          struct mu_wordsplit ws;
 
          ws.ws_comment = "#";
-         if (mu_wordsplit (stmt, &ws, MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT)
+         if (mu_wordsplit (stmt, &ws,
+                           MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT) == 0
              && ws.ws_wordc)
            {
              mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
@@ -443,9 +424,9 @@ run_user_action (FILE *tty, const char *cr, mu_message_t 
msg)
                } 
            }
          mu_wordsplit_free (&ws);
-         locus.mu_line += n;
+         locus.mu_line++;
        }
-      fclose (fp);
+      mu_stream_destroy (&input);
       mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
                        MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
       free (rcname);
diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index 20d4880..8c7f2e8 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -110,6 +110,7 @@ extern mu_filter_record_t mu_rfc_2047_B_filter;
 extern mu_filter_record_t mu_from_filter;
 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;
 
 enum mu_iconv_fallback_mode
   {
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index 0dc7388..38d9101 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -29,6 +29,7 @@ libfilter_la_SOURCES =\
  fromflt.c\
  header.c\
  inline-comment.c\
+ linecon.c\
  linelenflt.c\
  qpflt.c
 
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index 5b37cc6..1ebd4e9 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -80,6 +80,7 @@ mu_filter_get_list (mu_list_t *plist)
       mu_list_append (filter_list, mu_from_filter);
       mu_list_append (filter_list, mu_inline_comment_filter);
       mu_list_append (filter_list, mu_header_filter);
+      mu_list_append (filter_list, mu_linecon_filter);
       /* FIXME: add the default encodings?  */
     }
   *plist = filter_list;
diff --git a/libmailutils/filter/linecon.c b/libmailutils/filter/linecon.c
new file mode 100644
index 0000000..35d5101
--- /dev/null
+++ b/libmailutils/filter/linecon.c
@@ -0,0 +1,112 @@
+/* Simple inline comment filter for GNU Mailutils.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* linecon - a line continuation filter.
+
+   This filter has only decode mode.  It removes from the input
+   backslashes immediately followed by a newline, thus implementing
+   a familiar UNIX line-continuation facility. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/cctype.h>
+
+static enum mu_filter_result
+_linecon_decoder (void *xd, enum mu_filter_command cmd,
+                 struct mu_filter_io *iobuf)
+{
+  int *escaped = xd;
+  const unsigned char *iptr, *iend;
+  char *optr, *oend;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *escaped = 0;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  iend = iptr + iobuf->isize;
+  optr = iobuf->output;
+  oend = optr + iobuf->osize;
+
+  while (iptr < iend && optr < oend)
+    {
+      int c = *iptr++;
+      switch (c)
+       {
+       case '\\':
+         *escaped = 1;
+         continue;
+
+       case '\n':
+         if (*escaped)
+           {
+             *escaped = 0;
+             continue;
+           }
+         *optr++ = c;
+         break;
+
+       default:
+         if (*escaped)
+           {
+             *escaped = 0;
+             *optr++ = '\\';
+             if (optr == oend)
+               {
+                 iptr--;
+                 break;
+               }
+           }
+         *optr++ = c;
+       }
+    }
+
+  iobuf->isize = iptr - (const unsigned char *) iobuf->input;
+  iobuf->osize = optr - iobuf->output;
+  return mu_filter_ok;
+}
+
+static int
+alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
+{
+  *pret = malloc (sizeof (int));
+  if (!*pret)
+    return ENOMEM;
+  return 0;
+}
+
+static struct _mu_filter_record _linecon_filter = {
+  "LINECON",
+  0,
+  alloc_state,
+  NULL,
+  _linecon_decoder,
+};
+
+mu_filter_record_t mu_linecon_filter = &_linecon_filter;
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index fbf68ec..7960051 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -278,7 +278,7 @@ mu_mailbox_open (mu_mailbox_t mbox, int flag)
   if (flag & MU_STREAM_QACCESS)
     {
       /* Quick access mailboxes are read-only */
-      if (flag & (MU_STREAM_WRITE | MU_STREAM_RDWR
+      if (flag & (MU_STREAM_WRITE 
                  | MU_STREAM_APPEND | MU_STREAM_CREAT))
        return EINVAL; /* FIXME: Better error code, please? */
     }
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index b7960bf..6add3b2 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -69,6 +69,7 @@ TESTSUITE_AT = \
  fromflt.at\
  hdrflt.at\
  inline-comment.at\
+ linecon.at\
  list.at\
  mailcap.at\
  prop.at\
diff --git a/maidag/tests/url-mbox.at b/libmailutils/tests/linecon.at
similarity index 59%
copy from maidag/tests/url-mbox.at
copy to libmailutils/tests/linecon.at
index dd29ab4..c9c8eaa 100644
--- a/maidag/tests/url-mbox.at
+++ b/libmailutils/tests/linecon.at
@@ -14,21 +14,36 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([URL mode])
-AT_KEYWORDS([maidag url-mbox url])
+AT_SETUP([linecon filter])
+AT_KEYWORDS([filter decode linecon])
+sed 's/\$//' > input <<EOT
+input line 1
+input line 2
+a very\
+ long logical\
+ line spl\
+it over several physical\
+ ones
+a li\ne with \escapes
+backslash followed by a space \ $
+EOT
+sed 's/\$//' > expout <<EOT
+input line 1
+input line 2
+a very long logical line split over several physical ones
+a li\ne with \escapes
+backslash followed by a space \ $
+EOT
 
-AT_CHECK([
-echo ENVELOPE > expout
-cat $abs_top_srcdir/maidag/tests/input.msg >> expout
-echo "" >> expout
-mkdir spool
+AT_CHECK([fltst linecon decode read < input],
+[0],
+[expout])
 
-maidag MAIDAG_OPTIONS --from 'address@hidden' --url mbox:spool/out < dnl
- $abs_top_srcdir/maidag/tests/input.msg || exit $?
-sed '1s/From address@hidden/ENVELOPE/' spool/out
-],
+AT_CHECK([fltst linecon decode write < input],
 [0],
 [expout])
 
 AT_CLEANUP
- 
\ No newline at end of file
+
+
+
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index fa31189..d16cd99 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -67,4 +67,5 @@ m4_include([wicket.at])
 m4_include([prop.at])
 m4_include([inline-comment.at])
 m4_include([hdrflt.at])
+m4_include([linecon.at])
 


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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