From MAILER-DAEMON Tue Jul 01 18:19:33 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1X26Oj-0007uL-JD
	for mharc-commit-mailutils@gnu.org; Tue, 01 Jul 2014 18:19:33 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:36860)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X26Og-0007ts-Ac
	for commit-mailutils@gnu.org; Tue, 01 Jul 2014 18:19:32 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X26Oe-0004MD-E3
	for commit-mailutils@gnu.org; Tue, 01 Jul 2014 18:19:30 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:42923)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X26Oe-0004M9-9p
	for commit-mailutils@gnu.org; Tue, 01 Jul 2014 18:19:28 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X26Oc-0004ED-Ma
	for commit-mailutils@gnu.org; Tue, 01 Jul 2014 22:19:27 +0000
Date: Tue, 01 Jul 2014 22:19:26 +0000
Message-Id: <E1X26Oc-0004ED-Ma@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-679-g81ce97c
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: fc68d026ebb7685c6d6d7fd5f7675fcc0aba8c05
X-Git-Newrev: 81ce97c6ce9a7514af9597a8be356020ba51dd8e
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 01 Jul 2014 22:19: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=81ce97c6ce9a7514af9597a8be356020ba51dd8e

The branch, master has been updated
       via  81ce97c6ce9a7514af9597a8be356020ba51dd8e (commit)
      from  fc68d026ebb7685c6d6d7fd5f7675fcc0aba8c05 (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 81ce97c6ce9a7514af9597a8be356020ba51dd8e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Jul 2 01:16:42 2014 +0300

    New filter: htmlent
    
    * include/mailutils/filter.h (mu_htmlent_filter): New extern.
    * libmailutils/filter/Makefile.am: Add htmlent.c
    * libmailutils/filter/filter.c (mu_filter_get_list): Register mu_htmlent_filter.
    * libmailutils/filter/htmlent.c: New file.
    * libmailutils/tests/htmlent.at: New testcase.
    * libmailutils/tests/Makefile.am: Add new testcase.
    * libmailutils/tests/testsuite.at: Likewise.

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

Summary of changes:
 include/mailutils/filter.h      |    1 +
 libmailutils/filter/Makefile.am |    1 +
 libmailutils/filter/filter.c    |    1 +
 libmailutils/filter/htmlent.c   |  320 +++++++++++++++++++++++++++++++++++++++
 libmailutils/tests/Makefile.am  |    1 +
 libmailutils/tests/htmlent.at   |   73 +++++++++
 libmailutils/tests/testsuite.at |    1 +
 7 files changed, 398 insertions(+), 0 deletions(-)
 create mode 100644 libmailutils/filter/htmlent.c
 create mode 100644 libmailutils/tests/htmlent.at

diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index 7f39104..f6bb096 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -124,6 +124,7 @@ extern mu_filter_record_t mu_linecon_filter;
 extern mu_filter_record_t mu_linelen_filter;
 extern mu_filter_record_t mu_iconv_filter;
 extern mu_filter_record_t mu_c_escape_filter;
+extern mu_filter_record_t mu_htmlent_filter;
   
 enum mu_iconv_fallback_mode
   {
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index 1dea8b3..4dd16b0 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -29,6 +29,7 @@ libfilter_la_SOURCES =\
  fltchain.c\
  fromflt.c\
  header.c\
+ htmlent.c\
  iconvflt.c\
  inline-comment.c\
  linecon.c\
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index ccf4297..21ba158 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -84,6 +84,7 @@ mu_filter_get_list (mu_list_t *plist)
       mu_list_append (filter_list, mu_linelen_filter);
       mu_list_append (filter_list, mu_iconv_filter);
       mu_list_append (filter_list, mu_c_escape_filter);
+      mu_list_append (filter_list, mu_htmlent_filter);
       /* FIXME: add the default encodings?  */
     }
   *plist = filter_list;
diff --git a/libmailutils/filter/htmlent.c b/libmailutils/filter/htmlent.c
new file mode 100644
index 0000000..a9a0c74
--- /dev/null
+++ b/libmailutils/filter/htmlent.c
@@ -0,0 +1,320 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2014 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, 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 GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+
+/* The "htmlent" filter converts the following special HTML entities:
+
+    Decode       Encode
+   ---------+------------- 
+      <     +     &lt;
+      >     +     &gt;
+      &     +     &amp;
+ */
+
+struct transcode_map
+{
+  const char *ent;
+  size_t len;
+  int ch;
+};
+
+/* Note: entries in this array must be lexicographically sorted by the
+   ent member. */
+static struct transcode_map transcode_map[] = {
+#define S(s) s, sizeof(s) - 1
+  { S("&amp;"), '&' },
+  { S("&gt;"), '>' },
+  { S("&lt;"), '<' },
+#undef S
+  { NULL }
+};
+
+static struct transcode_map *
+ch2ent (int c)
+{
+  struct transcode_map *p;
+
+  for (p = transcode_map; p->ent; p++) 
+    {
+      if (p->ch == c)
+	return p;
+    }
+  return NULL;
+}
+
+struct htmlent_encode_state
+{
+  char buf[6];
+  int idx;
+};
+
+static enum mu_filter_result
+_htmlent_encoder (void *xd,
+		  enum mu_filter_command cmd,
+		  struct mu_filter_io *iobuf)
+{
+  struct htmlent_encode_state *cp = xd;
+  const char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      cp->idx = -1;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+
+  iptr = iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  while (isize && osize)
+    {
+      if (cp->idx > 0)
+	{
+	  *optr++ = cp->buf[--cp->idx];
+	  --osize;
+	}
+      else
+	{
+	  struct transcode_map *p;
+	  int c = *iptr++;
+	  --isize;
+	  
+	  p = ch2ent (c);
+	  if (p)
+	    {
+	      char const *q = p->ent + p->len;
+	      cp->idx = 0;
+	      while (q > p->ent)
+		cp->buf[cp->idx++] = *--q;
+	    }
+	  else
+	    {
+	      *optr++ = c;
+	      --osize;
+	    }
+	}
+    }
+  iobuf->isize -= isize;
+  iobuf->osize -= osize;
+
+  return mu_filter_ok;
+}
+
+enum htmlent_decode_phase
+  {
+    enc_init,
+    enc_map,
+    enc_rollback,
+    enc_finish
+  };
+
+struct htmlent_decode_state
+{
+  enum htmlent_decode_phase phase;
+  struct transcode_map *map;
+  int idx;
+  int pos;
+};
+
+#define DECODE_INIT(s)				\
+  do						\
+    {						\
+      (s)->phase = enc_init;			\
+      (s)->map = transcode_map;			\
+      (s)->idx = 0;				\
+    }						\
+  while (0)
+
+static enum htmlent_decode_phase
+nextchar (struct htmlent_decode_state *s, int c)
+{
+  if (c == s->map->ent[s->idx])
+    {
+      if (++s->idx == s->map->len)
+	s->phase = enc_finish;
+      else
+	s->phase = enc_map;
+    }
+  else
+    {
+      struct transcode_map *map;
+      
+      for (map = s->map; map->ent && c > map->ent[s->idx]; map++)
+	;
+      if (map->ent == NULL || c != map->ent[s->idx])
+	{
+	  if (s->idx != 0)
+	    { 
+	      s->phase = enc_rollback;
+	      s->pos = 0;
+	    }
+	  else
+	    DECODE_INIT (s);
+	}
+      else
+	{
+	  s->map = map;
+	  if (++s->idx == s->map->len)
+	    s->phase = enc_finish;
+	  else
+	    s->phase = enc_map;
+	}
+    }
+  return s->phase;
+}
+
+static enum mu_filter_result
+_htmlent_decoder (void *xd,
+		  enum mu_filter_command cmd,
+		  struct mu_filter_io *iobuf)
+{
+  struct htmlent_decode_state *cp = xd;
+  const char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      DECODE_INIT (cp);
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+
+  iptr = iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  while (isize && osize)
+    {
+      switch (cp->phase)
+	{
+	case enc_init:
+	  nextchar (cp, *iptr);
+	  if (cp->phase == enc_init)
+	    {
+	      *optr++ = *iptr;
+	      --osize;
+	    }
+	  ++iptr;
+	  --isize;
+	  break;
+	      
+	case enc_map:
+	  nextchar (cp, *iptr);
+	  if (cp->phase == enc_map || cp->phase == enc_finish)
+	    {
+	      ++iptr;
+	      --isize;
+	    }
+	  else if (cp->phase == enc_init)
+	    {
+	      *optr++ = *iptr++;
+	      --osize;
+	      --isize;
+	    }
+	  break;
+
+	case enc_finish:
+	  *optr++ = cp->map->ch;
+	  --osize;
+	  DECODE_INIT (cp);
+	  break;
+	  
+	case enc_rollback:
+	  *optr++ = cp->map->ent[cp->pos];
+	  --osize;
+	  if (++cp->pos == cp->idx)
+	    DECODE_INIT (cp);
+	  break;
+	}	  
+    }      
+  iobuf->isize -= isize;
+  iobuf->osize -= osize;
+
+  return mu_filter_ok;  
+}
+
+static int
+alloc_state (void **pret, int mode, int argc MU_ARG_UNUSED,
+	     const char **argv MU_ARG_UNUSED)
+{
+  union
+  {
+    struct htmlent_decode_state decode;
+    struct htmlent_encode_state encode;
+  } *cp;
+    
+
+  switch (mode)
+    {
+    case MU_FILTER_ENCODE:
+      cp = malloc (sizeof (cp->encode));
+      if (!cp)
+	return ENOMEM;
+      cp->encode.idx = -1;
+      break;
+
+    case MU_FILTER_DECODE:
+      cp = malloc (sizeof (cp->decode));
+      if (!cp)
+	return ENOMEM;
+      cp->decode.idx = 0;
+      cp->decode.map = transcode_map;
+      break;
+
+    default:
+      abort ();
+    }
+      
+  *pret = cp;
+  return 0;
+}
+
+static struct _mu_filter_record _htmlent_filter = {
+  "htmlent",
+  alloc_state,
+  _htmlent_encoder,
+  _htmlent_decoder,
+};
+
+mu_filter_record_t mu_htmlent_filter = &_htmlent_filter;
+
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 2338484..0126284 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -89,6 +89,7 @@ TESTSUITE_AT = \
  fsfolder01.at\
  fsfolder02.at\
  hdrflt.at\
+ htmlent.at\
  imapio.at\
  inline-comment.at\
  linecon.at\
diff --git a/libmailutils/tests/htmlent.at b/libmailutils/tests/htmlent.at
new file mode 100644
index 0000000..2670c33
--- /dev/null
+++ b/libmailutils/tests/htmlent.at
@@ -0,0 +1,73 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2014 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/>.
+
+AT_SETUP([htmlent filter])
+
+AT_KEYWORDS([filter decode encode htmlent])
+
+AT_CHECK([fltst htmlent encode read <<EOT
+<html>
+<head>
+ <title>Foo</title>
+</head>
+<body>
+  Text & more text
+</body>
+</html>
+EOT
+],
+[0],
+[&lt;html&gt;
+&lt;head&gt;
+ &lt;title&gt;Foo&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+  Text &amp; more text
+&lt;/body&gt;
+&lt;/html&gt;
+])
+
+AT_CHECK([fltst htmlent decode read <<EOT
+&lt;html&gt;
+&lt;head&gt;
+ &lt;title&gt;Foo&lt;/title&gt;
+&lt;/head&gt;
+&lt;body&gt;
+  Text &amp; more text
+&lt;/body&gt;
+&lt;/html&gt;
+EOT
+],
+[0],
+[<html>
+<head>
+ <title>Foo</title>
+</head>
+<body>
+  Text & more text
+</body>
+</html>
+])
+
+AT_CHECK([fltst htmlent decode read <<EOT
+&lt;&gt;&ampersand&amp;&gter
+EOT
+],
+[0],
+[<>&ampersand&&gter
+])
+
+AT_CLEANUP
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 3351a1d..b4b6f5f 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -85,6 +85,7 @@ m4_include([fromflt.at])
 m4_include([inline-comment.at])
 m4_include([hdrflt.at])
 m4_include([linecon.at])
+m4_include([htmlent.at])
 
 AT_BANNER(Debug Specification)
 m4_include([debugspec.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Jul 05 09:07:32 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1X3Pgi-0006Ly-Hx
	for mharc-commit-mailutils@gnu.org; Sat, 05 Jul 2014 09:07:32 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42080)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X3PgV-0006J4-1w
	for commit-mailutils@gnu.org; Sat, 05 Jul 2014 09:07:30 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X3PgI-0004cK-2A
	for commit-mailutils@gnu.org; Sat, 05 Jul 2014 09:07:18 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:47969)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X3PgH-0004c6-Ui
	for commit-mailutils@gnu.org; Sat, 05 Jul 2014 09:07:05 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X3PgG-0002j0-Su
	for commit-mailutils@gnu.org; Sat, 05 Jul 2014 13:07:05 +0000
Date: Sat, 05 Jul 2014 13:07:04 +0000
Message-Id: <E1X3PgG-0002j0-Su@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-680-g0e406bd
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 81ce97c6ce9a7514af9597a8be356020ba51dd8e
X-Git-Newrev: 0e406bd797b22703d208a396b2a870a16ae4cf0f
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 05 Jul 2014 13:07:30 -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=0e406bd797b22703d208a396b2a870a16ae4cf0f

The branch, master has been updated
       via  0e406bd797b22703d208a396b2a870a16ae4cf0f (commit)
      from  81ce97c6ce9a7514af9597a8be356020ba51dd8e (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 0e406bd797b22703d208a396b2a870a16ae4cf0f
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Jul 5 15:42:21 2014 +0300

    Implement the xml filter.
    
    * libmailutils/filter/xml.c: New file.
    * include/mailutils/filter.h (mu_xml_filter): New extern.
    * libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Add xml.c
    * libmailutils/filter/filter.c (mu_filter_get_list): Register mu_xml_filter.
    
    * libmailutils/tests/xml.at: New file.
    * libmailutils/tests/Makefile.am: Add xml.at
    * libmailutils/tests/testsuite.at: Likewise.

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

Summary of changes:
 include/mailutils/filter.h                  |    1 +
 libmailutils/filter/Makefile.am             |    3 +-
 libmailutils/filter/filter.c                |    1 +
 libmailutils/filter/xml.c                   |  600 +++++++++++++++++++++++++++
 libmailutils/tests/Makefile.am              |    1 +
 libmailutils/tests/testsuite.at             |    1 +
 libmailutils/tests/{modmesg02.at => xml.at} |   33 +-
 7 files changed, 624 insertions(+), 16 deletions(-)
 create mode 100644 libmailutils/filter/xml.c
 copy libmailutils/tests/{modmesg02.at => xml.at} (64%)

diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index f6bb096..893dfc8 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -125,6 +125,7 @@ extern mu_filter_record_t mu_linelen_filter;
 extern mu_filter_record_t mu_iconv_filter;
 extern mu_filter_record_t mu_c_escape_filter;
 extern mu_filter_record_t mu_htmlent_filter;
+extern mu_filter_record_t mu_xml_filter;
   
 enum mu_iconv_fallback_mode
   {
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index 4dd16b0..41dfe72 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -34,7 +34,8 @@ libfilter_la_SOURCES =\
  inline-comment.c\
  linecon.c\
  linelenflt.c\
- qpflt.c
+ qpflt.c\
+ xml.c
 
 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I${top_srcdir}/libmailutils
 
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index 21ba158..2ed0c72 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -85,6 +85,7 @@ mu_filter_get_list (mu_list_t *plist)
       mu_list_append (filter_list, mu_iconv_filter);
       mu_list_append (filter_list, mu_c_escape_filter);
       mu_list_append (filter_list, mu_htmlent_filter);
+      mu_list_append (filter_list, mu_xml_filter);
       /* FIXME: add the default encodings?  */
     }
   *plist = filter_list;
diff --git a/libmailutils/filter/xml.c b/libmailutils/filter/xml.c
new file mode 100644
index 0000000..f8bf8b2
--- /dev/null
+++ b/libmailutils/filter/xml.c
@@ -0,0 +1,600 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2014 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, 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 GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/cctype.h>
+
+/* In the "encode" mode, the "xml" filter takes a stream of UTF-8
+   characters as its input, converts the three XML entities as per
+   table below and replaces invalid characters (see
+   http://www.w3.org/TR/xml/#dt-charref) with their numeric character
+   reference representation as per http://www.w3.org/TR/xml/#charencoding.
+
+   In decode mode, the filter does the reverse.
+   
+   Special conversions:
+   
+    Decode       Encode
+   ---------+------------- 
+      <     +     &lt;
+      >     +     &gt;
+      &     +     &amp;
+ */
+
+struct transcode_map
+{
+  const char *ent;
+  size_t len;
+  int ch;
+};
+
+/* Note: entries in this array must be lexicographically sorted by the
+   ent member. */
+static struct transcode_map transcode_map[] = {
+#define S(s) s, sizeof(s) - 1
+  { S("&amp;"), '&' },
+  { S("&gt;"), '>' },
+  { S("&lt;"), '<' },
+#undef S
+  { NULL }
+};
+
+static struct transcode_map *
+ch2ent (int c)
+{
+  struct transcode_map *p;
+
+  for (p = transcode_map; p->ent; p++) 
+    {
+      if (p->ch == c)
+	return p;
+    }
+  return NULL;
+}
+
+struct xml_encode_state
+{
+  char buf[11]; /* Enough to acomodate &#x10FFFF; - max. UTF-8 codepoint */
+  int idx;
+};
+
+static int
+utf8_char_width(unsigned char ch)
+{
+    if (ch <= 0x7f)
+        return 1;
+    if (0xc2 <= ch && ch <= 0xdf)
+        return 2;
+    if (0xe0 <= ch && ch <= 0xef)
+        return 3;
+    if (0xf0 <= ch && ch <= 0xf4)
+        return 4;
+    return 0;
+}
+
+#ifndef ENODATA
+# define ENODATA EINVAL
+#endif
+
+static int
+utf8_mbtowc (unsigned char const *s, size_t l, unsigned int *pwc)
+{
+  if (l == 0)
+    {
+      errno = ENODATA;
+      return -1;
+    }
+  
+  if (s[0] < 0x80)
+    {
+      *pwc = s[0];
+      return 1;
+    }
+
+  if (s[0] < 0xc2)
+    {
+      errno = EILSEQ;
+      return -1;
+    }
+  else if (s[0] < 0xe0)
+    {
+      if (l < 2)
+        {
+	  errno = ENODATA;
+	  return -1;
+	}
+      if (!((s[1] ^ 0x80) < 0x40))
+	{
+	  errno = EILSEQ;
+	  return -1;
+        }
+      *pwc = ((unsigned int) (s[0] & 0x1f) << 6) |
+	      (unsigned int) (s[1] ^ 0x80);
+      return 2;
+    }
+
+  if (s[0] < 0xf0)
+    {
+      if (l < 3)
+        {
+	  errno = ENODATA;
+	  return -1;
+	}
+
+      if (!((s[1] ^ 0x80) < 0x40
+	    && (s[2] ^ 0x80) < 0x40 && (s[0] >= 0xe1 || s[1] >= 0xa0)))
+	{
+	  errno = EILSEQ;
+	  return -1;
+        }
+      
+      *pwc = ((unsigned long) (s[0] & 0x0f) << 12) |
+              ((unsigned long) (s[1] ^ 0x80) << 6) |
+               (unsigned long) (s[2] ^ 0x80);
+
+      return 3;
+    }
+    if (s[0] < 0xf8)
+      {
+	if (l < 4)
+	  {
+	    errno = ENODATA;
+	    return -1;
+	  }
+
+        if (!((s[1] ^ 0x80) < 0x40 &&
+              (s[2] ^ 0x80) < 0x40 &&
+              (s[3] ^ 0x80) < 0x40 && (s[0] >= 0xf1 || s[1] >= 0x90)))
+	  {
+            errno = EILSEQ;
+            return -1;
+	  }
+
+        *pwc = ((unsigned long) (s[0] & 0x07) << 18) |
+                ((unsigned long) (s[1] ^ 0x80) << 12) |
+                ((unsigned long) (s[2] ^ 0x80) << 6) |
+                (unsigned long) (s[3] ^ 0x80);
+
+        return 4;
+      }
+    errno = EILSEQ;
+    return -1;
+}
+
+static void
+store_buf (struct xml_encode_state *cp, const char *s, size_t len)
+{
+  cp->idx = 0;
+  s += len;
+  while (len--)
+    cp->buf[cp->idx++] = *--s;
+}
+
+static void
+store_char_ref (struct xml_encode_state *cp, unsigned wc)
+{
+  char buf[11];
+  snprintf (buf, sizeof buf, "&#x%x;", wc);
+  store_buf (cp, buf, strlen (buf));
+}
+
+static enum mu_filter_result
+_xml_encoder (void *xd,
+	      enum mu_filter_command cmd,
+	      struct mu_filter_io *iobuf)
+{
+  struct xml_encode_state *cp = xd;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+  
+  switch (cmd)
+    {
+    case mu_filter_init:
+      cp->idx = -1;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+
+  iptr = (unsigned char*) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  while (osize)
+    {
+      if (cp->idx > 0)
+	{
+	  *optr++ = cp->buf[--cp->idx];
+	  --osize;
+	}
+      else if (isize == 0)
+	break;
+      else
+	{
+	  struct transcode_map *p;
+	  unsigned int c = *iptr;
+
+	  p = ch2ent (c);
+	  if (p)
+	    {
+	      store_buf (cp, p->ent, p->len);
+	      ++iptr;
+	      --isize;
+	    }
+	  else
+	    {
+	      int count = utf8_char_width (c);
+
+	      if (count == 0)
+		{
+		  store_char_ref (cp, *iptr);
+		  ++iptr;
+		  --isize;
+		}
+	      else if (count > isize)
+		{
+		  if (cmd == mu_filter_lastbuf)
+		    {
+		      store_buf (cp, (char*) iptr, isize);
+		      iptr += isize;
+		      isize = 0;
+		    }
+		  else
+		    break;
+		}
+	      else
+		{
+		  unsigned wc;
+		  int rc;
+
+		  rc = utf8_mbtowc (iptr, isize, &wc);
+		  
+		  if (rc == -1)
+		    {	
+		      store_char_ref (cp, *iptr);
+		      ++iptr;
+		      --isize;
+		    }
+		  else
+		    {
+/* http://www.w3.org/TR/xml/#dt-charref:
+
+   Character Range
+
+   Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] |
+            [#xE000-#xFFFD] | [#x10000-#x10FFFF]
+
+   (any Unicode character, excluding the surrogate blocks, FFFE, and FFFF)
+*/
+		      if (wc == 0x9
+			  || wc == 0xa
+			  || wc == 0xd
+			  || (wc >= 0x20 && wc < 0xd7ff)
+			  || (wc >= 0xe000 && wc < 0xfffd)
+			  || (wc >= 0x10000 && wc < 0x10FFFF))
+			{
+			  if (osize >= count)
+			    {
+			      memcpy (optr, iptr, count);
+			      
+			      optr += count;
+			      osize -= count;
+
+			      iptr += count;
+			      isize -= count;
+			    }
+			  else
+			    {
+			      store_buf (cp, (char*) iptr, count);
+			      iptr += count;
+			      isize -= count;
+			    }
+			}
+		      else
+			{
+                          store_char_ref (cp, wc);
+			  iptr += count;
+			  isize -= count;
+			}
+		    }
+		}
+	    }
+	}
+    }
+  iobuf->isize -= isize;
+  iobuf->osize -= osize;
+
+  return mu_filter_ok;
+}
+
+enum xml_decode_phase
+  {
+    enc_init,
+    enc_map,
+    enc_rollback,
+    enc_finish,
+    enc_char_ref,
+    enc_char_cont,
+    enc_char_rollback
+  };
+
+struct xml_decode_state
+{
+  enum xml_decode_phase phase;   /* Decoding phase */
+  struct transcode_map *map;     /* Map entry being tried */
+  char buf[11]; /* Buffer for storing &# sequence -- used for rollback.
+		   Regarding its dimension, see the comment to
+		   xml_encode_state above. */
+  int idx;      /* In enc_init and enc_map phase - index to the next
+		   character in map->ent to compare;
+		   In enc_rollback phase marks the point in map->ent where
+		   to stop rolling back.
+		   In enc_char_ref and enc_char_cont modes indicates next
+		   free slot in buf.
+		   In enc_char_rollback phase marks the point in buf where
+		   to stop rolling back.
+		*/
+  int pos;      /* In enc_rollback phase - position in
+		   map->ent of the next character  to restore.
+		   In enc_char_rollback phase - position in buf of the next
+		   character  to restore. 
+		*/
+  int base;     /* Base for converting &# references */
+  unsigned wc;  /* Wide char being constructed from a reference */
+};
+
+#define DECODE_INIT(s)				\
+  do						\
+    {						\
+      (s)->phase = enc_init;			\
+      (s)->map = transcode_map;			\
+      (s)->idx = 0;				\
+    }						\
+  while (0)
+
+static enum xml_decode_phase
+nextchar (struct xml_decode_state *s, int c)
+{
+  if (c == s->map->ent[s->idx])
+    {
+      if (++s->idx == s->map->len)
+	s->phase = enc_finish;
+      else
+	s->phase = enc_map;
+    }
+  else if (s->phase == enc_init)
+    /* nothing */;
+  else if (s->idx == 1 && c == '#')
+    {
+      s->phase = enc_char_ref;
+      s->base = 0;
+      s->wc = 0;
+      s->idx = 0;
+      s->buf[s->idx++] = '&';
+      s->buf[s->idx++] = c;
+    }
+  else
+    {
+      struct transcode_map *map;
+      
+      for (map = s->map; map->ent && c > map->ent[s->idx]; map++)
+	;
+      if (map->ent == NULL || c != map->ent[s->idx])
+	{
+	  if (s->idx != 0)
+	    { 
+	      s->phase = enc_rollback;
+	      s->pos = 0;
+	    }
+	  else
+	    DECODE_INIT (s);
+	}
+      else
+	{
+	  s->map = map;
+	  if (++s->idx == s->map->len)
+	    s->phase = enc_finish;
+	  else
+	    s->phase = enc_map;
+	}
+    }
+  return s->phase;
+}
+
+static enum mu_filter_result
+_xml_decoder (void *xd,
+	      enum mu_filter_command cmd,
+	      struct mu_filter_io *iobuf)
+{
+  struct xml_decode_state *cp = xd;
+  const char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      DECODE_INIT (cp);
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+
+  iptr = iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  while (isize && osize)
+    {
+      switch (cp->phase)
+	{
+	case enc_init:
+	  nextchar (cp, *iptr);
+	  if (cp->phase == enc_init)
+	    {
+	      *optr++ = *iptr;
+	      --osize;
+	    }
+	  ++iptr;
+	  --isize;
+	  break;
+	      
+	case enc_map:
+	  nextchar (cp, *iptr);
+	  if (cp->phase == enc_map || cp->phase == enc_finish
+	      || cp->phase == enc_char_ref)
+	    {
+	      ++iptr;
+	      --isize;
+	    }
+	  else if (cp->phase == enc_init)
+	    {
+	      *optr++ = *iptr++;
+	      --osize;
+	      --isize;
+	    }
+	  break;
+
+	case enc_finish:
+	  *optr++ = cp->map->ch;
+	  --osize;
+	  DECODE_INIT (cp);
+	  break;
+	  
+	case enc_rollback:
+	  *optr++ = cp->map->ent[cp->pos];
+	  --osize;
+	  if (++cp->pos == cp->idx)
+	    DECODE_INIT (cp);
+	  break;
+
+	case enc_char_ref:
+	  if (*iptr == 'x')
+	    {
+	      cp->base = 16;
+	      cp->buf[cp->idx++] = *iptr;
+	      ++iptr;
+	      --isize;
+	    }
+	  else
+	    cp->base = 10;
+	  cp->phase = enc_char_cont;
+	  break;
+
+	case enc_char_cont:
+	  if (*iptr == ';')
+	    {
+	      *optr++ = cp->wc;
+	      --osize;
+	      ++iptr;
+	      --isize;
+	      DECODE_INIT (cp);
+	    }
+	  else if (cp->idx < MU_ARRAY_SIZE (cp->buf) && mu_isxdigit (*iptr))
+	    {
+	      static char xdig[] = "0123456789ABCDEF";
+	      int n = strchr (xdig, mu_toupper (*iptr)) - xdig;
+	      cp->wc = cp->wc * cp->base + n;
+	      cp->buf[cp->idx++] = *iptr;
+	      ++iptr;
+	      --isize;
+	    }
+	  else
+	    {
+	      cp->phase = enc_char_rollback;
+	      cp->pos = 0;
+	    }
+	  break;
+
+	case enc_char_rollback:
+	  *optr++ = cp->buf[cp->pos++];
+	  --osize;
+	  if (cp->pos == cp->idx)
+	    DECODE_INIT (cp);
+	}
+    }      
+  iobuf->isize -= isize;
+  iobuf->osize -= osize;
+
+  return mu_filter_ok;  
+}
+
+static int
+alloc_state (void **pret, int mode, int argc MU_ARG_UNUSED,
+	     const char **argv MU_ARG_UNUSED)
+{
+  union
+  {
+    struct xml_encode_state encode;
+    struct xml_decode_state decode;
+  } *cp;
+    
+
+  switch (mode)
+    {
+    case MU_FILTER_ENCODE:
+      cp = malloc (sizeof (cp->encode));
+      if (!cp)
+	return ENOMEM;
+      cp->encode.idx = -1;
+      break;
+
+    case MU_FILTER_DECODE:
+      cp = malloc (sizeof (cp->decode));
+      if (!cp)
+	return ENOMEM;
+      cp->decode.idx = 0;
+      cp->decode.map = transcode_map;
+      break;
+
+    default:
+      abort ();
+    }
+      
+  *pret = cp;
+  return 0;
+}
+
+static struct _mu_filter_record _xml_filter = {
+  "xml",
+  alloc_state,
+  _xml_encoder,
+  _xml_decoder
+};
+
+mu_filter_record_t mu_xml_filter = &_xml_filter;
+
+
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 0126284..8f48c7d 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -111,6 +111,7 @@ TESTSUITE_AT = \
  testsuite.at\
  url.at\
  url-comp.at\
+ xml.at\
  wicket.at\
  wordsplit.at
 
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index b4b6f5f..94e26d0 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -86,6 +86,7 @@ m4_include([inline-comment.at])
 m4_include([hdrflt.at])
 m4_include([linecon.at])
 m4_include([htmlent.at])
+m4_include([xml.at])
 
 AT_BANNER(Debug Specification)
 m4_include([debugspec.at])
diff --git a/libmailutils/tests/modmesg02.at b/libmailutils/tests/xml.at
similarity index 64%
copy from libmailutils/tests/modmesg02.at
copy to libmailutils/tests/xml.at
index cac3c55..286897d 100644
--- a/libmailutils/tests/modmesg02.at
+++ b/libmailutils/tests/xml.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014 Free Software Foundation, Inc.
+# Copyright (C) 2014 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
@@ -14,25 +14,28 @@
 # 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([modify body])
-AT_KEYWORDS([modmesg02])
+AT_SETUP([xml filter])
 
-AT_CHECK([modmesg -t "word\n"],
-[0],
-[From: root
+AT_KEYWORDS([filter decode encode xml])
 
-This is a test message.
-oo
-word
+AT_CHECK([fltst xml encode read <<EOT
+<body>
+  Text & moretext
+</body>
+EOT
+],
+[0],
+[&lt;body&gt;
+  Text &amp; more&#xc;text
+&lt;/body&gt;
 ])
 
-AT_CHECK([modmesg -l 0 -t "That"],
+AT_CHECK([fltst xml decode read <<EOT
+&lt;foo&#62;text+&#x34567eadfeefbce;&#x3c;/foo&#x3e;
+EOT
+],
 [0],
-[From: root
-
-That is a test message.
-oo
+[<foo>text+&#x34567eadfeefbce;</foo>
 ])
 
 AT_CLEANUP
-


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Jul 07 08:44:42 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1X48Hi-0001Lq-1u
	for mharc-commit-mailutils@gnu.org; Mon, 07 Jul 2014 08:44:42 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:56341)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X48Hd-0001Gk-Qo
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 08:44:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X48Hb-0002fd-K6
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 08:44:37 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:42804)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X48Hb-0002fZ-ER
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 08:44:35 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X48HZ-0000sN-SE
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 12:44:34 +0000
Date: Mon, 07 Jul 2014 12:44:34 +0000
Message-Id: <E1X48HZ-0000sN-SE@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-682-g24eb3d6
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 0e406bd797b22703d208a396b2a870a16ae4cf0f
X-Git-Newrev: 24eb3d6df145f2e301a2484551a395edfd9aa8e0
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 07 Jul 2014 12:44:40 -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=24eb3d6df145f2e301a2484551a395edfd9aa8e0

The branch, master has been updated
       via  24eb3d6df145f2e301a2484551a395edfd9aa8e0 (commit)
       via  ebfd2897f2230f527d1bfdaa507674268dc513e6 (commit)
      from  0e406bd797b22703d208a396b2a870a16ae4cf0f (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 24eb3d6df145f2e301a2484551a395edfd9aa8e0
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 7 15:43:37 2014 +0300

    New example: mboxidx
    
    * examples/mboxidx.c: New file
    * examples/Makefile.am: Add mboxidx

commit ebfd2897f2230f527d1bfdaa507674268dc513e6
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 7 15:41:12 2014 +0300

    Fix memory overrun in iconv filter.
    
    * libmailutils/filter/iconvflt.c (format_octal): New function.
    (_icvt_decoder): Fix size calculations before returning mu_filter_moreoutput.
    Use format_octal instead of sprintf to avoid memory overwrite with the
    terminating nul characteter.

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

Summary of changes:
 examples/mboxidx.c             |  532 ++++++++++++++++++++++++++++++++++++++++
 libmailutils/filter/iconvflt.c |   17 ++-
 libmailutils/filter/xml.c      |    4 +-
 3 files changed, 549 insertions(+), 4 deletions(-)
 create mode 100644 examples/mboxidx.c

diff --git a/examples/mboxidx.c b/examples/mboxidx.c
new file mode 100644
index 0000000..b06f68e
--- /dev/null
+++ b/examples/mboxidx.c
@@ -0,0 +1,532 @@
+/* Convert mailbox to a Sphinx XML input.
+   Copyright (C) 2014 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/>. */
+
+/* This program takes a mailbox in arbitrary format as its only argument
+   and produces on standard output an XML stream suitable for use with
+   Sphinx for indexing the mailbox content.  Example usage in sphinx.conf:
+
+   source mbox_source
+   {
+        type = xmlpipe2
+        xmlpipe_command = /usr/local/bin/mboxidx /var/spool/archive/mbox
+   }
+
+   index mbox_idx
+   {
+        source = mbox_source
+	docinfo = extern
+        charset_type = utf-8
+	...
+   }
+*/
+
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <mailutils/mailutils.h>
+#include <fnmatch.h>
+
+mu_list_t typelist;
+mu_list_t fldlist;
+int log_to_stderr = 1;
+char *output_charset = "utf-8";
+int no_out_if_empty = 0;
+
+char *docstr[] = {
+  "usage: mboxidx [OPTIONS] MBOX",
+  "converts MBOX into a xmlpipe2 stream for Sphinx indexing engine",
+  "OPTIONS are:",
+  "",
+  "    -c CHARSET         set output charset",
+  "    -d SPEC            set debug verbosity",
+  "    -f FIELD           index header FIELD",
+  "    -F FACILITY        set syslog facility",
+  "    -L TAG             set syslog tag",
+  "    -N                 no output if nothing to index",
+  "    -S N               skip first N messages",
+  "    -s FILE            save and read status of the prior run from FILE\n",
+  "    -t GLOB            index message body if its content type matches GLOB",
+  "    -h                 display this help summary",
+  NULL
+};
+
+void
+help (int c)
+{
+  int i;
+  FILE *fp = c ? stderr : stdout;
+
+  for (i = 0; docstr[i]; i++)
+    fprintf (fp, "%s\n", docstr[i]);
+
+  exit (c);
+}
+
+
+static int
+matchstr (void const *item, void const *data)
+{
+  char const *pat = item;
+  char const *str = data;
+
+  return fnmatch (pat, str, 0);
+}
+
+struct field
+{
+  char *name;
+  int ishdr;
+};
+
+static void
+fldadd (char *name, int ishdr)
+{
+  struct field *f = mu_alloc (sizeof (*f));
+  f->name = mu_strdup (name);
+  f->ishdr = ishdr;
+  mu_list_append (fldlist, f);
+}
+
+static int
+get_hdr_value (mu_header_t hdr, const char *name, char **value)
+{
+  int status = mu_header_aget_value_unfold (hdr, name, value);
+  if (status == 0)
+    mu_rtrim_class (*value, MU_CTYPE_SPACE);
+  return status;
+}
+
+
+static int
+get_content_encoding (mu_header_t hdr, char **value)
+{
+  char *encoding = NULL;
+  if (get_hdr_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, &encoding))
+    encoding = mu_strdup ("7bit");	/* Default.  */
+  *value = encoding;
+  return 0;
+}
+
+static int
+set_charset_filter (mu_stream_t * str, char *input_charset)
+{
+  int rc;
+  char const *args[4];
+
+  mu_stream_t b_stream = *str;
+
+  args[0] = "iconv";
+  args[1] = input_charset;
+  args[2] = output_charset;
+  args[3] = "copy-octal";
+  args[4] = NULL;
+
+  rc = mu_filter_create_args (str, b_stream,
+			      "iconv",
+			      4, args, MU_FILTER_DECODE, MU_STREAM_READ);
+
+  if (rc == 0)
+    mu_stream_unref (b_stream);
+  return rc;
+}
+
+
+static void
+formatbody (mu_message_t msg, int delim)
+{
+  int rc;
+  char *type;
+  char *input_charset = NULL;
+  int ismime = 0;
+  mu_message_t msgpart;
+  mu_header_t hdr = NULL;
+
+  mu_message_get_header (msg, &hdr);
+  if (get_hdr_value (hdr, MU_HEADER_CONTENT_TYPE, &type))
+    type = mu_strdup ("text/plain");
+  else
+    {
+      struct mu_wordsplit ws;
+
+      mu_strlower (type);
+
+      ws.ws_delim = ";";
+      if (mu_wordsplit (type, &ws,
+			MU_WRDSF_DELIM | MU_WRDSF_WS
+			| MU_WRDSF_NOVAR | MU_WRDSF_NOCMD))
+	{
+	  mu_error ("can't split content type \"%s\": %s",
+		    type, mu_wordsplit_strerror (&ws));
+	}
+      else
+	{
+	  int i;
+	  
+	  type = ws.ws_wordv[0];
+	  ws.ws_wordv[0] = NULL;
+	  for (i = 1; i < ws.ws_wordc; i++)
+	    {
+	      if (strncasecmp (ws.ws_wordv[i], "charset=", 8) == 0)
+		{
+		  input_charset = mu_strdup (ws.ws_wordv[i] + 8);
+		  break;
+		}
+	    }
+	  mu_wordsplit_free (&ws);
+	}
+    }
+
+  mu_message_is_multipart (msg, &ismime);
+  if (ismime)
+    {
+      size_t i, nparts;
+
+      rc = mu_message_get_num_parts (msg, &nparts);
+      if (rc)
+	mu_diag_funcall (MU_DIAG_ERROR, "mu_message_get_num_parts", NULL, rc);
+      else
+	for (i = 1; i <= nparts; i++)
+	  {
+	    if (mu_message_get_part (msg, i, &msgpart) == 0)
+	      formatbody (msgpart, 1);
+	  }
+    }
+  else if (mu_c_strncasecmp (type, "message/rfc822", strlen (type)) == 0)
+    {
+      rc = mu_message_unencapsulate (msg, &msgpart, NULL);
+      if (rc)
+	mu_diag_funcall (MU_DIAG_ERROR, "mu_message_unencapsulate", NULL, rc);
+      else
+	formatbody (msgpart, 1);
+    }
+  else if (mu_list_locate (typelist, type, NULL) == 0)
+    {
+      char *encoding;
+      mu_body_t body = NULL;
+      mu_stream_t b_stream = NULL;
+      mu_stream_t d_stream = NULL;
+      mu_stream_t stream = NULL;
+
+      get_content_encoding (hdr, &encoding);
+
+      mu_message_get_body (msg, &body);
+      mu_body_get_streamref (body, &b_stream);
+      if (mu_filter_create (&d_stream, b_stream, encoding,
+			    MU_FILTER_DECODE, MU_STREAM_READ) == 0)
+	{
+	  mu_stream_unref (b_stream);
+	  stream = d_stream;
+	}
+      else
+	stream = b_stream;
+
+      if (!input_charset || set_charset_filter (&stream, input_charset))
+	set_charset_filter (&stream, "US-ASCII");
+
+      b_stream = stream;
+      if (mu_filter_create (&stream, b_stream, "xml",
+			    MU_FILTER_ENCODE, MU_STREAM_READ) == 0)
+	mu_stream_unref (b_stream);
+
+      if (delim)
+	mu_printf ("\n");
+      mu_stream_copy (mu_strout, stream, 0, NULL);
+
+      mu_stream_unref (stream);
+      free (encoding);
+    }
+  free (type);
+}
+
+static int
+fldfmt (void *item, void *data)
+{
+  struct field *f = item;
+  mu_message_t msg = data;
+  int rc;
+
+  mu_printf ("    <%s>", f->name);
+  if (f->ishdr)
+    {
+      mu_header_t hdr;
+      char *hfield;
+
+      mu_message_get_header (msg, &hdr);
+      rc = mu_header_aget_value_unfold (hdr, f->name, &hfield);
+      if (rc == 0)
+	{
+	  char *tmp;
+
+	  rc = mu_rfc2047_decode (output_charset, hfield, &tmp);
+	  if (rc)
+	    mu_stream_write (mu_strout, hfield, strlen (hfield), NULL);
+	  else
+	    {
+	      mu_stream_write (mu_strout, tmp, strlen (tmp), NULL);
+	      free (tmp);
+	    }
+	}
+    }
+  else
+    formatbody (msg, 0);
+
+  mu_printf ("</%s>\n", f->name);
+  return 0;
+}
+
+static int
+fldout (void *item, void *data)
+{
+  struct field *f = item;
+  mu_printf ("    <sphinx:field name=\"%s\"/>\n", f->name);
+  return 0;
+}
+
+void
+xmlpipe2_header ()
+{
+  mu_printf ("<?xml version=\"1.0\"?>\n");
+  mu_printf ("<sphinx:docset>\n");
+  mu_printf ("  <sphinx:schema>\n");
+  mu_list_foreach (fldlist, fldout, NULL);
+  mu_printf ("  </sphinx:schema>\n");
+}
+
+void
+xmlpipe2_footer ()
+{
+  mu_printf ("</sphinx:docset>\n");
+}
+
+size_t skip_count;
+size_t nmesg;
+
+void
+read_state_file (const char *name)
+{
+  FILE *fp;
+  size_t count;
+  int c;
+
+  if (access (name, F_OK))
+    {
+      if (errno == ENOENT)
+	return;
+      mu_error ("can't access state file \"%s\": %s",
+		name, mu_strerror (errno));
+      exit (1);
+    }
+
+  fp = fopen (name, "r");
+  if (!fp)
+    {
+      mu_error ("can't open state file \"%s\" for reading: %s",
+		name, mu_strerror (errno));
+      exit (1);
+    }
+
+  count = 0;
+  while ((c = fgetc (fp)) != EOF && c >= '0' && c <= '9')
+    {
+      size_t n = count * 10 + c - '0';
+      if (n < count)
+	{
+	  mu_error ("%s: message number too big", name);
+	  exit (1);
+	}
+      count = n;
+    }
+  fclose (fp);
+
+  if (c != EOF && c != '\n')
+    {
+      mu_error ("%s: malformed state file", name);
+      exit (1);
+    }
+
+  skip_count = count;
+}
+
+void
+write_state_file (const char *name)
+{
+  FILE *fp;
+
+  fp = fopen (name, "w");
+  if (!fp)
+    {
+      mu_error ("can't open state file \"%s\" for writing: %s",
+		name, mu_strerror (errno));
+      exit (1);
+    }
+
+  fprintf (fp, "%lu\n", (unsigned long) nmesg);
+
+  fclose (fp);
+}
+
+static int
+action (mu_observer_t o, size_t type, void *data, void *action_data)
+{
+  mu_mailbox_t mbox = mu_observer_get_owner (o);
+  mu_message_t msg = NULL;
+
+  switch (type)
+    {
+    case MU_EVT_MESSAGE_ADD:
+      ++nmesg;
+      if (nmesg < skip_count)
+	break;
+      if (no_out_if_empty && nmesg == skip_count)
+	xmlpipe2_header ();
+
+      MU_ASSERT (mu_mailbox_get_message (mbox, nmesg, &msg));
+      mu_printf ("  <sphinx:document id=\"%lu\">\n", (unsigned long) nmesg);
+      mu_list_foreach (fldlist, fldfmt, msg);
+      mu_printf ("  </sphinx:document>\n");
+      break;
+    case MU_EVT_MAILBOX_PROGRESS:
+      /* Noop.  */
+      break;
+    }
+  return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+  int rc;
+  mu_mailbox_t mbox;
+  mu_observer_t observer;
+  mu_observable_t observable;
+  size_t total;
+  char *p;
+  char *state_file = NULL;
+
+  mu_set_program_name (argv[0]);
+  mu_register_all_mbox_formats ();
+  mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
+
+  MU_ASSERT (mu_list_create (&fldlist));
+
+  MU_ASSERT (mu_list_create (&typelist));
+  mu_list_set_comparator (typelist, matchstr);
+  mu_list_append (typelist, mu_strdup ("text/*"));
+
+  while ((rc = getopt (argc, argv, "c:d:f:F:hL:NS:s:t:")) != EOF)
+    {
+      switch (rc)
+	{
+	case 'c':
+	  output_charset = optarg;
+	  break;
+	case 'd':
+	  mu_debug_parse_spec (optarg);
+	  break;
+	case 'F':
+	  if (mu_string_to_syslog_facility (optarg, &mu_log_facility))
+	    {
+	      mu_error ("unknown facility: %s", optarg);
+	      exit (1);
+	    }
+	  log_to_stderr = 0;
+	  break;
+	case 'f':
+	  fldadd (optarg, 1);
+	  break;
+	case 'L':
+	  mu_log_tag = optarg;
+	  break;
+	case 'N':
+	  no_out_if_empty = 1;
+	  break;
+	case 'S':
+	  skip_count = strtoul (optarg, &p, 10);
+	  if (*p)
+	    {
+	      mu_error ("invalid number: %s", optarg);
+	      exit (1);
+	    }
+	  break;
+	case 's':
+	  state_file = optarg;
+	  break;
+	case 't':
+	  p = mu_strdup (optarg);
+	  mu_strlower (p);
+	  mu_list_append (typelist, p);
+	  break;
+	case 'h':
+	  help (0);
+	default:
+	  exit (1);
+	}
+    }
+  fldadd ("content", 0);
+
+  if (state_file)
+    read_state_file (state_file);
+
+  skip_count++;
+
+  argc -= optind;
+  argv += optind;
+
+  if (argc != 1)
+    help (1);
+
+  if (log_to_stderr)
+    mu_stdstream_strerr_setup (MU_STRERR_STDERR);
+  else
+    {
+      if (!mu_log_tag)
+	mu_log_tag = (char *) mu_program_name;
+      mu_stdstream_strerr_setup (MU_STRERR_SYSLOG);
+    }
+
+  rc = mu_mailbox_create_default (&mbox, argv[0]);
+  if (rc)
+    {
+      mu_error ("mu_mailbox_create: %s", mu_strerror (rc));
+      exit (EXIT_FAILURE);
+    }
+
+  rc = mu_mailbox_open (mbox, MU_STREAM_READ);
+  if (rc)
+    {
+      mu_error ("mu_mailbox_open: %s", mu_strerror (rc));
+      exit (EXIT_FAILURE);
+    }
+
+  mu_observer_create (&observer, mbox);
+  mu_observer_set_action (observer, action, mbox);
+  mu_observer_set_action_data (observer, NULL, mbox);
+  mu_mailbox_get_observable (mbox, &observable);
+  mu_observable_attach (observable, MU_EVT_MESSAGE_ADD, observer);
+
+  if (!no_out_if_empty)
+    xmlpipe2_header ();
+  MU_ASSERT (mu_mailbox_scan (mbox, 1, &total));
+  if (!no_out_if_empty || nmesg >= skip_count)
+    xmlpipe2_footer ();
+  mu_mailbox_close (mbox);
+  mu_mailbox_destroy (&mbox);
+
+  if (state_file)
+    write_state_file (state_file);
+
+  return EXIT_SUCCESS;
+}
diff --git a/libmailutils/filter/iconvflt.c b/libmailutils/filter/iconvflt.c
index a227dc4..1d0f3db 100644
--- a/libmailutils/filter/iconvflt.c
+++ b/libmailutils/filter/iconvflt.c
@@ -76,6 +76,19 @@ struct _icvt_filter
   iconv_t cd;           /* Conversion descriptor */
 };
 
+static void
+format_octal (char *op, unsigned char n)
+{
+  op += 4;
+  *--op = n % 8;
+  n >> 3;
+  *--op = n % 8;
+  n >> 3;
+  *--op = n % 8;
+  n >> 3;
+  *--op = '\\';
+}
+
 static enum mu_filter_result
 _icvt_decoder (void *xd,
 	       enum mu_filter_command cmd,
@@ -169,10 +182,10 @@ _icvt_decoder (void *xd,
 		{
 		  if (olen < 4)
 		    {
-		      iobuf->osize = 4;
+		      iobuf->osize += 4;
 		      return mu_filter_moreoutput;
 		    }
-		  sprintf (op, "\\%03o", *(unsigned char*)ip);
+		  format_octal (op, *(unsigned char*)ip);
 		  op += 4;
 		  olen -= 4;
 		  ip++;
diff --git a/libmailutils/filter/xml.c b/libmailutils/filter/xml.c
index f8bf8b2..e1f1b54 100644
--- a/libmailutils/filter/xml.c
+++ b/libmailutils/filter/xml.c
@@ -27,8 +27,8 @@
 /* In the "encode" mode, the "xml" filter takes a stream of UTF-8
    characters as its input, converts the three XML entities as per
    table below and replaces invalid characters (see
-   http://www.w3.org/TR/xml/#dt-charref) with their numeric character
-   reference representation as per http://www.w3.org/TR/xml/#charencoding.
+   http://www.w3.org/TR/xml/#charsets) with their numeric character
+   reference representation as per http://www.w3.org/TR/xml/#dt-charref.
 
    In decode mode, the filter does the reverse.
    


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Jul 07 10:43:31 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1X4A8h-0003pB-7P
	for mharc-commit-mailutils@gnu.org; Mon, 07 Jul 2014 10:43:31 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41407)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X4A8c-0003oX-UK
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 10:43:27 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X4A8b-00060t-MM
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 10:43:26 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:44968)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X4A8b-00060o-Ja
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 10:43:25 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X4A8Z-0002QJ-V6
	for commit-mailutils@gnu.org; Mon, 07 Jul 2014 14:43:25 +0000
Date: Mon, 07 Jul 2014 14:43:24 +0000
Message-Id: <E1X4A8Z-0002QJ-V6@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-683-g2357bd1
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 24eb3d6df145f2e301a2484551a395edfd9aa8e0
X-Git-Newrev: 2357bd10a05ad5161919b8b06856b1a4d11ea777
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 07 Jul 2014 14:43:28 -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=2357bd10a05ad5161919b8b06856b1a4d11ea777

The branch, master has been updated
       via  2357bd10a05ad5161919b8b06856b1a4d11ea777 (commit)
      from  24eb3d6df145f2e301a2484551a395edfd9aa8e0 (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 2357bd10a05ad5161919b8b06856b1a4d11ea777
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 7 17:42:59 2014 +0300

    Push missing files.

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

Summary of changes:
 examples/Makefile.am |   13 +++++++++++++
 examples/mboxidx.c   |    2 +-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/examples/Makefile.am b/examples/Makefile.am
index e0076a4..e5f150b 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -35,6 +35,7 @@ noinst_PROGRAMS = \
  iconv\
  lsf\
  mblconv\
+ mboxidx\
  msg-send\
  mta\
  mucat\
@@ -122,3 +123,15 @@ muemail_LDADD = \
  ${MU_APP_LIBRARIES} \
  ${MU_LIB_MAILUTILS}
 
+mboxidx_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
+mboxidx_LDADD=\
+ ../lib/libmuaux.a\
+ ${MU_LIB_MBOX}\
+ ${MU_LIB_IMAP}\
+ ${MU_LIB_POP}\
+ ${MU_LIB_NNTP}\
+ ${MU_LIB_MH}\
+ ${MU_LIB_MAILDIR}\
+ ${MU_LIB_AUTH}\
+ @MU_AUTHLIBS@ \
+ ${MU_LIB_MAILUTILS}
diff --git a/examples/mboxidx.c b/examples/mboxidx.c
index b06f68e..ba2f1c3 100644
--- a/examples/mboxidx.c
+++ b/examples/mboxidx.c
@@ -57,7 +57,7 @@ char *docstr[] = {
   "    -L TAG             set syslog tag",
   "    -N                 no output if nothing to index",
   "    -S N               skip first N messages",
-  "    -s FILE            save and read status of the prior run from FILE\n",
+  "    -s FILE            save and read status of the prior run from FILE",
   "    -t GLOB            index message body if its content type matches GLOB",
   "    -h                 display this help summary",
   NULL


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Jul 17 08:28:47 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1X7knn-0004oy-CL
	for mharc-commit-mailutils@gnu.org; Thu, 17 Jul 2014 08:28:47 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42667)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X7knk-0004l9-BB
	for commit-mailutils@gnu.org; Thu, 17 Jul 2014 08:28:45 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X7kni-0007cf-GM
	for commit-mailutils@gnu.org; Thu, 17 Jul 2014 08:28:44 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:58231)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X7kni-0007cb-Ci
	for commit-mailutils@gnu.org; Thu, 17 Jul 2014 08:28:42 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1X7knh-0004it-8w
	for commit-mailutils@gnu.org; Thu, 17 Jul 2014 12:28:41 +0000
Date: Thu, 17 Jul 2014 12:28:41 +0000
Message-Id: <E1X7knh-0004it-8w@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-685-g8e1f5a5
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 2357bd10a05ad5161919b8b06856b1a4d11ea777
X-Git-Newrev: 8e1f5a53201184ff42348f9d4cf230f765d1441d
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 17 Jul 2014 12:28:45 -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=8e1f5a53201184ff42348f9d4cf230f765d1441d

The branch, master has been updated
       via  8e1f5a53201184ff42348f9d4cf230f765d1441d (commit)
       via  e1e999ded50db980bf844c479c9fc150e0ed3e5d (commit)
      from  2357bd10a05ad5161919b8b06856b1a4d11ea777 (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 8e1f5a53201184ff42348f9d4cf230f765d1441d
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Jul 17 15:27:09 2014 +0300

    Bugfixes.
    
    * examples/echosrv.c: Fix typo.
    * libmailutils/sockaddr/url.c: Likewise.
    * mh/mhn.c: Likewise.
    * mh/folder.c (roll_back): Fix conditional.
    * THANKS: Update.

commit e1e999ded50db980bf844c479c9fc150e0ed3e5d
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Jul 17 15:25:06 2014 +0300

    Bugfix.
    
    * libmailutils/filter/iconvflt.c: Fix silly errors.

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

Summary of changes:
 THANKS                         |    1 +
 examples/echosrv.c             |    2 +-
 libmailutils/filter/iconvflt.c |   12 ++++++------
 libmailutils/sockaddr/url.c    |    2 +-
 mh/folder.c                    |    5 +++--
 mh/mhn.c                       |    2 +-
 6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/THANKS b/THANKS
index f00b2a8..8153e27 100644
--- a/THANKS
+++ b/THANKS
@@ -21,6 +21,7 @@ Jordi Mallach        <jordi@sindominio.net>
 Kidong Lee           <briankdlee@yahoo.com>
 Kostas Zorbadelos    <kzorba@otenet.gr>
 Matthew Whitworth    <matthew@okcomputer.org>
+maks                 <maksqwe1@ukr.net>
 Neil R. Ormos        <ormos@ormos.org>
 Olivier Bornet       <Olivier.Bornet@smartdata.ch>
 Robby Villegas       <robby.villegas@gmail.com>
diff --git a/examples/echosrv.c b/examples/echosrv.c
index 76d6e5b..cfb7a17 100644
--- a/examples/echosrv.c
+++ b/examples/echosrv.c
@@ -140,7 +140,7 @@ create_server (char *arg)
       exit (1);
     }
 
-  memset (&hints, sizeof(hints), 0);
+  memset (&hints, 0, sizeof(hints));
   hints.flags = MU_AH_PASSIVE;
   hints.socktype = SOCK_STREAM;
   hints.protocol = IPPROTO_TCP;
diff --git a/libmailutils/filter/iconvflt.c b/libmailutils/filter/iconvflt.c
index 1d0f3db..07d3fcb 100644
--- a/libmailutils/filter/iconvflt.c
+++ b/libmailutils/filter/iconvflt.c
@@ -80,12 +80,12 @@ static void
 format_octal (char *op, unsigned char n)
 {
   op += 4;
-  *--op = n % 8;
-  n >> 3;
-  *--op = n % 8;
-  n >> 3;
-  *--op = n % 8;
-  n >> 3;
+  *--op = n % 8 + '0';
+  n >>= 3;
+  *--op = n % 8 + '0';
+  n >>= 3;
+  *--op = n % 8 + '0';
+  n >>= 3;
   *--op = '\\';
 }
 
diff --git a/libmailutils/sockaddr/url.c b/libmailutils/sockaddr/url.c
index 08e37df..baa8347 100644
--- a/libmailutils/sockaddr/url.c
+++ b/libmailutils/sockaddr/url.c
@@ -62,7 +62,7 @@ mu_sockaddr_from_url (struct mu_sockaddr **retval, mu_url_t url,
     memcpy (&hints, mh, sizeof (hints));
   else
     {
-      memset (&hints, sizeof(hints), 0);
+      memset (&hints, 0, sizeof(hints));
       hints.family = AF_UNSPEC;
       hints.socktype = SOCK_STREAM;
       hints.protocol = IPPROTO_TCP;
diff --git a/mh/folder.c b/mh/folder.c
index 0810a29..acaba97 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -720,9 +720,9 @@ roll_back (const char *folder_name, struct pack_tab *pack_tab, size_t i)
   if (i == 0)
     return;
   
-  start = i - 1;
+  start = --i;
   mu_error (_("rolling back changes..."));
-  while (--i >= 0)
+  do
     if (pack_rename (pack_tab + i, 1))
       {
 	mu_error (_("CRITICAL ERROR: Folder `%s' left in an inconsistent state, because an error\n"
@@ -736,6 +736,7 @@ roll_back (const char *folder_name, struct pack_tab *pack_tab, size_t i)
 	mu_error (_("You will have to fix it manually."));
 	exit (1);
       }
+  while (i-- > 0);
   mu_error (_("folder `%s' restored successfully"), folder_name);
 }
 
diff --git a/mh/mhn.c b/mh/mhn.c
index d307b23..5714030 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -2808,7 +2808,7 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
 		mu_message_get_part (omsg, 1, &part);
 	      else
 		part = omsg;
-	      if (part);
+	      if (part)
 		{
 		  mu_header_t parthdr = NULL;
 		  char *typestr, *typeargs;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Jul 27 17:32:02 2014
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1XBW30-0000Km-Bk
	for mharc-commit-mailutils@gnu.org; Sun, 27 Jul 2014 17:32:02 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:53221)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XBW2u-0000Kb-RM
	for commit-mailutils@gnu.org; Sun, 27 Jul 2014 17:32:01 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XBW2q-0005yS-Nh
	for commit-mailutils@gnu.org; Sun, 27 Jul 2014 17:31:56 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:32869)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XBW2q-0005yK-GY
	for commit-mailutils@gnu.org; Sun, 27 Jul 2014 17:31:52 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1XBW2o-0001uh-OD
	for commit-mailutils@gnu.org; Sun, 27 Jul 2014 21:31:51 +0000
Date: Sun, 27 Jul 2014 21:31:50 +0000
Message-Id: <E1XBW2o-0001uh-OD@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-687-g836d8ad
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 8e1f5a53201184ff42348f9d4cf230f765d1441d
X-Git-Newrev: 836d8ad109de5517ff1aa5ef61a557f5ed240081
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 27 Jul 2014 21:32:01 -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=836d8ad109de5517ff1aa5ef61a557f5ed240081

The branch, master has been updated
       via  836d8ad109de5517ff1aa5ef61a557f5ed240081 (commit)
       via  835cf591f2d7d9beff22adb32d7755da38779070 (commit)
      from  8e1f5a53201184ff42348f9d4cf230f765d1441d (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 836d8ad109de5517ff1aa5ef61a557f5ed240081
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Jul 27 20:32:34 2014 +0300

    Add scripting capability to mh/inc.
    
    This patch adds a convenience library libmuscript that provides scripting
    capability easy to use in MU applications. Currently used by maidag and
    inc.
    
    * include/mailutils/util.h (mu_stpcpy): 2nd arg is const.
    * libmailutils/string/stpcpy.c: Likewise.
    
    * lib/.gitignore: Update.
    * lib/Makefile.am: New library libmuscript.a
    * lib/muscript.h: New file.
    * lib/muscript_priv.h: New file.
    * lib/script.c: New file.
    * maidag/guile.c: Rename to ...
    * lib/guile.c: ... this
    * maidag/python.c: Rename to ...
    * lib/python.c: ... this
    * maidag/sieve.c: Rename to ...
    * lib/sieve.c: ... this
    
    * maidag/Makefile.am (maidag_LDADD): Add libmuscript.a
    (maidag_SOURCES): Update.
    * maidag/maidag.c (script_handler): Change type to mu_script_t.
    * maidag/maidag.h: Include muscript.h
    * maidag/script.c: Rewrite via libmuscript
    
    * mh/Makefile.am (inc_LDADD): New variable.
    * mh/inc.c (options): New options --language and --script.
    (mh_option): New options -language and -script.
    (incdat) <handler,descr>: New members.
    (incmbx): Optionally process each message through a script. If it is
    marked as deleted upon return, don't incorporate it.
    (main): Set mh as the default mailbox scheme.
    Initialize scripting subsystem and deallocate it when finished.
    * mh/mh_getopt.h (ARG_LANG, ARG_SCRIPT): New constants.

commit 835cf591f2d7d9beff22adb32d7755da38779070
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Jul 26 15:52:14 2014 +0300

    Move gnulib into a subdir.
    
    * bootstrap.conf: Create and populate lib/gnu, if necessary.
    * configure.ac (MU_APP_COMMON_INCLUDES): Update.
    (AC_CONFIG_FILES): Build lib/gnu/Makefile
    * lib/Makefile.am (libmuaux_a_SOURCES): Add all objects from gnu/
    * po/POTFILES.in: Update.
    
    * examples/.gitignore: Update.

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

Summary of changes:
 bootstrap.conf               |   14 ++++-
 configure.ac                 |    7 +-
 examples/.gitignore          |    1 +
 include/mailutils/debug.h    |    2 +-
 include/mailutils/util.h     |    2 +-
 lib/.gitignore               |    1 +
 lib/Makefile.am              |   33 +++++++--
 {maidag => lib}/guile.c      |   29 +++++---
 lib/muscript.h               |   45 +++++++++++++
 lib/muscript_priv.h          |   14 ++++
 {maidag => lib}/python.c     |   50 ++++++++++-----
 lib/script.c                 |  127 +++++++++++++++++++++++++++++++++++
 lib/sieve.c                  |  150 ++++++++++++++++++++++++++++++++++++++++++
 libmailutils/string/stpcpy.c |    2 +-
 maidag/Makefile.am           |    4 +-
 maidag/maidag.c              |   55 +++++----------
 maidag/maidag.h              |    7 +-
 maidag/script.c              |   90 +++++++------------------
 maidag/sieve.c               |   85 ------------------------
 mh/Makefile.am               |   21 ++++++
 mh/inc.c                     |   91 +++++++++++++++++++++++++-
 mh/mh_getopt.h               |    2 +
 po/POTFILES.in               |    6 +-
 23 files changed, 601 insertions(+), 237 deletions(-)
 create mode 100644 lib/.gitignore
 rename {maidag => lib}/guile.c (77%)
 create mode 100644 lib/muscript.h
 create mode 100644 lib/muscript_priv.h
 rename {maidag => lib}/python.c (63%)
 create mode 100644 lib/script.c
 create mode 100644 lib/sieve.c
 delete mode 100644 maidag/sieve.c

diff --git a/bootstrap.conf b/bootstrap.conf
index 9bd5806..5361ef2 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -15,7 +15,19 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-gnulib_name=libmuaux
+test -d lib/gnu || mkdir lib/gnu
+test -f lib/gnu/Makefile.am || cat > lib/gnu/Makefile.am <<EOT
+# THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
+include gnulib.mk
+AM_CPPFLAGS += @MU_LIB_COMMON_INCLUDES@ -I${top_srcdir}/lib/gnu -I${top_builddir}/lib/gnu
+# Local Variables:
+# buffer-read-only: t
+# End:
+# vi: set ro:
+EOT
+
+gnulib_name=libgnu
+source_base=lib/gnu
 
 # We don't need these modules, even though gnulib-tool mistakenly
 # includes them because of gettext dependencies.
diff --git a/configure.ac b/configure.ac
index ca3c1e7..03d4b63 100644
--- a/configure.ac
+++ b/configure.ac
@@ -69,7 +69,7 @@ AC_SUBST(MU_APP_LIBRARIES,'../libmu_argp/libmu_argp.a ../libmu_cfg/libmu_cfg.la
 
 AC_SUBST(MU_LIB_COMMON_INCLUDES,'-I${top_builddir} -I${top_srcdir}/include  -I${top_builddir}/include')
 
-AC_SUBST(MU_APP_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_builddir}/lib -I${top_builddir} -I${top_builddir}/include -I${top_srcdir}/libmu_argp -I${top_srcdir}/libmu_cfg')
+AC_SUBST(MU_APP_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_srcdir}/lib/gnu -I${top_builddir}/lib/gnu -I${top_builddir} -I${top_builddir}/include -I${top_srcdir}/libmu_argp -I${top_srcdir}/libmu_cfg')
 
 dnl Check for programs
 AC_PROG_CC
@@ -116,8 +116,8 @@ AC_CHECK_TYPE(iconv_t,:,
 # To make these two headers accessible for the libraries, they are linked
 # to include/.
 #
-AC_CONFIG_LINKS(include/gettext.h:lib/gettext.h)
-AC_CONFIG_LINKS(include/intprops.h:lib/intprops.h)
+AC_CONFIG_LINKS(include/gettext.h:lib/gnu/gettext.h)
+AC_CONFIG_LINKS(include/intprops.h:lib/gnu/intprops.h)
 
 AH_BOTTOM([
 #define DEFAULT_TEXT_DOMAIN PACKAGE
@@ -1462,6 +1462,7 @@ AC_CONFIG_FILES([
  include/mailutils/sys/Makefile
  include/mailutils/cpp/Makefile
  lib/Makefile
+ lib/gnu/Makefile
  libmu_argp/Makefile
  libmu_auth/Makefile
  libmu_cfg/Makefile
diff --git a/examples/.gitignore b/examples/.gitignore
index 890812a..e75f226 100644
--- a/examples/.gitignore
+++ b/examples/.gitignore
@@ -12,6 +12,7 @@ listop
 lsf
 mailcap
 mblconv
+mboxidx
 mimetest
 msg-send
 mta
diff --git a/include/mailutils/debug.h b/include/mailutils/debug.h
index cb026f7..ed117f0 100644
--- a/include/mailutils/debug.h
+++ b/include/mailutils/debug.h
@@ -81,7 +81,7 @@ void mu_debug_log_cont (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_end (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 void mu_debug_log_nl (void);
 
-  int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset);
+int mu_debug_get_iterator (mu_iterator_t *piterator, int skipunset);
 
   
 #define MU_ASSERT(expr)						\
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index 61c25f2..30493be 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -34,7 +34,7 @@ extern "C" {
 unsigned long mu_hex2ul (char hex);
 size_t mu_hexstr2ul (unsigned long* ul, const char* hex, size_t len);
 size_t mu_cpystr (char *dst, const char *src, size_t size);
-char *mu_stpcpy (char *p, char *q);
+char *mu_stpcpy (char *p, const char *q);
 int mu_string_unfold (char *text, size_t *plen);
 int mu_true_answer_p (const char *p);
 int mu_unre_set_regex (const char *str, int caseflag, char **errp);
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644
index 0000000..f7fe184
--- /dev/null
+++ b/lib/.gitignore
@@ -0,0 +1 @@
+gnu
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 559dd39..0ddb34c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -15,11 +15,17 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
-include gnulib.mk
+SUBDIRS = gnu .
 
-AM_CPPFLAGS += @MU_LIB_COMMON_INCLUDES@ 
+AM_CPPFLAGS = \
+ @MU_LIB_COMMON_INCLUDES@\
+ -I${top_srcdir}/lib/gnu\
+ -I${top_builddir}/lib/gnu\
+ @GUILE_INCLUDES@\
+ @PYTHON_INCLUDES@
 
-libmuaux_a_SOURCES += \
+noinst_LIBRARIES = libmuaux.a libmuscript.a
+libmuaux_a_SOURCES = \
  argp_base.c\
  daemon.c\
  mailcap.c\
@@ -29,14 +35,27 @@ libmuaux_a_SOURCES += \
  tcpwrap.c\
  mu_umaxtostr.c\
  mu_umaxtostr.h
+libmuaux_a_LIBADD=gnu/*.o
+#libmuaux_a_LIBADD=`$(AR) t gnu/libgnu.a | sed s.^.gnu/.`
 
-noinst_HEADERS +=\
+noinst_HEADERS =\
  mailcap.h\
  muaux.h\
+ muscript.h\
+ muscript_priv.h\
  tcpwrap.h
 
-EXTRA_DIST += utmp.c
-gl_LIBOBJS += @LIBOBJS@
-gl_LTLIBOBJS += @LTLIBOBJS@
+EXTRA_DIST = utmp.c
 
+libmuscript_a_SOURCES = \
+ script.c\
+ sieve.c
+
+if MU_COND_LIBMU_SCM
+ libmuscript_a_SOURCES += guile.c
+endif
+
+if MU_COND_PYTHON
+ libmuscript_a_SOURCES += python.c
+endif
 
diff --git a/maidag/guile.c b/lib/guile.c
similarity index 77%
rename from maidag/guile.c
rename to lib/guile.c
index 984fd62..9ac7e23 100644
--- a/maidag/guile.c
+++ b/lib/guile.c
@@ -15,21 +15,18 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "maidag.h"
-
-#ifdef WITH_GUILE
+#include "muscript.h"
+#include "muscript_priv.h"
 #include <mailutils/guile.h>
 
-int debug_guile;
 static int initialized;
 
-int
-scheme_check_msg (mu_message_t msg, struct mu_auth_data *auth,
-		  const char *prog)
+static int
+scheme_init (const char *prog, mu_script_descr_t *pdescr)
 {
   if (!initialized)
     {
-      mu_guile_init (debug_guile);
+      mu_guile_init (mu_script_debug_guile);
       if (mu_log_syslog)
 	{
 	  SCM port;
@@ -42,9 +39,21 @@ scheme_check_msg (mu_message_t msg, struct mu_auth_data *auth,
       initialized = 1;
     }
   mu_guile_load (prog, 0, NULL);
-  mu_guile_message_apply (msg, "mailutils-check-message");
   return 0;
 }
 
-#endif
+static int
+scheme_proc (mu_script_descr_t descr, mu_message_t msg)
+{
+  mu_guile_message_apply (msg, "mailutils-check-message");
+  return 0;
+}
 
+struct mu_script_fun mu_script_scheme = {
+  "scheme",
+  "scm\0",
+  scheme_init,
+  NULL,
+  scheme_proc,
+  NULL
+};
diff --git a/lib/muscript.h b/lib/muscript.h
new file mode 100644
index 0000000..2c15be5
--- /dev/null
+++ b/lib/muscript.h
@@ -0,0 +1,45 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014 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/>. */
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+#include <mailutils/sieve.h>
+#include <mailutils/diag.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+
+
+typedef struct mu_script_fun *mu_script_t;
+typedef struct mu_script_descr *mu_script_descr_t;
+
+mu_script_t mu_script_lang_handler (const char *lang);
+mu_script_t mu_script_suffix_handler (const char *name);
+
+int mu_script_init (mu_script_t scr, const char *name, mu_script_descr_t *);
+int mu_script_done (mu_script_t, mu_script_descr_t);
+int mu_script_process_msg (mu_script_t, mu_script_descr_t, mu_message_t msg);
+void mu_script_log_enable (mu_script_t scr, mu_script_descr_t descr,
+			   const char *name, const char *hdr);
+
+int mu_script_debug_flags (const char *arg, char **endp);
+
+extern int mu_script_debug_guile;
+extern int mu_script_debug_sieve;
+extern int mu_script_sieve_log;
+
+
diff --git a/lib/muscript_priv.h b/lib/muscript_priv.h
new file mode 100644
index 0000000..f97899f
--- /dev/null
+++ b/lib/muscript_priv.h
@@ -0,0 +1,14 @@
+struct mu_script_fun
+{
+  char *lang;
+  char *suf;
+  int (*script_init) (const char *, mu_script_descr_t *);
+  int (*script_done) (mu_script_descr_t);
+  int (*script_process) (mu_script_descr_t, mu_message_t);
+  int (*script_log_enable) (mu_script_descr_t descr, const char *name,
+			    const char *hdr);
+};
+
+extern struct mu_script_fun mu_script_python;
+extern struct mu_script_fun mu_script_sieve;
+extern struct mu_script_fun mu_script_scheme;
diff --git a/maidag/python.c b/lib/python.c
similarity index 63%
rename from maidag/python.c
rename to lib/python.c
index 2d7f0da..8b0fad0 100644
--- a/maidag/python.c
+++ b/lib/python.c
@@ -14,41 +14,59 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include "maidag.h"
-
-#ifdef WITH_PYTHON
+#include "muscript.h"
+#include "muscript_priv.h"
 #include <mailutils/python.h>
+#include <string.h>
+
+static int
+python_init (const char *prog, mu_script_descr_t *pdescr)
+{
+  *pdescr = (mu_script_descr_t) strdup (prog);
+  if (!*pdescr)
+    return errno;
+  return 0;
+}
 
-int
-python_check_msg (mu_message_t msg, struct mu_auth_data *auth,
-		  const char *prog)
+static int
+python_done (mu_script_descr_t descr)
+{
+  free (descr);
+}
+
+static int
+python_proc (mu_script_descr_t descr, mu_message_t msg)
 {
   PyMessage *py_msg;
   mu_py_dict dict[2];
   mu_py_script_data data[1];
-  char *argv[] = { "maidag", NULL };
+  char *argv[] = { NULL, NULL };
 
+  argv[0] = mu_program_name;
+  
   mu_py_script_init (1, argv);
 
-  if (!log_to_stderr)
-    {
-      /* FIXME */
-    }
-
   py_msg = PyMessage_NEW ();
   py_msg->msg = msg;
   Py_INCREF (py_msg);
 
   dict[0].name = "message";
   dict[0].obj  = (PyObject *)py_msg;
-  dict[1].name = NULL;
-  data[0].module_name = "maidag";
+  data[0].module_name = mu_program_name;
   data[0].attrs = dict;
+  dict[1].name = NULL;
 
-  mu_py_script_run (prog, data);
+mu_py_script_run ((char*)descr, data);
   mu_py_script_finish ();
   return 0;
 }
 
-#endif /* WITH_PYTHON */
+struct mu_script_fun mu_script_python = {
+  "python",
+  "py\0pyc\0",
+  python_init,
+  python_done,
+  python_proc,
+  NULL
+};
 
diff --git a/lib/script.c b/lib/script.c
new file mode 100644
index 0000000..9882634
--- /dev/null
+++ b/lib/script.c
@@ -0,0 +1,127 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014 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/>. */
+
+#include "muscript.h"
+#include "muscript_priv.h"
+
+int mu_script_debug_sieve;
+int mu_script_debug_guile;
+int mu_script_sieve_log;
+
+struct mu_script_fun *script_tab[] = {
+  &mu_script_sieve,
+#ifdef WITH_PYTHON
+  &mu_script_python,  
+#endif
+#ifdef WITH_GUILE
+  &mu_script_scheme,
+#endif
+  NULL
+};
+
+int
+mu_script_debug_flags (const char *arg, char **endp)
+{
+  for (; *arg; arg++)
+    {
+      switch (*arg)
+	{
+	case 'g':
+	  mu_script_debug_guile = 1;
+	  break;
+
+	case 't':
+	  mu_script_debug_sieve |= MU_SIEVE_DEBUG_TRACE;
+	  break;
+	  
+	case 'i':
+	  mu_script_debug_sieve |= MU_SIEVE_DEBUG_INSTR;
+	  break;
+	  
+	case 'l':
+	  mu_script_sieve_log = 1;
+	  break;
+	  
+	default:
+	  if (endp)
+	    *endp = (char*) arg;
+	  return 1;
+	}
+    }
+  return 0;
+}
+
+mu_script_t
+mu_script_lang_handler (const char *lang)
+{
+  int i;
+
+  for (i = 0; script_tab[i]; i++)
+    if (strcmp (script_tab[i]->lang, lang) == 0)
+      return script_tab[i];
+  return NULL;
+}
+
+mu_script_t
+mu_script_suffix_handler (const char *name)
+{
+  int i;
+  char *suf;
+  
+  suf = strrchr (name, '.');
+  if (!suf)
+    return NULL;
+  suf++;
+  
+  for (i = 0; script_tab[i]; i++)
+    {
+      char *s;
+
+      for (s = script_tab[i]->suf; *s; s += strlen (s) + 1)
+	if (strcmp (s, suf) == 0)
+	  return script_tab[i];
+    }
+  return NULL;
+}
+
+int
+mu_script_init (mu_script_t scr, const char *name, mu_script_descr_t *pdescr)
+{
+  return scr->script_init ? scr->script_init (name, pdescr) : 0;
+}
+
+int
+mu_script_done (mu_script_t scr, mu_script_descr_t descr)
+{
+  return scr->script_done ? scr->script_done (descr) : 0;
+}
+
+void
+mu_script_log_enable (mu_script_t scr, mu_script_descr_t descr,
+		      const char *name, const char *hdr)
+{
+  if (scr->script_log_enable)
+    scr->script_log_enable (descr, name, hdr);
+}
+
+int
+mu_script_process_msg (mu_script_t scr, mu_script_descr_t descr,
+		       mu_message_t msg)
+{
+  return scr->script_process (descr, msg);
+}
+
diff --git a/lib/sieve.c b/lib/sieve.c
new file mode 100644
index 0000000..21f21c7
--- /dev/null
+++ b/lib/sieve.c
@@ -0,0 +1,150 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014 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/>. */
+
+#include "muscript.h"
+#include "muscript_priv.h"
+
+struct sieve_log_data
+{
+  char *user;
+  char *hdr;
+};
+
+static void
+_sieve_action_log (void *data,
+		   mu_stream_t stream, size_t msgno,
+		   mu_message_t msg,
+		   const char *action, const char *fmt, va_list ap)
+{
+  struct sieve_log_data *ldat = data;
+  int pfx = 0;
+
+  mu_stream_printf (stream, "\033s<%d>", MU_LOG_NOTICE);
+  if (ldat)
+    {
+      if (ldat->user)
+	mu_stream_printf (stream, _("(user %s) "), ldat->user);
+      if (ldat->hdr)
+	{
+	  mu_header_t hdr = NULL;
+	  char *val = NULL;
+	  mu_message_get_header (msg, &hdr);
+	  if (mu_header_aget_value (hdr, ldat->hdr, &val) == 0
+	      || mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &val) == 0)
+	    {
+	      pfx = 1;
+	      mu_stream_printf (stream, _("%s on msg %s"), action, val);
+	      free (val);
+	    }
+	}
+    }
+  
+  if (!pfx)
+    {
+      size_t uid = 0;
+      mu_message_get_uid (msg, &uid);
+      mu_stream_printf (stream, _("%s on msg uid %lu"), action,
+			(unsigned long) uid);
+    }
+  
+  if (fmt && strlen (fmt))
+    {
+      mu_stream_printf (stream, "; ");
+      mu_stream_vprintf (stream, fmt, ap);
+    }
+  mu_stream_printf (stream, "\n");
+}
+
+static int
+sieve_init (const char *prog, mu_script_descr_t *pdescr)
+{
+  int rc;
+  mu_sieve_machine_t mach;
+
+  rc = mu_sieve_machine_init (&mach);
+  if (rc == 0)
+    {
+      mu_sieve_set_debug_level (mach, mu_script_debug_sieve);
+      if (mu_script_sieve_log)
+	mu_sieve_set_logger (mach, _sieve_action_log);
+      rc = mu_sieve_compile (mach, prog);
+    }
+  *pdescr = (mu_script_descr_t) mach;
+  return rc;
+}
+
+static int
+sieve_log_enable (mu_script_descr_t descr, const char *name, const char *hdr)
+{
+  mu_sieve_machine_t mach = (mu_sieve_machine_t) descr;
+  struct sieve_log_data *ldat;
+  size_t size = 0;
+  char *p;
+  
+  if (name)
+    size += strlen (name) + 1;
+  if (hdr)
+    size += strlen (hdr) + 1;
+
+  if (size)
+    {
+      ldat = calloc (1, sizeof (*ldat) + size);
+      if (!ldat)
+	return ENOMEM;
+      p = (char *) (ldat + 1); 
+      if (name)
+	{
+	  ldat->user = p;
+	  p = mu_stpcpy (p, name) + 1;
+	}
+      if (hdr)
+	{
+	  ldat->hdr = p;
+	  strcpy (p, hdr);
+	}
+      
+      mu_sieve_set_data (mach, ldat);
+    }
+  mu_sieve_set_logger (mach, _sieve_action_log);
+  return 0;
+}
+
+static int
+sieve_done (mu_script_descr_t descr)
+{
+  mu_sieve_machine_t mach = (mu_sieve_machine_t) descr;
+  void *p = mu_sieve_get_data (mach);
+  free (p);
+  mu_sieve_machine_destroy (&mach);
+  return 0;
+}
+
+static int
+sieve_proc (mu_script_descr_t descr, mu_message_t msg)
+{
+  return mu_sieve_message ((mu_sieve_machine_t) descr, msg);
+}
+
+struct mu_script_fun mu_script_sieve = {
+  "sieve",
+  "sv\0siv\0sieve\0",
+  sieve_init,
+  sieve_done,
+  sieve_proc,
+  sieve_log_enable
+};
+
diff --git a/libmailutils/string/stpcpy.c b/libmailutils/string/stpcpy.c
index d348b0d..39fb884 100644
--- a/libmailutils/string/stpcpy.c
+++ b/libmailutils/string/stpcpy.c
@@ -23,7 +23,7 @@
 #include <mailutils/util.h>
 
 char *
-mu_stpcpy (char *p, char *q)
+mu_stpcpy (char *p, const char *q)
 {
   if (q)
     while ((*p = *q++))
diff --git a/maidag/Makefile.am b/maidag/Makefile.am
index 3395845..6d79754 100644
--- a/maidag/Makefile.am
+++ b/maidag/Makefile.am
@@ -19,13 +19,10 @@ sbin_PROGRAMS=maidag
 maidag_SOURCES=\
  deliver.c\
  forward.c\
- guile.c\
  lmtp.c\
  maidag.c\
  maidag.h\
  mailquota.c\
- python.c\
- sieve.c\
  script.c\
  util.c
 
@@ -34,6 +31,7 @@ if MU_COND_DBM
 endif
 
 maidag_LDADD = \
+ ../lib/libmuscript.a\
  @LIBMU_SCM@ @GUILE_LIBS@\
  @LIBMU_SCM_DEPS@\
  @MU_LIB_PY@ @PYTHON_LIBS@\
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 399c6c2..71c9ded 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -30,7 +30,7 @@ char *quota_query = NULL;  /* SQL query to retrieve mailbox quota */
 
 char *sender_address = NULL;       
 
-maidag_script_fun script_handler;
+mu_script_t script_handler;
 
 mu_list_t script_list;
 
@@ -62,7 +62,7 @@ static char doc[] =
 N_("GNU maidag -- the mail delivery agent.")
 "\v"
 N_("Debug flags are:\n\
-  g - guimb stack traces\n\
+  g - guile stack traces\n\
   t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
   i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
   l - sieve action logs\n\
@@ -143,47 +143,28 @@ static const char *maidag_argp_capa[] = {
   NULL
 };
 
-#define D_DEFAULT "9,s"
-
 static void
 set_debug_flags (const char *arg)
 {
   while (*arg)
     {
-      if (mu_isdigit (*arg))
+      if (mu_script_debug_flags (arg, (char**)&arg) == 0)
+	break;
+      else if (mu_isdigit (*arg))
 	debug_level = strtoul (arg, (char**)&arg, 10);
       else
-	for (; *arg && *arg != ','; arg++)
-	  {
-	    switch (*arg)
-	      {
-	      case 'g':
-#ifdef WITH_GUILE
-		debug_guile = 1;
-#endif
-		break;
-
-	      case 't':
-		sieve_debug_flags |= MU_SIEVE_DEBUG_TRACE;
-		break;
-	  
-	      case 'i':
-		sieve_debug_flags |= MU_SIEVE_DEBUG_INSTR;
-		break;
-	  
-	      case 'l':
-		sieve_enable_log = 1;
-		break;
-	  
-	      default:
-		mu_error (_("%c is not a valid debug flag"), *arg);
-		break;
-	      }
-	  }
+	{
+	  mu_error (_("%c is not a valid debug flag"), *arg);
+	  break;
+	}
+
       if (*arg == ',')
 	arg++;
       else if (*arg)
-	mu_error (_("expected comma, but found %c"), *arg);
+	{
+	  mu_error (_("expected comma, but found %c"), *arg);
+	  exit (1);
+	}
     }
 }
 
@@ -234,7 +215,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
       
     case 'l':
-      script_handler = script_lang_handler (arg);
+      script_handler = mu_script_lang_handler (arg);
       if (!script_handler)
 	argp_error (state, _("unknown or unsupported language: %s"),
 		    arg);
@@ -256,7 +237,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
       break;
       
     case 'x':
-      mu_argp_node_list_new (lst, "debug", arg ? arg : D_DEFAULT);
+      mu_argp_node_list_new (lst, "debug", arg);
       break;
 
     case STDERR_OPTION:
@@ -353,7 +334,7 @@ cb_script_language (void *data, mu_config_value_t *val)
 {
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  script_handler = script_lang_handler (val->v.string);
+  script_handler = mu_script_lang_handler (val->v.string);
   if (!script_handler)
     {
       mu_error (_("unsupported language: %s"), val->v.string);
@@ -457,7 +438,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
   { "debug", mu_cfg_callback, NULL, 0, cb_debug,
     N_("Set maidag debug level.  Debug level consists of one or more "
        "of the following letters:\n"
-       "  g - guimb stack traces\n"
+       "  g - guile stack traces\n"
        "  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n"
        "  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n"
        "  l - sieve action logs\n") },
diff --git a/maidag/maidag.h b/maidag/maidag.h
index 0ae7ce3..9975848 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -94,6 +94,7 @@
 #include "mailutils/libargp.h"
 
 #include "tcpwrap.h"
+#include "muscript.h"
 
 /* Debug */
 extern int debug_level;
@@ -177,12 +178,12 @@ typedef int (*maidag_script_fun) (mu_message_t msg,
 				  struct mu_auth_data *auth,
 				  const char *prog);
 
-extern maidag_script_fun script_handler;
+extern mu_script_t script_handler;
 
 struct maidag_script
 {
-  maidag_script_fun fun;   /* Handler function */
-  const char *pat;         /* Script name pattern */
+  mu_script_t scr;   /* Handler script */
+  const char *pat;   /* Script name pattern */
 };
 
 maidag_script_fun script_lang_handler (const char *lang);
diff --git a/maidag/script.c b/maidag/script.c
index 80dff7c..9cfb70c 100644
--- a/maidag/script.c
+++ b/maidag/script.c
@@ -17,80 +17,27 @@
 
 #include "maidag.h"
 
-struct script_tab
-{
-  char *lang;
-  char *suf;
-  maidag_script_fun fun;
-};
-
-struct script_tab script_tab[] = {
-#ifdef WITH_PYTHON
-  { "python", "py\0pyc\0", python_check_msg },
-#endif
-  { "sieve",  "sv\0siv\0sieve\0", sieve_check_msg },
-#ifdef WITH_GUILE
-  { "scheme", "scm\0", scheme_check_msg },
-#endif
-  { NULL }
-};
-
-maidag_script_fun
-script_lang_handler (const char *lang)
-{
-  struct script_tab *p;
-
-  for (p = script_tab; p->lang; p++)
-    if (strcmp (p->lang, lang) == 0)
-      return p->fun;
-  return NULL;
-}
-
-maidag_script_fun
-script_suffix_handler (const char *name)
-{
-  struct script_tab *p;
-  char *suf;
-  
-  suf = strrchr (name, '.');
-  if (!suf)
-    return NULL;
-  suf++;
-  
-  for (p = script_tab; p->lang; p++)
-    {
-      char *s;
-
-      for (s = p->suf; *s; s += strlen (s) + 1)
-	if (strcmp (s, suf) == 0)
-	  return p->fun;
-    }
-  return NULL;
-}
-
-
-
 int
 script_register (const char *pattern)
 {
-  maidag_script_fun fun;
-  struct maidag_script *scr;
+  mu_script_t scr;
+  struct maidag_script *p;
   
   if (script_handler)
-    fun = script_handler;
+    scr = script_handler;
   else
     {
-      fun = script_suffix_handler (pattern);
-      if (!fun)
+      scr = mu_script_suffix_handler (pattern);
+      if (!scr)
 	return EINVAL;
     }
 
-  scr = malloc (sizeof (*scr));
-  if (!scr)
+  p = malloc (sizeof (*p));
+  if (!p)
     return MU_ERR_FAILURE;
   
-  scr->fun = fun;
-  scr->pat = pattern;
+  p->scr = scr;
+  p->pat = pattern;
 
   if (!script_list)
     {
@@ -98,7 +45,7 @@ script_register (const char *pattern)
 	return MU_ERR_FAILURE;
     }
 
-  if (mu_list_append (script_list, scr))
+  if (mu_list_append (script_list, p))
     return MU_ERR_FAILURE;
 
   return 0;
@@ -119,6 +66,7 @@ apply_script (void *item, void *data)
   char *progfile;
   int rc;
   struct stat st;
+  mu_script_descr_t sd;
   
   progfile = mu_expand_path_pattern (scr->pat, clos->auth->name);
   if (stat (progfile, &st))
@@ -131,7 +79,21 @@ apply_script (void *item, void *data)
       return 0;
     }
 
-  rc = scr->fun (clos->msg, clos->auth, progfile);
+  rc = mu_script_init (scr->scr, progfile, &sd);
+  if (rc)
+    mu_error (_("initialization of script %s failed: %s"),
+	      progfile, mu_strerror (rc));
+  else
+    {
+      if (sieve_enable_log)
+	mu_script_log_enable (scr->scr, sd, clos->auth->name,
+			      message_id_header);
+      rc = mu_script_process_msg (scr->scr, sd, clos->msg);
+      if (rc)
+	mu_error (_("script %s failed: %s"), progfile, mu_strerror (rc));
+      mu_script_done (scr->scr, sd);
+    }
+
   free (progfile);
 
   if (rc == 0)
diff --git a/maidag/sieve.c b/maidag/sieve.c
deleted file mode 100644
index f5451c6..0000000
--- a/maidag/sieve.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014 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/>. */
-
-#include "maidag.h"
-
-static void
-_sieve_action_log (void *user_name,
-		   mu_stream_t stream, size_t msgno,
-		   mu_message_t msg,
-		   const char *action, const char *fmt, va_list ap)
-{
-  int pfx = 0;
-
-  mu_stream_printf (stream, "\033s<%d>", MU_LOG_NOTICE);
-  mu_stream_printf (stream, _("(user %s) "), (char*) user_name);
-  if (message_id_header)
-    {
-      mu_header_t hdr = NULL;
-      char *val = NULL;
-      mu_message_get_header (msg, &hdr);
-      if (mu_header_aget_value (hdr, message_id_header, &val) == 0
-	  || mu_header_aget_value (hdr, MU_HEADER_MESSAGE_ID, &val) == 0)
-	{
-	  pfx = 1;
-	  mu_stream_printf (stream, _("%s on msg %s"), action, val);
-	  free (val);
-	}
-    }
-  
-  if (!pfx)
-    {
-      size_t uid = 0;
-      mu_message_get_uid (msg, &uid);
-      mu_stream_printf (stream, _("%s on msg uid %lu"), action,
-			(unsigned long) uid);
-    }
-  
-  if (fmt && strlen (fmt))
-    {
-      mu_stream_printf (stream, "; ");
-      mu_stream_vprintf (stream, fmt, ap);
-    }
-  mu_stream_printf (stream, "\n");
-}
-
-int
-sieve_check_msg (mu_message_t msg, struct mu_auth_data *auth, const char *prog)
-{
-  int rc;
-  mu_sieve_machine_t mach;
-
-  rc = mu_sieve_machine_init (&mach);
-  if (rc)
-    {
-      mu_error (_("Cannot initialize sieve machine: %s"),
-		mu_strerror (rc));
-    }
-  else
-    {
-      mu_sieve_set_data (mach, auth->name);
-      if (sieve_enable_log)
-	mu_sieve_set_logger (mach, _sieve_action_log);
-	  
-      rc = mu_sieve_compile (mach, prog);
-      if (rc == 0)
-	mu_sieve_message (mach, msg);
-      mu_sieve_machine_destroy (&mach);
-    }
-  return 0;
-}
-
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 22857e9..1a0a5f0 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -125,6 +125,27 @@ pick_SOURCES = pick.c pick.h pick-gram.c pick-gram.h
 YLWRAP = $(SHELL) $(mu_aux_dir)/gylwrap
 AM_YFLAGS=-vt
 
+inc_LDADD = \
+ ./libmh.a\
+ ../lib/libmuaux.a\
+ ../lib/libmuscript.a\
+ @LIBMU_SCM@ @GUILE_LIBS@\
+ @LIBMU_SCM_DEPS@\
+ @MU_LIB_PY@ @PYTHON_LIBS@\
+ ${MU_LIB_SIEVE}\
+ ${MU_LIB_MBOX}\
+ ${MU_LIB_IMAP}\
+ ${MU_LIB_POP}\
+ ${MU_LIB_MH}\
+ ${MU_LIB_NNTP}\
+ ${MU_LIB_MAILDIR}\
+ ${MU_LIB_MAILER}\
+ ${MU_LIB_AUTH}\
+ @MU_AUTHLIBS@\
+ ${MU_LIB_MAILUTILS}\
+ @MU_COMMON_LIBRARIES@
+
+
 pick-gram.c pick-gram.h: $(srcdir)/pick.y
 	$(YLWRAP) "$(YACC) $(AM_YFLAGS) -d" $< \
 	          y.tab.c pick-gram.c y.tab.h pick-gram.h \
diff --git a/mh/inc.c b/mh/inc.c
index bf0f1d2..497f9a8 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -18,9 +18,15 @@
 /* MH inc command */
 
 #include <mh.h>
+#include "muscript.h"
 
 static char doc[] = N_("GNU MH inc")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+N_("Debug flags are:\n\
+  g - guile stack traces\n\
+  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
+  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
+  l - sieve action logs\n\n\
+Use -help to obtain the list of traditional MH options.");
 static char args_doc[] = N_("[+FOLDER]");
 
 /* GNU options */
@@ -51,6 +57,12 @@ static struct argp_option options[] = {
    N_("be quiet")},
   {"notify",  ARG_NOTIFY,N_("BOOL"),   OPTION_ARG_OPTIONAL,
    N_("enable biff notification"), },
+  {"language",ARG_LANG,  N_("LANG"), 0,
+   N_("set language for the --script option") },
+  {"script",  ARG_SCRIPT,N_("FILE"), 0,
+   N_("filter incoming messages using script FILE") },
+  {"debug",   ARG_DEBUG, N_("FLAGS"), 0,
+   N_("enable debugging") },   
   { 0 }
 };
 
@@ -67,6 +79,9 @@ struct mh_option mh_option[] = {
   { "width",     MH_OPT_ARG, "number" },
   { "notify",    MH_OPT_BOOL },
   { "quiet" },
+  { "language",  MH_OPT_ARG, "lang" },
+  { "script",    MH_OPT_ARG, "file" },
+  { "debug",     MH_OPT_ARG, "flags" },
   { NULL }
 };
 
@@ -81,11 +96,14 @@ static int quiet = 0;
 static int notify = 0;
 static const char *append_folder;
 static const char *move_to_mailbox;
+static const char *script_file;
+static const char *script_lang;
 
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
 {
   int rc;
+  char *p;
   
   switch (key)
     {
@@ -106,6 +124,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       changecur = is_true (arg);
       break;
 
+    case ARG_DEBUG:
+      if (mu_script_debug_flags (arg, &p))
+	argp_error (state, _("invalid debug flag near %s"), p);
+      break;
+
     case ARG_NOCHANGECUR:
       changecur = 0;
       break;
@@ -169,6 +192,14 @@ opt_handler (int key, char *arg, struct argp_state *state)
     case ARG_NOTIFY:
       notify = is_true (arg);;
       break;
+
+    case ARG_LANG:
+      script_lang = arg;
+      break;
+
+    case ARG_SCRIPT:
+      script_file = arg;
+      break;
       
     default:
       return ARGP_ERR_UNKNOWN;
@@ -196,6 +227,8 @@ struct incdat
   mu_mailbox_t output;
   size_t lastmsg;
   mh_format_t format;
+  mu_script_t handler;
+  mu_script_descr_t descr;
 };
 
 static int
@@ -294,6 +327,23 @@ incmbx (void *item, void *data)
 	  continue;
 	}
 
+      if (dp->handler)
+	{
+	  mu_attribute_t attr;
+
+	  if (mu_script_process_msg (dp->handler, dp->descr, imsg))
+	    {
+	      mu_error (_("%lu: filter failed: %s"),
+		    (unsigned long) n, mu_strerror (rc));
+	      continue;
+	    }
+
+	  mu_message_get_attribute (imsg, &attr);
+	  if (mu_attribute_is_deleted (attr))
+	    continue;
+	}
+
+      
       if ((rc = mu_mailbox_append_message (dp->output, imsg)) != 0)
 	{
 	  mu_error (_("%lu: error appending message: %s"),
@@ -379,10 +429,12 @@ main (int argc, char **argv)
   
   /* Native Language Support */
   MU_APP_INIT_NLS ();
-
+  
   mh_argp_init ();
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, NULL);
+  mu_registrar_set_default_scheme ("mh");
+
   /* Inc sets missing cur to 1 */
   mh_mailbox_cur_default = 1;
 
@@ -395,6 +447,38 @@ main (int argc, char **argv)
 
   incdat.output = mh_open_folder (append_folder,
 				  MU_STREAM_READ|MU_STREAM_APPEND|MU_STREAM_CREAT);
+
+  if (script_file)
+    {
+      if (script_lang)
+	{
+	  incdat.handler = mu_script_lang_handler (script_lang);
+	  if (!incdat.handler)
+	    {
+	      mu_error (_("unknown or unsupported language: %s"),
+			script_lang);
+	      exit (1);
+	    }
+	}
+      else
+	{
+	  incdat.handler = mu_script_suffix_handler (script_file);
+	  if (!incdat.handler)
+	    {
+	      mu_error (_("unknown or unsupported language: %s"),
+			script_file);
+	      exit (1);
+	    }
+	}
+      rc = mu_script_init (incdat.handler, script_file, &incdat.descr);
+      if (rc)
+	{
+	  mu_error (_("script initialization failed: %s"),
+		    mu_strerror (rc));
+	  exit (1);
+	}
+    }
+  
   if (notify)
     {
       rc = mu_mailbox_set_notify (incdat.output, NULL);
@@ -424,6 +508,9 @@ main (int argc, char **argv)
   else
     mu_list_foreach (input_file_list, incmbx, &incdat);
 
+  if (script_file)
+    mu_script_done (incdat.handler, incdat.descr);
+  
   unseen_seq = mh_global_profile_get ("Unseen-Sequence", NULL);
   if (unseen_seq && lastseen < incdat.lastmsg)
     {
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index c457b4f..c2cc51d 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -87,6 +87,7 @@ enum mh_arg {
   ARG_HOST,
   ARG_INPLACE,		
   ARG_INTERACTIVE,	
+  ARG_LANG,
   ARG_LBRACE,		
   ARG_LENGTH,		
   ARG_LIMIT,		
@@ -166,6 +167,7 @@ enum mh_arg {
   ARG_RECURSIVE,		
   ARG_REORDER,		
   ARG_REVERSE,		
+  ARG_SCRIPT,
   ARG_SEQUENCE,		
   ARG_SERIALONLY,		
   ARG_SHOW,		
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 95abad3..eb39744 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,9 +25,9 @@ imap4d/signal.c
 imap4d/starttls.c
 imap4d/util.c
 
-lib/argp-help.c
-lib/argp-parse.c
-lib/getopt.c
+lib/gnu/argp-help.c
+lib/gnu/argp-parse.c
+lib/gnu/getopt.c
 lib/mailcap.c
 lib/tcpwrap.c
 lib/strexit.c


hooks/post-receive
-- 
GNU Mailutils


