From MAILER-DAEMON Tue Nov 02 09:36:13 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PDH25-0000Th-09
	for mharc-commit-mailutils@gnu.org; Tue, 02 Nov 2010 09:36:13 -0400
Received: from [140.186.70.92] (port=34863 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PDH1y-0003vR-NH
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 09:36:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDEJK-0006ip-MM
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 06:41:52 -0400
Received: from colonialone.fsf.org ([140.186.70.51]:38029
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDEJK-0006ik-Ke
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 06:41:50 -0400
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDEJK-0002Xt-ES
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 10:41:50 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDEJJ-0002Gv-W4
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 10:41:50 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: c66e1b8de8fd661a34f03734cbb0a559324c3075
X-Git-Newrev: 1d5c1ef0d22380eafe6ee78991e0c60315a33222
Message-Id: <E1PDEJJ-0002Gv-W4@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 02 Nov 2010 10:41:50 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-171-g1d5c1ef
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 02 Nov 2010 13:36:11 -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=1d5c1ef0d22380eafe6ee78991e0c60315a33222

The branch, master has been updated
       via  1d5c1ef0d22380eafe6ee78991e0c60315a33222 (commit)
      from  c66e1b8de8fd661a34f03734cbb0a559324c3075 (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 1d5c1ef0d22380eafe6ee78991e0c60315a33222
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 2 10:57:21 2010 +0200

    Minor changes.
    
    * include/mailutils/wordsplit.h (mu_wordsplit_free_words): New proto.
    * libmu_auth/sql.c: Include wordsplit.h

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

Summary of changes:
 include/mailutils/wordsplit.h |    1 +
 libmu_auth/sql.c              |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/include/mailutils/wordsplit.h b/include/mailutils/wordsplit.h
index 40e4289..3ddedb6 100644
--- a/include/mailutils/wordsplit.h
+++ b/include/mailutils/wordsplit.h
@@ -126,6 +126,7 @@ int mu_wordsplit (const char *s, struct mu_wordsplit *p, int flags);
 int mu_wordsplit_len (const char *s, size_t len,
 		      struct mu_wordsplit *p, int flags);
 void mu_wordsplit_free (struct mu_wordsplit *p);
+void mu_wordsplit_free_words (struct mu_wordsplit *ws);
 
 int mu_wordsplit_c_unquote_char (int c);
 int mu_wordsplit_c_quote_char (int c);
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index e622470..c4e3dfb 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -50,6 +50,7 @@
 #include <mailutils/util.h>
 #include <mailutils/sql.h>
 #include <mailutils/cstr.h>
+#include <mailutils/wordsplit.h>
 #include "sql.h"
 
 #ifdef USE_SQL


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 02 11:36:40 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PDIud-0003dX-Jb
	for mharc-commit-mailutils@gnu.org; Tue, 02 Nov 2010 11:36:39 -0400
Received: from [140.186.70.92] (port=40997 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PDIuZ-0003Zv-5u
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 11:36:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDIuW-0006SP-JX
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 11:36:34 -0400
Received: from colonialone.fsf.org ([140.186.70.51]:55943
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDIuW-0006SI-G8
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 11:36:32 -0400
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDIuW-0006QQ-4t
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 15:36:32 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDIuV-0001OC-7K
	for commit-mailutils@gnu.org; Tue, 02 Nov 2010 15:36:31 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 1d5c1ef0d22380eafe6ee78991e0c60315a33222
X-Git-Newrev: b02eb9b062494d2ed77ca1f52cd7733486df0bef
Message-Id: <E1PDIuV-0001OC-7K@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 02 Nov 2010 15:36:31 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-174-gb02eb9b
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 02 Nov 2010 15:36:37 -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=b02eb9b062494d2ed77ca1f52cd7733486df0bef

The branch, master has been updated
       via  b02eb9b062494d2ed77ca1f52cd7733486df0bef (commit)
       via  89bdc37336218836a6c208e37696e6e723c42894 (commit)
       via  150ebcfaf5ded43ff71313ce2acff79bf99c1487 (commit)
      from  1d5c1ef0d22380eafe6ee78991e0c60315a33222 (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 b02eb9b062494d2ed77ca1f52cd7733486df0bef
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 2 15:04:55 2010 +0200

    Remove the --license option.
    
    It is not needed because the --version option shows a terse info about the
    license, as well as a link to its full text.

commit 89bdc37336218836a6c208e37696e6e723c42894
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 2 14:47:42 2010 +0200

    Minor change.
    
    * po/POTFILES.in: Fix erroneous filenames.

commit 150ebcfaf5ded43ff71313ce2acff79bf99c1487
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 2 14:47:01 2010 +0200

    Use full buffering for streamrefs.
    
    * libmailutils/stream/streamref.c (mu_streamref_create_abridged): Set
    full buffering by default.

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

Summary of changes:
 comsat/comsat.c                 |    1 -
 dotlock/dotlock.c               |    1 -
 examples/muauth.c               |    1 -
 frm/frm.c                       |    1 -
 frm/from.c                      |    1 -
 guimb/main.c                    |    1 -
 imap4d/imap4d.c                 |    1 -
 include/mailutils/libargp.h     |    1 -
 include/mailutils/version.h     |    1 -
 libmailutils/base/version.c     |   17 ---------------
 libmailutils/cfg/gocs.c         |    1 -
 libmailutils/stream/streamref.c |    5 +++-
 libmu_argp/cmdline.c            |    1 -
 libmu_argp/common.c             |   43 ---------------------------------------
 libmu_cfg/init.c                |    2 +-
 maidag/maidag.c                 |    1 -
 mail/mail.c                     |    1 -
 messages/messages.c             |    1 -
 mimeview/mimeview.c             |    1 -
 movemail/movemail.c             |    1 -
 mu/mu.c                         |    1 -
 po/POTFILES.in                  |    5 ++-
 pop3d/pop3d.c                   |    1 -
 pop3d/popauth.c                 |    1 -
 sieve/sieve.c                   |    1 -
 25 files changed, 8 insertions(+), 84 deletions(-)

diff --git a/comsat/comsat.c b/comsat/comsat.c
index 373998f..8f82f1a 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -87,7 +87,6 @@ static const char *comsat_argp_capa[] = {
   "logging",
   "mailbox",
   "locking",
-  "license",
   NULL
 };
 
diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index 84d322e..6afeec0 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -134,7 +134,6 @@ struct mu_cfg_param dotlock_cfg_param[] = {
 
 
 const char *dotlock_capa[] = {
-  "license",
   "common",
   "debug",
   NULL
diff --git a/examples/muauth.c b/examples/muauth.c
index a80cda8..3008b30 100644
--- a/examples/muauth.c
+++ b/examples/muauth.c
@@ -31,7 +31,6 @@ static char args_doc[] = "key";
 
 static const char *capa[] = {
   "auth",
-  "license",
   "common",
   "debug",
   NULL
diff --git a/frm/frm.c b/frm/frm.c
index fdd43c1..c0348e0 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -203,7 +203,6 @@ static struct argp argp = {
 static const char *frm_argp_capa[] = {
   "common",
   "debug",
-  "license",
   "mailbox",
   "locking",
   NULL
diff --git a/frm/from.c b/frm/from.c
index d86cfea..e621a23 100644
--- a/frm/from.c
+++ b/frm/from.c
@@ -70,7 +70,6 @@ static struct argp argp = {
 static const char *capa[] = {
   "common",
   "debug",
-  "license",
   "mailbox",
   "locking",
   NULL
diff --git a/guimb/main.c b/guimb/main.c
index 4a3f39e..a6cfbb1 100644
--- a/guimb/main.c
+++ b/guimb/main.c
@@ -139,7 +139,6 @@ static const char *guimb_argp_capa[] = {
   "debug",
   "mailbox",
   "locking",
-  "license",
   NULL
 };
 
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 844b953..848b4d7 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -90,7 +90,6 @@ static const char *imap4d_capa[] = {
   "mailbox",
   "locking",
   "logging",
-  "license",
   NULL
 };
 
diff --git a/include/mailutils/libargp.h b/include/mailutils/libargp.h
index 586d74a..603b859 100644
--- a/include/mailutils/libargp.h
+++ b/include/mailutils/libargp.h
@@ -47,7 +47,6 @@ extern int (*mu_app_cfg_verifier) (void);
   
 extern struct mu_cmdline_capa mu_common_cmdline;
 extern struct mu_cmdline_capa mu_logging_cmdline;
-extern struct mu_cmdline_capa mu_license_cmdline;
 extern struct mu_cmdline_capa mu_mailbox_cmdline;
 extern struct mu_cmdline_capa mu_locking_cmdline;
 extern struct mu_cmdline_capa mu_address_cmdline;
diff --git a/include/mailutils/version.h b/include/mailutils/version.h
index 566d735..d93ff75 100644
--- a/include/mailutils/version.h
+++ b/include/mailutils/version.h
@@ -30,7 +30,6 @@ struct mu_conf_option
   char *descr;
 };
   
-extern char *mu_license_text;
 extern void mu_print_options (void);
 extern void mu_fprint_options (FILE *fp, int verbose);
 extern void mu_fprint_conf_option (FILE *fp, const struct mu_conf_option *opt,
diff --git a/libmailutils/base/version.c b/libmailutils/base/version.c
index d482140..2cf11ac 100644
--- a/libmailutils/base/version.c
+++ b/libmailutils/base/version.c
@@ -27,23 +27,6 @@
 
 #include <confpaths.h>
 
-char *mu_license_text =
- N_("   GNU Mailutils is free software; you can redistribute it and/or modify\n"
-    "   it under the terms of the GNU General Public License as published by\n"
-    "   the Free Software Foundation; either version 3 of the License, or\n"
-    "   (at your option) any later version.\n"
-    "\n"
-    "   GNU Mailutils is distributed in the hope that it will be useful,\n"
-    "   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-    "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-    "   GNU General Public License for more details.\n"
-    "\n"
-    "   You should have received a copy of the GNU General Public License along\n"
-    "   with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.\n"
-    "\n"
-    "\n"
-);
-
 static struct mu_conf_option mu_conf_option[] = {
   { "VERSION=" VERSION, N_("Version of this package") },
   { "SYSCONFDIR=" SYSCONFDIR, N_("System configuration directory") },
diff --git a/libmailutils/cfg/gocs.c b/libmailutils/cfg/gocs.c
index 7976aa2..d50d3f7 100644
--- a/libmailutils/cfg/gocs.c
+++ b/libmailutils/cfg/gocs.c
@@ -299,7 +299,6 @@ find_init_function (struct mu_gocs_entry *tab, const char *capa)
 
 static struct mu_gocs_entry std_gocs_table[] = {
   { "common", mu_gocs_dummy },
-  { "license", mu_gocs_dummy },
   { "mailbox", mu_gocs_mailbox_init },
   { "locking", mu_gocs_locking_init },
   { "address", mu_gocs_source_email_init },
diff --git a/libmailutils/stream/streamref.c b/libmailutils/stream/streamref.c
index e860a55..2faff48 100644
--- a/libmailutils/stream/streamref.c
+++ b/libmailutils/stream/streamref.c
@@ -266,7 +266,7 @@ mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str,
   mu_off_t off;
   int flags;
   struct _mu_streamref *sp;
-
+  
   rc = mu_stream_seek (str, 0, MU_SEEK_SET, &off);
   if (rc)
     return rc;
@@ -302,6 +302,9 @@ mu_streamref_create_abridged (mu_stream_t *pref, mu_stream_t str,
     off = start;
   sp->offset = off;
   *pref = (mu_stream_t) sp;
+
+  mu_stream_set_buffer (*pref, mu_buffer_full, 0);
+
   return 0;
 }
 
diff --git a/libmu_argp/cmdline.c b/libmu_argp/cmdline.c
index 26f84fa..13994bf 100644
--- a/libmu_argp/cmdline.c
+++ b/libmu_argp/cmdline.c
@@ -24,7 +24,6 @@
 static struct mu_cmdline_capa *all_cmdline_capa[] = {
   &mu_common_cmdline,
   &mu_logging_cmdline,
-  &mu_license_cmdline,
   &mu_mailer_cmdline,
   &mu_debug_cmdline,
   &mu_tls_cmdline,
diff --git a/libmu_argp/common.c b/libmu_argp/common.c
index a76e378..cfc6b1f 100644
--- a/libmu_argp/common.c
+++ b/libmu_argp/common.c
@@ -197,49 +197,6 @@ struct mu_cmdline_capa mu_logging_cmdline = {
 
 
 /* ************************************************************************* */
-/* License                                                                   */
-/* ************************************************************************* */
-
-/* Option to print the license. */
-static struct argp_option mu_license_argp_option[] = {
-  { "license", OPT_LICENSE, NULL, 0, N_("print license and exit"), -2 },
-  { NULL,      0, NULL, 0, NULL, 0 }
-};
-
-static error_t
-mu_license_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case OPT_LICENSE:
-      printf (_("License for %s:\n\n"), argp_program_version);
-      printf ("%s", mu_license_text);
-      exit (0);
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_license_argp = {
-  mu_license_argp_option,
-  mu_license_argp_parser,
-};
-
-struct argp_child mu_license_argp_child = {
-  &mu_license_argp,
-  0,
-  NULL,
-  0
-};
-
-struct mu_cmdline_capa mu_license_cmdline = {
-  "license", &mu_license_argp_child 
-};
-
-
-/* ************************************************************************* */
 /* Mailer                                                                    */
 /* ************************************************************************* */
 
diff --git a/libmu_cfg/init.c b/libmu_cfg/init.c
index 1dcaa77..176465c 100644
--- a/libmu_cfg/init.c
+++ b/libmu_cfg/init.c
@@ -57,7 +57,7 @@ find_cfg_capa (const char *name)
 static int
 reserved_name (const char *name)
 {
-  static char *reserved[] = { "common", "license", NULL };
+  static char *reserved[] = { "common", NULL };
   char **p;
   for (p = reserved; *p; p++)
     if (strcmp (name, *p) == 0)
diff --git a/maidag/maidag.c b/maidag/maidag.c
index b588ca9..0b54e6c 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -131,7 +131,6 @@ static const char *maidag_argp_capa[] = {
   "auth",
   "common",
   "debug",
-  "license",
   "logging",
   "mailbox",
   "locking",
diff --git a/mail/mail.c b/mail/mail.c
index 3f70e66..acf265c 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -203,7 +203,6 @@ static struct argp argp = {
 static const char *mail_capa[] = {
   "common",
   "debug",
-  "license",
   "mailbox",
   "locking",
   NULL 
diff --git a/messages/messages.c b/messages/messages.c
index e467a9b..6fc5d4b 100644
--- a/messages/messages.c
+++ b/messages/messages.c
@@ -44,7 +44,6 @@ static struct argp_option options[] = {
 static const char *argp_capa[] = {
   "common",
   "debug",
-  "license",
   "mailbox",
   "locking",
   NULL
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 6523853..5d67108 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -178,7 +178,6 @@ struct mu_cfg_param mimeview_cfg_param[] = {
 static const char *capa[] = {
   "common",
   "debug",
-  "license",
   NULL
 };
 
diff --git a/movemail/movemail.c b/movemail/movemail.c
index b8da17f..1acef61 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -330,7 +330,6 @@ struct mu_cfg_param movemail_cfg_param[] = {
 static const char *movemail_capa[] = {
   "common",
   "debug",
-  "license",
   "locking",
   "mailbox",
   "auth",
diff --git a/mu/mu.c b/mu/mu.c
index a0900f7..8649efe 100644
--- a/mu/mu.c
+++ b/mu/mu.c
@@ -73,7 +73,6 @@ static struct argp argp = {
 static const char *mu_tool_capa[] = {
   "common",
   "debug",
-  "license",
   "locking",
   "mailbox",
   "auth",
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c23e197..b2d2a5b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -142,8 +142,9 @@ libmailutils/server/msrv.c
 libmailutils/mailbox/message.c
 libmailutils/mailbox/mbx_default.c
 libmailutils/mailer/mailer.c
-libmailutils/mailer/smtp.c
-libmailutils/mailer/smtp_gsasl.c
+
+libproto/mailer/smtp.c
+libproto/mailer/smtp_gsasl.c
 
 libmailutils/auth/mu_auth.c
 
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index b058147..a497996 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -139,7 +139,6 @@ static const char *pop3d_argp_capa[] = {
   "mailbox",
   "locking",
   "logging",
-  "license",
   NULL
 };
 
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index 2c9d75e..4bd172b 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -98,7 +98,6 @@ static struct argp argp = {
 
 static const char *popauth_argp_capa[] = {
   "common",
-  "license",
   NULL
 };
 
diff --git a/sieve/sieve.c b/sieve/sieve.c
index e021a33..0a4ec61 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -307,7 +307,6 @@ static const char *sieve_argp_capa[] =
   "debug",
   "mailbox",
   "locking",
-  "license",
   "logging",
   "mailer",
   NULL


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 03 07:26:53 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PDbUT-0003s9-JH
	for mharc-commit-mailutils@gnu.org; Wed, 03 Nov 2010 07:26:53 -0400
Received: from [140.186.70.92] (port=40127 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PDbTB-0003ZM-B8
	for commit-mailutils@gnu.org; Wed, 03 Nov 2010 07:26:49 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDbSj-0003T6-I0
	for commit-mailutils@gnu.org; Wed, 03 Nov 2010 07:25:08 -0400
Received: from colonialone.fsf.org ([140.186.70.51]:34088
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDbSj-0003T1-FB
	for commit-mailutils@gnu.org; Wed, 03 Nov 2010 07:25:05 -0400
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDbSf-0005ub-HG
	for commit-mailutils@gnu.org; Wed, 03 Nov 2010 11:25:01 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PDbSb-0005gs-Eh
	for commit-mailutils@gnu.org; Wed, 03 Nov 2010 11:25:01 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: b02eb9b062494d2ed77ca1f52cd7733486df0bef
X-Git-Newrev: 966a860c0eef32bfe8cab5c5c05c54a8e115270b
Message-Id: <E1PDbSb-0005gs-Eh@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 03 Nov 2010 11:24:57 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-175-g966a860
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 03 Nov 2010 11:26:50 -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=966a860c0eef32bfe8cab5c5c05c54a8e115270b

The branch, master has been updated
       via  966a860c0eef32bfe8cab5c5c05c54a8e115270b (commit)
      from  b02eb9b062494d2ed77ca1f52cd7733486df0bef (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 966a860c0eef32bfe8cab5c5c05c54a8e115270b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 3 12:27:17 2010 +0200

    Improve command module system in mu.  Add a `help' command.
    
    * mu/Makefile.am (MODULES): New variable.  Put all commands there.
    (mu_SOURCES): Include $(MODULES).
    (EXTRA_DIST): Add mu-setup.h mu-setup.c mu-setup.awk
    (BUILT_SOURCES): New variable.
    (mu-setup.h, mu-setup.c): New goals.
    
    * mu/mu.c (doc): Remove command description: it is generated automatically.
    (mu_help_filter): New function.
    (argp): Use mu_help_filter.
    (mutool_action_tab): Remove.
    (mutool_nosys,find_action): Remove.
    (mu_help): New function.
    (main): Use dispatch_find_action.
    * mu/mu.h: Include mailutils/types.h
    (mutool_pop, mutool_filter, mutool_flt2047)
    (mutool_info, mutool_query, mutool_acl)
    (mutool_wicket, mutool_ldflags, mutool_cflags): Remove protos.
    (mu_help, dispatch_find_action, dispatch_docstring): New protos.
    
    * mu/acl.c: Add MU Setup comment.
    * mu/cflags.c: Likewise.
    * mu/filter.c: Likewise.
    * mu/flt2047.c: Likewise.
    * mu/info.c: Likewise.
    * mu/ldflags.c: Likewise.
    * mu/pop.c: Likewise.
    * mu/query.c: Likewise.
    * mu/wicket.c: Likewise.
    
    * mu/mu-setup.awk: New file.
    * mu/help.c: New file.
    * mu/dispatch.c: New file.
    
    * mu/.gitignore: Add mu-status.[ch]
    
    * po/POTFILES.in: Add mu/dispatch.c and mu/help.c.

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

Summary of changes:
 mu/.gitignore   |    2 +
 mu/Makefile.am  |   24 +++++++++++----
 mu/acl.c        |    8 +++++
 mu/cflags.c     |    7 ++++
 mu/dispatch.c   |   78 +++++++++++++++++++++++++++++++++++++++++++++++
 mu/filter.c     |   10 +++++-
 mu/flt2047.c    |    8 +++++
 mu/help.c       |   74 +++++++++++++++++++++++++++++++++++++++++++++
 mu/info.c       |    8 +++++
 mu/ldflags.c    |    7 ++++
 mu/mu-setup.awk |   64 +++++++++++++++++++++++++++++++++++++++
 mu/mu.c         |   90 ++++++++++++++++++------------------------------------
 mu/mu.h         |   17 ++++-------
 mu/pop.c        |    8 +++++
 mu/query.c      |    8 +++++
 mu/shell.c      |    1 +
 mu/wicket.c     |    9 +++++
 po/POTFILES.in  |    2 +
 18 files changed, 347 insertions(+), 78 deletions(-)
 create mode 100644 mu/dispatch.c
 create mode 100644 mu/help.c
 create mode 100644 mu/mu-setup.awk

diff --git a/mu/.gitignore b/mu/.gitignore
index 92cfbd6..c159d48 100644
--- a/mu/.gitignore
+++ b/mu/.gitignore
@@ -1 +1,3 @@
 mu
+mu-setup.c
+mu-setup.h
diff --git a/mu/Makefile.am b/mu/Makefile.am
index 6fe40d9..52ab78c 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -22,22 +22,28 @@ if MU_COND_SUPPORT_POP
  POP_C=pop.c
 endif
 
-EXTRA_DIST=pop.c
+EXTRA_DIST=pop.c mu-setup.h mu-setup.c mu-setup.awk
+BUILT_SOURCES=mu-setup.h mu-setup.c
 
-mu_SOURCES = \
+MODULES = \
  acl.c\
  cflags.c\
- info.c\
- mu.h\
- mu.c\
  filter.c\
  flt2047.c\
+ help.c\
+ info.c\
  ldflags.c\
  $(POP_C)\
  query.c\
- shell.c\
  wicket.c
 
+mu_SOURCES = \
+ dispatch.c\
+ mu.h\
+ mu.c\
+ shell.c\
+ $(MODULES)
+
 mu_LDADD = \
  ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
@@ -61,3 +67,9 @@ AM_CPPFLAGS = \
   -DGUILE_LIBS="\"$(GUILE_LIBS)\"" \
   -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
   -DI18NLIBS="\"$(LIBINTL)\""
+
+mu-setup.h: Makefile.am $(MODULES)
+	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=h $(MODULES) > mu-setup.h
+
+mu-setup.c: Makefile.am $(MODULES)
+	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=c $(MODULES) > mu-setup.c
diff --git a/mu/acl.c b/mu/acl.c
index 0c9cc21..9d86460 100644
--- a/mu/acl.c
+++ b/mu/acl.c
@@ -30,6 +30,7 @@
 #include "xalloc.h"
 
 static char acl_doc[] = N_("mu acl - test access control lists.");
+char acl_docstring[] = N_("test access control lists");
 static char acl_args_doc[] = N_("ADDRESS [ADDRESS...]");
 
 static struct argp_option acl_options[] = {
@@ -191,3 +192,10 @@ mutool_acl (int argc, char **argv)
 
   return 0;
 }
+
+/*
+  MU Setup: acl
+  mu-handler: mutool_acl
+  mu-docstring: acl_docstring
+  End MU Setup:
+*/
diff --git a/mu/cflags.c b/mu/cflags.c
index 9d177d0..ea510da 100644
--- a/mu/cflags.c
+++ b/mu/cflags.c
@@ -23,6 +23,7 @@
 #include <argp.h>
 
 static char cflags_doc[] = N_("mu cflags - show compiler options");
+char cflags_docstring[] = N_("show compiler options");
 
 static struct argp cflags_argp = {
   NULL,
@@ -43,4 +44,10 @@ mutool_cflags (int argc, char **argv)
   return 0;
 }
 
+/*
+  MU Setup: cflags
+  mu-handler: mutool_cflags
+  mu-docstring: cflags_docstring
+  End MU Setup:
+*/
 
diff --git a/mu/dispatch.c b/mu/dispatch.c
new file mode 100644
index 0000000..0769b7f
--- /dev/null
+++ b/mu/dispatch.c
@@ -0,0 +1,78 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/stream.h>
+#include <mailutils/nls.h>
+#include "mu.h"
+#include "mu-setup.h"
+#include "xalloc.h"
+
+struct mutool_action_tab
+{
+  const char *name;
+  mutool_action_t action;
+  const char *docstring;
+};
+
+struct mutool_action_tab mutool_action_tab[] = {
+#include "mu-setup.c"
+  { NULL }
+};
+
+mutool_action_t
+dispatch_find_action (const char *name)
+{
+  struct mutool_action_tab *p;
+
+  for (p = mutool_action_tab; p->name; p++)
+    if (strcmp (p->name, name) == 0)
+      return p->action;
+  return NULL;
+}
+
+char *
+dispatch_docstring (const char *text)
+{
+  mu_stream_t str;
+  struct mutool_action_tab *p;
+  mu_off_t size;
+  size_t n;
+  char *ret;
+  
+  mu_memory_stream_create (&str, MU_STREAM_RDWR);
+  mu_stream_printf (str, "%s\n%s\n\n", text, _("Commands are:"));
+  for (p = mutool_action_tab; p->name; p++)
+    mu_stream_printf (str, "  mu %-16s - %s\n",
+		      p->name, gettext (p->docstring));
+  mu_stream_printf (str, "\n%s\n\n",
+		    _("Try `mu COMMAND --help' to get help on a particular "
+		      "COMMAND."));
+  mu_stream_printf (str, "%s\n", _("Options are:"));
+  mu_stream_flush (str);
+  mu_stream_size (str, &size);
+  ret = xmalloc (size + 1);
+  mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
+  mu_stream_read (str, ret, size, &n);
+  ret[n] = 0;
+  mu_stream_destroy (&str);
+  return ret;
+}
+    
diff --git a/mu/filter.c b/mu/filter.c
index dedc2f9..2facaee 100644
--- a/mu/filter.c
+++ b/mu/filter.c
@@ -23,7 +23,8 @@
 #include "argp.h"
 #include "mu.h"
 
-static char filter_doc[] = N_("mu filter");
+static char filter_doc[] = N_("mu filter - apply a filter to the input");
+char filter_docstring[] = N_("apply a filter to the input");
 static char filter_args_doc[] = N_("NAME");
 
 static struct argp_option filter_options[] = {
@@ -157,3 +158,10 @@ mutool_filter (int argc, char **argv)
   
   return 0;
 }
+
+/*
+  MU Setup: filter
+  mu-handler: mutool_filter
+  mu-docstring: filter_docstring
+  End MU Setup:
+*/
diff --git a/mu/flt2047.c b/mu/flt2047.c
index 7c6c9d6..ecd7e27 100644
--- a/mu/flt2047.c
+++ b/mu/flt2047.c
@@ -24,6 +24,7 @@
 #include "mu.h"
 
 static char flt2047_doc[] = N_("mu 2047 - decode/encode message headers.");
+char flt2047_docstring[] = N_("decode/encode email message headers");
 static char flt2047_args_doc[] = N_("[text]");
 
 static struct argp_option flt2047_options[] = {
@@ -153,3 +154,10 @@ mutool_flt2047 (int argc, char **argv)
   
   return 0;
 }
+
+/*
+  MU Setup: 2047
+  mu-handler: mutool_flt2047
+  mu-docstring: flt2047_docstring
+  End MU Setup:
+*/
diff --git a/mu/help.c b/mu/help.c
new file mode 100644
index 0000000..c389765
--- /dev/null
+++ b/mu/help.c
@@ -0,0 +1,74 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* mu help - specjalnie dla Wojtka :) */
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <mailutils/nls.h>
+#include "mailutils/libargp.h"
+#include "mu.h"
+
+static char help_doc[] = N_("mu help - display a terse help summary");
+char help_docstring[] = N_("display a terse help summary");
+static char help_args_doc[] = N_("[COMMAND]");
+
+static struct argp help_argp = {
+  NULL,
+  NULL,
+  help_args_doc,
+  help_doc,
+  NULL,
+  NULL,
+  NULL
+};
+
+int
+mutool_help (int argc, char **argv)
+{
+  int index;
+
+  if (argp_parse (&help_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
+    return 1;
+
+  if (index == argc - 1)
+    {
+      mutool_action_t action = dispatch_find_action (argv[index]);
+      if (!action)
+	{
+	  mu_error (_("don't know what %s is"), argv[index]);
+	  exit (1);
+	}
+      argv[0] = argv[index];
+      argv[1] = "--help";
+      return action (2, argv);
+    }
+  else if (argc != index)
+    {
+      mu_error (_("too many arguments"));
+      exit (1);
+    }
+  return mu_help ();
+}
+
+/*
+  MU Setup: help
+  mu-handler: mutool_help
+  mu-docstring: help_docstring
+  End MU Setup:
+*/
diff --git a/mu/info.c b/mu/info.c
index e101d2b..48f903c 100644
--- a/mu/info.c
+++ b/mu/info.c
@@ -26,6 +26,7 @@
 static char info_doc[] = N_("mu info - print a list of configuration\
  options used to build mailutils; optional arguments are interpreted\
  as a list of configuration options to check for.");
+char info_docstring[] = N_("show Mailutils configuration");
 static char info_args_doc[] = N_("[capa...]");
 
 static struct argp_option info_options[] = {
@@ -91,3 +92,10 @@ mutool_info (int argc, char **argv)
     }
   return 0;
 }
+
+/*
+  MU Setup: info
+  mu-handler: mutool_info
+  mu-docstring: info_docstring
+  End MU Setup:
+*/
diff --git a/mu/ldflags.c b/mu/ldflags.c
index 59ac5eb..f93536c 100644
--- a/mu/ldflags.c
+++ b/mu/ldflags.c
@@ -23,6 +23,7 @@
 #include <argp.h>
 
 static char ldflags_doc[] = N_("mu ldflags - list libraries required to link");
+char ldflags_docstring[] = N_("list libraries required to link");
 static char ldflags_args_doc[] = N_("KEYWORD [KEYWORD...]");
 
 static struct argp ldflags_argp = {
@@ -191,3 +192,9 @@ mutool_ldflags (int argc, char **argv)
   return 0;
 }
 
+/*
+  MU Setup: ldflags
+  mu-handler: mutool_ldflags
+  mu-docstring: ldflags_docstring
+  End MU Setup:
+*/
diff --git a/mu/mu-setup.awk b/mu/mu-setup.awk
new file mode 100644
index 0000000..5d261f1
--- /dev/null
+++ b/mu/mu-setup.awk
@@ -0,0 +1,64 @@
+# This file is part of GNU Mailutils.
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2, 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/>.
+
+state == 0 && /MU Setup:/  {
+  if (NF != 3) {
+    print FILENAME ":" NR ":", "missing module name" > "/dev/stderr"
+    exit(1)
+  } else {  
+    state = 1;
+    module_name=$3;
+    if (modules[module_name]) {
+      print FILENAME ":" NR ":", "this module already declared" > "/dev/stderr"
+      print modules[module_name] ":", "location of the prior declaration" > "/dev/stderr"
+    } else
+      modules[module_name] = (FILENAME":"NR);
+  }
+}
+state == 1 && /mu-.*:/ {
+  setup[module_name,substr($1,4,length($1)-4)] = $2;
+  next
+}
+state == 1 && /End MU Setup/ { state = 0 }
+END {
+  print "/* -*- buffer-read-only: t -*- vi: set ro:"
+  print "   THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT."
+  print "*/"
+
+  vartab[1] = "handler"
+  vartab[2] = "docstring"
+  n = asorti(modules,modname)
+  for (i = 1; i <= n; i++) {
+    name = modname[i]
+    for (j in vartab) {
+      if (!setup[name,vartab[j]]) {
+	print modules[name] ":", "mu-" vartab[j], "not defined"
+	err = 1
+      }
+    }
+    if (err)
+      continue
+    if (mode == "h") {
+      print "extern int", setup[name,"handler"], "(int argc, char **argv);"
+      print "extern char " setup[name,"docstring"] "[];"
+    } else {
+      print "{", "\"" name "\",", setup[name,"handler"] ",", setup[name,"docstring"], "},"
+    }
+  }
+}
+
+  
+  
diff --git a/mu/mu.c b/mu/mu.c
index 8649efe..b5e8bc6 100644
--- a/mu/mu.c
+++ b/mu/mu.c
@@ -25,25 +25,7 @@
 #include "mu.h"
 
 static char args_doc[] = N_("COMMAND [CMDOPTS]");
-static char doc[] = N_("mu -- GNU Mailutils multi-purpose tool.\n\
-Commands are:\n\
-    mu info   - show Mailutils configuration\n\
-    mu query  - query configuration values\n\
-    mu pop    - POP3 client program\n\
-    mu filter - filter program\n\
-    mu 2047   - decode/encode message headers as per RFC 2047\n\
-    mu acl    - test access control lists\n\
-    mu wicket - find matching URL in wicket\n\
-    mu ldflags- list libraries required to link\n\
-    mu cflags - list compiler flags\n\
-\n\
-Try `mu COMMAND --help' to get help on a particular COMMAND.\n\
-\n\
-Options are:\n");
-/* FIXME: add
-    mu imap
-    mu send [opts]
- */
+static char doc[] = N_("mu -- GNU Mailutils multi-purpose tool.");
 
 static struct argp_option options[] = {
   { NULL }
@@ -60,13 +42,31 @@ parse_opt (int key, char *arg, struct argp_state *state)
   return 0;
 }
 
+static char *
+mu_help_filter (int key, const char *text, void *input)
+{
+  char *s;
+  
+  switch (key)
+    {
+    case ARGP_KEY_HELP_PRE_DOC:
+      s = dispatch_docstring (text);
+      break;
+      
+    default:
+      s = (char*) text;
+    }
+  return s;
+}
+
+
 static struct argp argp = {
   options,
   parse_opt,
   args_doc,
   doc,
   NULL,
-  NULL,
+  mu_help_filter,
   NULL
 };
 
@@ -83,46 +83,16 @@ struct mu_cfg_param mu_tool_param[] = {
   { NULL }
 };
 
-struct mutool_action_tab
-{
-  const char *name;
-  mutool_action_t action;
-};
-
-static int
-mutool_nosys (int argc, char **argv)
-{
-  mu_error (_("%s is not available because required code is not compiled"),
-	    argv[0]);
-  return 1;
-}
-
-struct mutool_action_tab mutool_action_tab[] = {
-  { "info", mutool_info },
-#ifdef ENABLE_POP
-  { "pop", mutool_pop },
-#else
-  { "pop", mutool_nosys },
-#endif
-  { "filter", mutool_filter },
-  { "2047", mutool_flt2047 },
-  { "query", mutool_query },
-  { "acl", mutool_acl },
-  { "wicket", mutool_wicket },
-  { "ldflags", mutool_ldflags },
-  { "cflags", mutool_cflags },
-  { NULL }
-};
-
-static mutool_action_t
-find_action (const char *name)
+int
+mu_help ()
 {
-  struct mutool_action_tab *p;
-
-  for (p = mutool_action_tab; p->name; p++)
-    if (strcmp (p->name, name) == 0)
-      return p->action;
-  return NULL;
+  char *x_argv[3];
+    
+  x_argv[0] = (char*) mu_program_name;
+  x_argv[1] = "--help";
+  x_argv[2] = NULL;
+  return mu_app_init (&argp, mu_tool_capa, mu_tool_param, 
+		      2, x_argv, 0, NULL, NULL);
 }
 
 int
@@ -155,7 +125,7 @@ main (int argc, char **argv)
       exit (1);
     }
 	
-  action = find_action (argv[0]);
+  action = dispatch_find_action (argv[0]);
   if (!action)
     {
       mu_error (_("don't know what %s is"), argv[0]);
diff --git a/mu/mu.h b/mu/mu.h
index 4280b0e..d46bc41 100644
--- a/mu/mu.h
+++ b/mu/mu.h
@@ -14,6 +14,8 @@
    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 <mailutils/types.h>
+
 typedef int (*mutool_action_t) (int argc, char **argv);
 
 struct mutool_command
@@ -28,20 +30,13 @@ struct mutool_command
   const char *docstring;/* Documentation for this function.  */
 };
 
-
-int mutool_pop (int argc, char **argv);
-int mutool_filter (int argc, char **argv);
-int mutool_flt2047 (int argc, char **argv);
-int mutool_info (int argc, char **argv);
-int mutool_query (int argc, char **argv);
-int mutool_acl (int argc, char **argv);
-int mutool_wicket (int argc, char **argv);
-int mutool_ldflags (int argc, char **argv);
-int mutool_cflags (int argc, char **argv);
-  
 extern char *mutool_shell_prompt;
 extern char **mutool_prompt_env;
 extern int mutool_shell_interactive;
 extern mu_stream_t mustrin, mustrout;
 int mutool_shell (const char *name, struct mutool_command *cmd);
 mu_stream_t mutool_open_pager (void);
+
+int mu_help (void);
+mutool_action_t dispatch_find_action (const char *name);
+char *dispatch_docstring (const char *text);
diff --git a/mu/pop.c b/mu/pop.c
index 311bd67..bf2c938 100644
--- a/mu/pop.c
+++ b/mu/pop.c
@@ -28,6 +28,7 @@
 #include "xalloc.h"
 
 static char pop_doc[] = N_("mu pop - POP3 client shell.");
+char pop_docstring[] = N_("POP3 client shell");
 static char pop_args_doc[] = "";
 
 static struct argp_option pop_options[] = {
@@ -807,3 +808,10 @@ mutool_pop (int argc, char **argv)
   mutool_shell ("pop", pop_comtab);
   return 0;
 }
+
+/*
+  MU Setup: pop
+  mu-handler: mutool_pop
+  mu-docstring: pop_docstring
+  End MU Setup:
+*/
diff --git a/mu/query.c b/mu/query.c
index fd951c2..6a1c557 100644
--- a/mu/query.c
+++ b/mu/query.c
@@ -25,6 +25,7 @@
 #include "mu.h"
 
 static char query_doc[] = N_("mu query - query configuration values.");
+char query_docstring[] = N_("query configuration values");
 static char query_args_doc[] = N_("path [path...]");
 
 char *file_name;
@@ -118,4 +119,11 @@ mutool_query (int argc, char **argv)
   return 0;
 }
  
+
+/*
+  MU Setup: query
+  mu-handler: mutool_query
+  mu-docstring: query_docstring
+  End MU Setup:
+*/
   
diff --git a/mu/shell.c b/mu/shell.c
index 51ed25a..ab12fd4 100644
--- a/mu/shell.c
+++ b/mu/shell.c
@@ -620,3 +620,4 @@ mutool_shell (const char *name, struct mutool_command *cmd)
   mu_stream_destroy (&mustrout);
   return 0;
 }
+
diff --git a/mu/wicket.c b/mu/wicket.c
index 2ea8eec..6cd9715 100644
--- a/mu/wicket.c
+++ b/mu/wicket.c
@@ -23,6 +23,7 @@
 #include <argp.h>
 
 static char wicket_doc[] = N_("mu wicket - find matching URL in wicket");
+char wicket_docstring[] = N_("scan wickets for matching URLs");
 static char wicket_args_doc[] = N_("NAME");
 
 static struct argp_option wicket_options[] = {
@@ -172,3 +173,11 @@ mutool_wicket (int argc, char **argv)
   mu_stream_destroy (&stream);
   return exit_code;
 }
+
+
+/*
+  MU Setup: wicket
+  mu-handler: mutool_wicket
+  mu-docstring: wicket_docstring
+  End MU Setup:
+*/
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b2d2a5b..8d2e5e6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -212,8 +212,10 @@ sieve/sieve.c
 sql/mysql.c
 
 mu/acl.c
+mu/dispatch.c
 mu/filter.c
 mu/flt2047.c
+mu/help.c
 mu/info.c
 mu/mu.c
 mu/pop.c


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 09 09:14:00 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PFoxU-000510-7P
	for mharc-commit-mailutils@gnu.org; Tue, 09 Nov 2010 09:14:00 -0500
Received: from [140.186.70.92] (port=48347 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PFoxL-0004vL-3u
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 09:13:59 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFoxA-0001B5-Dz
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 09:13:46 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:59526
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFoxA-0001Az-8j
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 09:13:40 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFoxA-0008Du-8I
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 14:13:40 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFoxA-0006iH-3d
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 14:13:40 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 966a860c0eef32bfe8cab5c5c05c54a8e115270b
X-Git-Newrev: 439f8c1a9f99409087694f95c82f40c12e286371
Message-Id: <E1PFoxA-0006iH-3d@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 09 Nov 2010 14:13:40 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-179-g439f8c1
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Nov 2010 14:13:59 -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=439f8c1a9f99409087694f95c82f40c12e286371

The branch, master has been updated
       via  439f8c1a9f99409087694f95c82f40c12e286371 (commit)
       via  96cfdb5e8ef877b1f8773e426061ef4d3442997e (commit)
       via  78e57f7ec9df1547dd5e176a97fa1f8954b51c09 (commit)
       via  78d43b05bf6dfd37b5f251715211f48f3f22fb58 (commit)
      from  966a860c0eef32bfe8cab5c5c05c54a8e115270b (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 439f8c1a9f99409087694f95c82f40c12e286371
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 9 16:00:31 2010 +0200

    imap client: implement login and id commands.
    
    * libproto/imap/id.c: New file.
    * libproto/imap/login.c: New file.
    * libproto/imap/Makefile.am: Add new files.
    * libproto/imap/capability.c (mu_imap_capability): Clear
    MU_IMAP_RESP before reading response.
    Add MU_WRDSF_QUOTE to mu_wordsplit flags.
    * libproto/imap/err.c (_mu_imap_seterrstr): Bugfix: initialize
    imap->errstr.
    * libproto/imap/logout.c (mu_imap_logout): Clear
    MU_IMAP_RESP before reading response.
    * libproto/imap/response.c (_mu_imap_response): Set error string.
    * mu/imap.c (com_login, com_id): New functions.
    (imap_comtab) <login, id>: New keywords.

commit 96cfdb5e8ef877b1f8773e426061ef4d3442997e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 9 12:41:22 2010 +0200

    Make sure stream->offset points to the position in stream corresponding to the start of the buffer.
    
    * libmailutils/stream/stream.c (_stream_fill_buffer): Keep
    track of the current offset.
    (mu_stream_seek): avoid unnecessary seeks.
    (_stream_skip_input_bytes): Call _stream_flush_buffer before
    _stream_fill_buffer.
    (_stream_write_unbuffered): Do not modify current offset.
    (mu_stream_read,mu_stream_write): For unbuffered streams,
    modify current offset after invoking the corresponding I/O
    call.
    (_stream_scandelim): Call _stream_flush_buffer before
    _stream_fill_buffer.

commit 78e57f7ec9df1547dd5e176a97fa1f8954b51c09
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 9 11:14:53 2010 +0200

    Fix the "UNIX mailbox first message symptom".
    
    UFMS, or "UNIX mailbox first message symptom", is a long-standing
    bug that existed in all previous versions of Mailutils:  under
    certain circumstances, a fragment of the message headers would get
    prepended to the body of the very first message in a UNIX mailbox.
    See the detailed description in testsuite/ufms.c.
    
    Along with fixing this bug, this change also ensures a proper restoring
    of UIDs from UNIX mailboxes.
    
    * libproto/mbox/mbox.c (_msg_body_setup): Call mu_body_clear_modified
    after constructing the body.
    (new_message): Ditto for mu_message_clear_modified.
    (mbox_reset): Rewrite.  Drop all cached messages and rescan entire
    mailbox to avoid the "1st message symptom".
    (mbox_expunge0): Change the call to mbox_reset.
    * libproto/mbox/mboxscan.c (IS_X_UID, IS_X_IMAPBASE): New macros.
    (mbox_scan_internal): Change handling of min_uid.
    Attempt to get UID and imapbase from the corresponding message headers.
    (mbox_scan0): Reflect the above changes.
    
    * testsuite/.gitignore: Add ufms.
    * testsuite/Makefile.am (noinst_PROGRAMS): Add ufms.
    (TESTSUITE_AT): Add ufms.at.
    * testsuite/testsuite.at: Include ufms.at.
    * testsuite/ufms.at: New test case.
    * testsuite/ufms.c: New test program.
    
    * imap4d/testsuite/imap4d/expunge.exp: Fix UIDNEXT expectation.

commit 78d43b05bf6dfd37b5f251715211f48f3f22fb58
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 8 21:23:09 2010 +0200

    Begin imap client implementation.
    
    * include/mailutils/imap.h: New file.
    * include/mailutils/Makefile.am (pkginclude_HEADERS): Add imap.h
    
    * libproto/imap/capability.c: New file.
    * libproto/imap/capatst.c: New file.
    * libproto/imap/carrier.c: New file.
    * libproto/imap/connect.c: New file.
    * libproto/imap/create.c: New file.
    * libproto/imap/destroy.c: New file.
    * libproto/imap/disconnect.c: New file.
    * libproto/imap/err.c: New file.
    * libproto/imap/fake-folder.c: New file.
    * libproto/imap/logout.c: New file.
    * libproto/imap/response.c: New file.
    * libproto/imap/state.c: New file.
    * libproto/imap/tag.c: New file.
    * libproto/imap/trace.c: New file.
    * libproto/imap/Makefile.am (libmu_imap_la_SOURCES): Temporarly
    remove folder.c, mbox.c and url.c. Add new files.
    
    * mu/getarg.c: New file.
    * mu/imap.c: New file.
    * mu/verbose.c: New file.
    * mu/Makefile.am (IDLE_MODULES): New variable.
    (IMAP_C): New variable.
    (MODULES): Add $(IMAP_C).
    (mu_SOURCES): Add getarg.c and verbose.c
    (mu-setup.h, mu-setup.c): Add IDLE_MODULES both to the dependencies
    and to the mu-setup.awk command line.
    * mu/mu-setup.awk: New keyword mu-cond.
    * mu/pop.c: Add mu-cond keyword.
    
    * include/mailutils/sys/imap.h: Rewrite.
    * include/mailutils/sys/pop3.h (MU_POP3_CHECK_EAGAIN): Take into
    account MU_ERR_REPLY and MU_ERR_BADREPLY, which are recoverable errors.
    
    * libmailutils/base/list.c (mu_list_clear): Return immediately if
    list is NULL.
    * libmu_auth/sql.c (sql_escape_string): Remove unused variable.
    
    * libproto/pop/pop3_carrier.c (mu_pop3_get_carrier): Increase refcount
    on the returned stream.
    * libproto/pop/pop3_response.c (mu_pop3_response): Check POP3 reply code.

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

Summary of changes:
 imap4d/testsuite/imap4d/expunge.exp                |    2 +-
 include/mailutils/Makefile.am                      |    1 +
 include/mailutils/imap.h                           |   80 +++
 include/mailutils/sys/imap.h                       |  284 ++++-------
 include/mailutils/sys/pop3.h                       |   35 +-
 libmailutils/base/list.c                           |    4 +-
 libmailutils/stream/stream.c                       |  161 ++++---
 libmailutils/tests/wsp.c                           |    3 +-
 libmu_auth/sql.c                                   |    1 -
 libproto/imap/Makefile.am                          |   26 +-
 libproto/imap/capability.c                         |  147 ++++++
 libproto/{pop/pop3_capatst.c => imap/capatst.c}    |   13 +-
 libproto/{pop/pop3_carrier.c => imap/carrier.c}    |   32 +-
 libproto/imap/connect.c                            |  119 +++++
 libproto/{pop/pop3_create.c => imap/create.c}      |   45 +-
 libproto/{pop/pop3_destroy.c => imap/destroy.c}    |   41 +-
 .../{nntp/nntp_timeout.c => imap/disconnect.c}     |   31 +-
 .../mailbox/hdrfirst.c => libproto/imap/err.c      |   49 ++-
 libproto/imap/fake-folder.c                        |    7 +
 libproto/imap/id.c                                 |  180 +++++++
 libproto/imap/login.c                              |   80 +++
 libproto/{nntp/nntp_quit.c => imap/logout.c}       |   54 +-
 libproto/imap/response.c                           |  125 +++++
 libproto/{nntp/nntp_timeout.c => imap/state.c}     |   34 +-
 libproto/imap/tag.c                                |  103 ++++
 libproto/{pop/pop3_trace.c => imap/trace.c}        |   66 ++--
 libproto/mbox/mbox.c                               |   34 +-
 libproto/mbox/mboxscan.c                           |   55 ++-
 libproto/pop/Makefile.am                           |    2 +-
 libproto/pop/pop3_carrier.c                        |    1 +
 libproto/pop/pop3_response.c                       |    7 +
 mu/Makefile.am                                     |   22 +-
 mu/{cflags.c => getarg.c}                          |   68 ++-
 mu/imap.c                                          |  519 ++++++++++++++++++++
 mu/mu-setup.awk                                    |    4 +
 mu/mu.h                                            |   18 +
 mu/pop.c                                           |  182 +------
 mu/verbose.c                                       |  114 +++++
 testsuite/.gitignore                               |    1 +
 testsuite/Makefile.am                              |    4 +-
 testsuite/testsuite.at                             |    1 +
 readmsg/tests/twomsg.at => testsuite/ufms.at       |   37 +-
 testsuite/ufms.c                                   |  100 ++++
 43 files changed, 2203 insertions(+), 689 deletions(-)
 create mode 100644 include/mailutils/imap.h
 create mode 100644 libproto/imap/capability.c
 copy libproto/{pop/pop3_capatst.c => imap/capatst.c} (73%)
 copy libproto/{pop/pop3_carrier.c => imap/carrier.c} (65%)
 create mode 100644 libproto/imap/connect.c
 copy libproto/{pop/pop3_create.c => imap/create.c} (60%)
 copy libproto/{pop/pop3_destroy.c => imap/destroy.c} (62%)
 copy libproto/{nntp/nntp_timeout.c => imap/disconnect.c} (65%)
 copy libmailutils/mailbox/hdrfirst.c => libproto/imap/err.c (60%)
 create mode 100644 libproto/imap/fake-folder.c
 create mode 100644 libproto/imap/id.c
 create mode 100644 libproto/imap/login.c
 copy libproto/{nntp/nntp_quit.c => imap/logout.c} (51%)
 create mode 100644 libproto/imap/response.c
 copy libproto/{nntp/nntp_timeout.c => imap/state.c} (60%)
 create mode 100644 libproto/imap/tag.c
 copy libproto/{pop/pop3_trace.c => imap/trace.c} (61%)
 copy mu/{cflags.c => getarg.c} (50%)
 create mode 100644 mu/imap.c
 create mode 100644 mu/verbose.c
 copy readmsg/tests/twomsg.at => testsuite/ufms.at (69%)
 create mode 100644 testsuite/ufms.c

diff --git a/imap4d/testsuite/imap4d/expunge.exp b/imap4d/testsuite/imap4d/expunge.exp
index cc114c2..e410168 100644
--- a/imap4d/testsuite/imap4d/expunge.exp
+++ b/imap4d/testsuite/imap4d/expunge.exp
@@ -63,7 +63,7 @@ imap4d_test "SELECT mbox1" \
 "1 EXISTS"\
 "0 RECENT"\
 -re {OK \[UIDVALIDITY [0-9]+\] UID valididy status}\
-"OK \[UIDNEXT 2\] Predicted next uid"\
+"OK \[UIDNEXT 6\] Predicted next uid"\
 "OK \[UNSEEN 1\] first unseen messsage"\
 "FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
 "OK \[PERMANENTFLAGS (\\Answered \\Deleted \\Seen)\] Permanent flags" \
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 787d04e..cd17f85 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -52,6 +52,7 @@ pkginclude_HEADERS = \
  gsasl.h\
  guile.h\
  header.h\
+ imap.h\
  io.h\
  iterator.h\
  kwd.h\
diff --git a/include/mailutils/imap.h b/include/mailutils/imap.h
new file mode 100644
index 0000000..6d8e14a
--- /dev/null
+++ b/include/mailutils/imap.h
@@ -0,0 +1,80 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifndef _MAILUTILS_IMAP_H
+#define _MAILUTILS_IMAP_H
+
+#include <mailutils/iterator.h>
+#include <mailutils/debug.h>
+#include <mailutils/stream.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MU_IMAP_DEFAULT_PORT 143
+#define MU_IMAP_DEFAULT_SSL_PORT 993
+  
+typedef struct _mu_imap *mu_imap_t;
+
+enum mu_imap_state
+  {
+    MU_IMAP_STATE_INIT,     /* Initial state */
+    MU_IMAP_STATE_NONAUTH,  /* Non-Authenticated State */
+    MU_IMAP_STATE_AUTH,     /* Authenticated State */
+    MU_IMAP_STATE_SELECTED, /* Selected State */
+    MU_IMAP_STATE_LOGOUT    /* Logout State */
+  };
+  
+int mu_imap_create (mu_imap_t *pimap);
+void mu_imap_destroy (mu_imap_t *pimap);
+
+int mu_imap_connect (mu_imap_t imap);
+int mu_imap_disconnect (mu_imap_t imap);
+
+int mu_imap_capability (mu_imap_t imap, int reread, mu_iterator_t *piter);
+int mu_imap_capability_test (mu_imap_t imap, const char *name,
+			     const char **pret);
+
+int mu_imap_login (mu_imap_t imap, const char *user, const char *pass);
+int mu_imap_logout (mu_imap_t imap);
+
+int mu_imap_id (mu_imap_t imap, char **idenv, mu_list_t *plist);
+  
+int mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier);
+int mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier);
+
+#define MU_IMAP_TRACE_CLR 0
+#define MU_IMAP_TRACE_SET 1
+#define MU_IMAP_TRACE_QRY 2
+int mu_imap_trace (mu_imap_t imap, int op);
+int mu_imap_trace_mask (mu_imap_t imap, int op, int lev);
+
+int mu_imap_strerror (mu_imap_t imap, const char **pstr);
+
+int mu_imap_state (mu_imap_t imap, int *pstate);
+int mu_imap_state_str (int state, const char **pstr);
+
+int mu_imap_tag (mu_imap_t imap, const char **pseq);
+  
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _MAILUTILS_IMAP_H */
+  
+  
diff --git a/include/mailutils/sys/imap.h b/include/mailutils/sys/imap.h
index 6bb154d..d23f597 100644
--- a/include/mailutils/sys/imap.h
+++ b/include/mailutils/sys/imap.h
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2005, 2007, 2009, 2010 Free Software
-   Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -13,7 +12,7 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see 
+   Public License along with this library.  If not, see
    <http://www.gnu.org/licenses/>. */
 
 #ifndef _MAILUTILS_SYS_IMAP_H
@@ -23,211 +22,122 @@
 # include <mailutils/sys/mailbox.h>
 # include <mailutils/sys/registrar.h>
 # include <mailutils/sys/auth.h>
+# include <mailutils/imap.h>
 
 # ifdef __cplusplus
 extern "C" {
 # endif
 
-# define CLEAR_STATE(f_imap)				\
- f_imap->selected = NULL, f_imap->state = IMAP_NO_STATE
-
-/* Clear the state and close the stream.  */
-# define CHECK_ERROR_CLOSE(folder, f_imap, status)	\
-  do							\
-    {							\
-      if (status != 0)					\
-	{						\
-          mu_stream_close (folder->stream);		\
-          CLEAR_STATE (f_imap);				\
-          return status;				\
-	}						\
-    }							\
-  while (0)
+#define MU_IMAP_RESP  0x01
+#define MU_IMAP_TRACE 0x02  
+#define MU_IMAP_XSCRIPT_MASK(n) (1<<((n)+1))
+
+enum mu_imap_client_state
+  {
+    MU_IMAP_NO_STATE,
+    MU_IMAP_ERROR,
+    MU_IMAP_CONNECT,
+    MU_IMAP_GREETINGS,
+    MU_IMAP_CONNECTED,
+    MU_IMAP_CAPABILITY_RX,
+    MU_IMAP_LOGIN_RX,
+    MU_IMAP_LOGOUT_RX,
+    MU_IMAP_ID_RX,
+  };
+
+enum mu_imap_response
+  {
+    MU_IMAP_OK,
+    MU_IMAP_NO,
+    MU_IMAP_BAD
+  };
+  
+struct _mu_imap
+  {
+    int flags;
+
+    /* Holds the tagged response to the last command */
+    char *tagbuf;
+    size_t tagsize;
+    enum mu_imap_response resp_code;
+    
+    /* Untagged responses */
+    mu_list_t untagged_resp;
+
+    /* Error string (if any) */
+    char *errstr;
+    size_t errsize;
+    
+    /* Input line buffer */
+    char *rdbuf;
+    size_t rdsize;
+
+    enum mu_imap_state state;
+    enum mu_imap_state imap_state;
+
+    /* Tag */
+    size_t tag_len;  /* Length of the command tag */
+    int *tag_buf;    /* Tag number (BCD) */
+    char *tag_str;   /* String representation (tag_len + 1 bytes, asciiz) */
+    
+    mu_list_t capa;
+    mu_stream_t carrier;
+};
+
+#define MU_IMAP_FSET(p,f) ((p)->flags |= (f))
+#define MU_IMAP_FISSET(p,f) ((p)->flags & (f))  
+#define MU_IMAP_FCLR(p,f) ((p)->flags &= ~(f))
 
-/* Clear the state.  */
-# define CHECK_ERROR(f_imap, status)		\
+int _mu_imap_init (mu_imap_t imap);
+int _mu_imap_trace_enable (mu_imap_t imap);
+int _mu_imap_trace_disable (mu_imap_t imap);
+int _mu_imap_xscript_level (mu_imap_t imap, int xlev);
+
+/* If status indicates an error, return.
+  */
+#define MU_IMAP_CHECK_ERROR(imap, status)	\
   do						\
     {						\
       if (status != 0)				\
 	{					\
-          CLEAR_STATE (f_imap);			\
+          imap->state = MU_IMAP_ERROR;		\
           return status;			\
 	}					\
     }						\
-while (0)
+  while (0)
 
-/* Clear the state for non recoverable error.  */
-# define CHECK_EAGAIN(f_imap, status)		\
+/* Check if status indicates an error.
+   If the error is recoverable just return the status.
+   Otherwise, set the error state and return the status
+ */
+#define MU_IMAP_CHECK_EAGAIN(imap, status)	\
   do						\
     {						\
-      if (status != 0)				\
-	{								\
-	  if (status != EAGAIN && status != EINPROGRESS && status != EINTR) \
-	    {								\
-	      CLEAR_STATE (f_imap);					\
-	    }								\
-	  return status;						\
-	}								\
-    }									\
+      switch (status)				\
+	{					\
+        case 0:                                 \
+	  break;				\
+        case EAGAIN:                            \
+        case EINPROGRESS:                       \
+        case EINTR:                             \
+        case MU_ERR_REPLY:                      \
+        case MU_ERR_BADREPLY:                   \
+	  return status;                        \
+        default:                                \
+          imap->state = MU_IMAP_ERROR;		\
+	  return status;			\
+	}					\
+    }						\
   while (0)
 
-struct _f_imap;
-struct _m_imap;
-struct _msg_imap;
-typedef struct _f_imap *f_imap_t;
-typedef struct _m_imap *m_imap_t;
-typedef struct _msg_imap *msg_imap_t;
-
-enum imap_state
-{
-  IMAP_NO_STATE=0,
-  IMAP_AUTH, IMAP_AUTH_DONE,
-  IMAP_APPEND, IMAP_APPEND_CONT, IMAP_APPEND_SEND, IMAP_APPEND_ACK,
-  IMAP_BODY,
-  IMAP_CLOSE, IMAP_CLOSE_ACK,
-  IMAP_COPY, IMAP_COPY_ACK,
-  IMAP_CREATE, IMAP_CREATE_ACK,
-  IMAP_DELETE, IMAP_DELETE_ACK,
-  IMAP_EXPUNGE, IMAP_EXPUNGE_ACK,
-  IMAP_FETCH, IMAP_FETCH_ACK,
-  IMAP_GREETINGS,
-  IMAP_HEADER,
-  IMAP_HEADER_FIELD,
-  IMAP_LIST, IMAP_LIST_PARSE, IMAP_LIST_ACK,
-  IMAP_LOGIN, IMAP_LOGIN_ACK,
-  IMAP_LOGOUT, IMAP_LOGOUT_ACK,
-  IMAP_LSUB, IMAP_LSUB_ACK,
-  IMAP_MESSAGE,
-  IMAP_NOOP, IMAP_NOOP_ACK,
-  IMAP_OPEN_CONNECTION,
-  IMAP_RENAME, IMAP_RENAME_ACK,
-  IMAP_SCAN, IMAP_SCAN_ACK,
-  IMAP_SELECT, IMAP_SELECT_ACK,
-  IMAP_STORE, IMAP_STORE_ACK,
-  IMAP_SUBSCRIBE, IMAP_SUBSCRIBE_ACK,
-  IMAP_UNSUBSCRIBE, IMAP_UNSUBSCRIBE_ACK
-};
+int _mu_imap_seterrstr (mu_imap_t imap, const char *str, size_t len);
+void _mu_imap_clrerrstr (mu_imap_t imap);
 
-enum imap_auth_state
-{
-  /* ANONYMOUS */
-  IMAP_AUTH_ANON_REQ_WRITE,
-  IMAP_AUTH_ANON_REQ_SEND,
-  IMAP_AUTH_ANON_WAIT_CONT,
-  IMAP_AUTH_ANON_MSG,
-  IMAP_AUTH_ANON_MSG_SEND,
-  IMAP_AUTH_ANON_WAIT_RESP
-};
-
-struct literal_string
-{
-  char *buffer;
-  size_t buflen;
-  size_t total;
-  msg_imap_t msg_imap;
-  enum imap_state type;
-  size_t nleft;  /* nleft to read in the literal. */
-};
-
-struct _f_imap
-{
-  /* Back pointer.  */
-  mu_folder_t folder;
-  m_imap_t selected;
+int _mu_imap_tag_next (mu_imap_t imap);
+int _mu_imap_tag_clr (mu_imap_t imap);
 
-  enum imap_state state;
-  int imaps; /* IMAPS or IMAP? */
-
-  size_t seq; /* Sequence number to build a tag.  */
-  char **capav; /* Cabilities of the server.  */
-  int capac;    /* Number of capabilities in the above array */
-  int flags;
-
-  /* IO use to hold the literal and quoted strings send by
-     the IMAP server.  */
-  struct
-  {
-    mu_stream_t stream;
-    mu_off_t offset;
-    size_t nleft;  /* nleft to read in the literal. */
-    msg_imap_t msg_imap;
-    enum imap_state type;
-  } string;
-
-  /* Use for LIST and LSUB.  */
-  mu_list_t flist;
-  mu_folder_enumerate_fp enum_fun;
-  void *enum_data;
-  int enum_stop;
+int _mu_imap_response (mu_imap_t imap);
   
-  int isopen;
-
-  /* Server channel buffer I/O  */
-  size_t buflen;
-  char *buffer;
-  char *ptr;
-  char *nl;
-  mu_off_t offset; /* Dummy, this is used because of the stream buffering.
-                   The mu_stream_t maintains and offset and the offset we
-		   use must be in sync.  */
-
-  /* Login  */
-  char *user;
-  mu_secret_t secret;
-
-  /* AUTHENTICATE states */
-  enum imap_auth_state auth_state;
-};
-
-struct _m_imap
-{
-  /* Back pointers.  */
-  mu_mailbox_t mailbox;
-  f_imap_t f_imap;
-  size_t messages_count;
-  size_t imessages_count;
-  msg_imap_t *imessages;
-  size_t recent;
-  size_t unseen;
-  unsigned long uidvalidity;
-  size_t uidnext;
-  char *name;
-  enum imap_state state;
-    /* mailbox operations can be sequences of folder operations, and
-       thus need to keep meta-state, mailbox_imap_open(), for example. */
-};
-
-struct _msg_imap
-{
-  /* Back pointers.  */
-  mu_message_t message;
-  m_imap_t m_imap;
-  size_t num;
-  size_t part;
-  size_t num_parts;
-  msg_imap_t *parts;
-  msg_imap_t parent;
-  int flags;
-  size_t uid;
-
-  mu_header_t fheader;
-  char *internal_date;
-
-  size_t mu_message_size;
-  size_t mu_message_lines;
-  size_t body_size;
-  size_t body_lines;
-  size_t header_size;
-  size_t header_lines;
-};
-
-int imap_writeline    (f_imap_t,  const char *format, ...) MU_PRINTFLIKE(2,3);
-int imap_write        (f_imap_t);
-int imap_send         (f_imap_t);
-int imap_parse        (f_imap_t);
-int imap_readline     (f_imap_t);
-char *section_name    (msg_imap_t);
-
 # ifdef __cplusplus
 }
 # endif
diff --git a/include/mailutils/sys/pop3.h b/include/mailutils/sys/pop3.h
index 96d8d61..eba6f57 100644
--- a/include/mailutils/sys/pop3.h
+++ b/include/mailutils/sys/pop3.h
@@ -93,28 +93,31 @@ int _mu_pop3_trace_disable (mu_pop3_t pop3);
 
 int _mu_pop3_init (mu_pop3_t pop3);
   
-/* Check for non recoverable error.
-   The error is consider not recoverable if not part of the signal set:
-   EAGAIN, EINPROGRESS, EINTR.
-   For unrecoverable error we reset, by moving the working ptr
-   to the begining of the buffer and setting the state to error.
+/* Check if status indicates an error.
+   If the error is recoverable just return the status.
+   Otherwise, set the error state and return the status
  */
 #define MU_POP3_CHECK_EAGAIN(pop3, status)	\
   do						\
     {						\
-      if (status != 0)				\
-	{								\
-	  if (status != EAGAIN && status != EINPROGRESS && status != EINTR) \
-	    {								\
-	      pop3->state = MU_POP3_ERROR;				\
-	    }								\
-	  return status;						\
-	}								\
-    }									\
+      switch (status)				\
+	{					\
+        case 0:                                 \
+	  break;				\
+        case EAGAIN:                            \
+        case EINPROGRESS:                       \
+        case EINTR:                             \
+        case MU_ERR_REPLY:                      \
+        case MU_ERR_BADREPLY:                   \
+	  return status;                        \
+        default:                                \
+          pop3->state = MU_POP3_ERROR;		\
+	  return status;			\
+	}					\
+    }						\
   while (0)
 
-/* If error return.
-   Check status an reset(see MU_POP2_CHECK_EAGAIN) the buffer.
+/* If status indicates an error, return.
   */
 #define MU_POP3_CHECK_ERROR(pop3, status)	\
   do						\
diff --git a/libmailutils/base/list.c b/libmailutils/base/list.c
index 9147ef8..89240ce 100644
--- a/libmailutils/base/list.c
+++ b/libmailutils/base/list.c
@@ -64,7 +64,9 @@ mu_list_clear (mu_list_t list)
 {
   struct list_data *current;
   struct list_data *previous;
-  
+
+  if (!list)
+    return;
   mu_monitor_wrlock (list->monitor);
   for (current = list->head.next; current != &list->head;)
     {
diff --git a/libmailutils/stream/stream.c b/libmailutils/stream/stream.c
index 6084479..367db90 100644
--- a/libmailutils/stream/stream.c
+++ b/libmailutils/stream/stream.c
@@ -110,7 +110,6 @@ _stream_fill_buffer (struct _mu_stream *stream)
   int rc = 0;
   char c;
 
-  stream->offset += stream->level;
   switch (stream->buftype)
     {
     case mu_buffer_none:
@@ -127,7 +126,8 @@ _stream_fill_buffer (struct _mu_stream *stream)
       for (n = 0;
 	   n < stream->bufsize
 	     && (rc = _stream_read_unbuffered (stream,
-					       &c, 1, 0, &rdn)) == 0;)
+					       &c, 1,
+					       0, &rdn)) == 0;)
 	{
 	  if (rdn == 0)
 	    {
@@ -143,7 +143,6 @@ _stream_fill_buffer (struct _mu_stream *stream)
     }
   if (rc == 0)
     {
-      stream->offset -= stream->level;
       stream->pos = 0;
       _stream_event (stream, _MU_STR_EVENT_FILLBUF,
 		     stream->level, _stream_curp (stream));
@@ -193,7 +192,8 @@ _stream_flush_buffer (struct _mu_stream *stream, int flags)
 	    
 	case mu_buffer_full:
 	  if ((rc = _stream_write_unbuffered (stream, stream->buffer,
-					      stream->level, 1, NULL)))
+					      stream->level,
+					      1, NULL)))
 	    return rc;
 	  _stream_event (stream, _MU_STR_EVENT_FLUSHBUF,
 			 stream->level, stream->buffer);
@@ -208,7 +208,8 @@ _stream_flush_buffer (struct _mu_stream *stream, int flags)
 	       end = memchr (start, '\n', wrsize))
 	    {
 	      size_t size = end - start + 1;
-	      rc = _stream_write_unbuffered (stream, start, size, 1, NULL);
+	      rc = _stream_write_unbuffered (stream, start, size,
+					     1, NULL);
 	      if (rc)
 		return rc;
 	      _stream_event (stream, _MU_STR_EVENT_FLUSHBUF,
@@ -231,18 +232,26 @@ _stream_flush_buffer (struct _mu_stream *stream, int flags)
 			     wrsize, stream->buffer);
 	      wrsize = 0;
 	    }
-	  if (wrsize)
-	    memmove (stream->buffer, start, wrsize);
-	  else
-	    _stream_clrflag (stream, _MU_STR_DIRTY);
-	  stream->level = stream->pos = wrsize;
-	  return 0;
+	  if (!(flags & _MU_STR_FLUSH_KEEP))
+	    {
+	      if (wrsize)
+		memmove (stream->buffer, start, wrsize);
+	      else
+		_stream_clrflag (stream, _MU_STR_DIRTY);
+	      stream->offset += stream->level - wrsize;
+	      stream->level = stream->pos = wrsize;
+	      return 0;
+	    }
 	}
       _stream_clrflag (stream, _MU_STR_DIRTY);
     }
 
   if (!(flags & _MU_STR_FLUSH_KEEP))
-    stream->pos = stream->level = 0;
+    {
+      stream->offset += stream->level;
+      stream->pos = stream->level = 0;
+    }
+  
   return 0;
 }
 
@@ -413,19 +422,21 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence,
       return mu_stream_seterr (stream, EINVAL, 1);
     }
 
-  if (stream->buftype == mu_buffer_none ?
-      (offset != stream->offset)
-       : (stream->level == 0
-	  || offset < stream->offset
-	  || offset > stream->offset + stream->level))
+  if (!(stream->buftype == mu_buffer_none ?
+	(offset == stream->offset)
+	: (stream->offset <= offset &&
+	   offset < stream->offset + stream->level)))
     {
       if ((rc = _stream_flush_buffer (stream, _MU_STR_FLUSH_ALL)))
 	return rc;
-      rc = stream->seek (stream, offset, &stream->offset);
-      if (rc == ESPIPE)
-	return rc;
-      if (rc)
-	return mu_stream_seterr (stream, rc, 1);
+      if (stream->offset != offset)
+	{
+	  rc = stream->seek (stream, offset, &stream->offset);
+	  if (rc == ESPIPE)
+	    return rc;
+	  if (rc)
+	    return mu_stream_seterr (stream, rc, 1);
+	}
       _mu_stream_cleareof (stream);
     }
   else if (stream->buftype != mu_buffer_none)
@@ -476,10 +487,10 @@ _stream_skip_input_bytes (mu_stream_t stream, mu_off_t count, mu_off_t *pres)
 	{
 	  for (pos = 0;;)
 	    {
-	      if ((rc = _stream_flush_buffer (stream, _MU_STR_FLUSH_ALL)))
-		return rc;
 	      if (stream->pos == stream->level)
 		{
+		  if ((rc = _stream_flush_buffer (stream, _MU_STR_FLUSH_ALL)))
+		    return rc;
 		  rc = _stream_fill_buffer (stream);
 		  if (rc)
 		    break;
@@ -585,44 +596,42 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size,
       return 0;
     }
     
-    if (full_read)
-      {
-	size_t rdbytes;
-
-	nread = 0;
-	while (size > 0
-	       && (rc = stream->read (stream, buf, size, &rdbytes)) == 0)
-	  {
-	    if (rdbytes == 0)
-	      {
-		_stream_setflag (stream, _MU_STR_EOF);
-		break;
-	      }
-	    buf += rdbytes;
-	    nread += rdbytes;
-	    size -= rdbytes;
-	    stream->bytes_in += rdbytes;
-	    
-	  }
-	if (size && rc)
-	  rc = mu_stream_seterr (stream, rc, 0);
-      }
-    else
-      {
-	rc = stream->read (stream, buf, size, &nread);
-	if (rc == 0)
-	  {
-	    if (nread == 0)
+  if (full_read)
+    {
+      size_t rdbytes;
+
+      nread = 0;
+      while (size > 0
+	     && (rc = stream->read (stream, buf, size, &rdbytes)) == 0)
+	{
+	  if (rdbytes == 0)
+	    {
 	      _stream_setflag (stream, _MU_STR_EOF);
-	    stream->bytes_in += nread;
-	  }
-	mu_stream_seterr (stream, rc, rc != 0);
-      }
-    stream->offset += nread;
-    if (pnread)
-      *pnread = nread;
-    
-    return rc;
+	      break;
+	    }
+	  buf += rdbytes;
+	  nread += rdbytes;
+	  size -= rdbytes;
+	  stream->bytes_in += rdbytes;
+	}
+      if (size && rc)
+	rc = mu_stream_seterr (stream, rc, 0);
+    }
+  else
+    {
+      rc = stream->read (stream, buf, size, &nread);
+      if (rc == 0)
+	{
+	  if (nread == 0)
+	    _stream_setflag (stream, _MU_STR_EOF);
+	  stream->bytes_in += nread;
+	}
+      mu_stream_seterr (stream, rc, rc != 0);
+    }
+  if (pnread)
+    *pnread = nread;
+  
+  return rc;
 }
 
 static int
@@ -657,7 +666,7 @@ _stream_write_unbuffered (mu_stream_t stream,
       nwritten = 0;
       while (size > 0
 	     && (rc = stream->write (stream, bufp, size, &wrbytes))
-	             == 0)
+	     == 0)
 	{
 	  if (wrbytes == 0)
 	    {
@@ -677,7 +686,6 @@ _stream_write_unbuffered (mu_stream_t stream,
 	stream->bytes_out += nwritten;
     }
   _stream_setflag (stream, _MU_STR_WRT);
-  stream->offset += nwritten;
   if (pnwritten)
     *pnwritten = nwritten;
   mu_stream_seterr (stream, rc, rc != 0);
@@ -695,7 +703,14 @@ mu_stream_read (mu_stream_t stream, void *buf, size_t size, size_t *pread)
     }
   
   if (stream->buftype == mu_buffer_none)
-    return _stream_read_unbuffered (stream, buf, size, !pread, pread);
+    {
+      size_t nread = 0;
+      int rc = _stream_read_unbuffered (stream, buf, size, !pread, &nread);
+      stream->offset += nread;
+      if (pread)
+	*pread = nread;
+      return rc;
+    }
   else
     {
       char *bufp = buf;
@@ -712,6 +727,12 @@ mu_stream_read (mu_stream_t stream, void *buf, size_t size, size_t *pread)
 	  
 	  if (stream->pos == stream->level)
 	    {
+	      if ((rc = _stream_flush_buffer (stream, _MU_STR_FLUSH_ALL)))
+		{
+		  if (nbytes)
+		    break;
+		  return rc;
+		}
 	      if ((rc = _stream_fill_buffer (stream)))
 		{
 		  if (nbytes)
@@ -757,6 +778,8 @@ _stream_scandelim (mu_stream_t stream, char *buf, size_t size, int delim,
       
       if (stream->pos == stream->level)
 	{
+	  if ((rc = _stream_flush_buffer (stream, _MU_STR_FLUSH_ALL)))
+	    break;
 	  if ((rc = _stream_fill_buffer (stream)) || stream->level == 0)
 	    break;
 	}
@@ -959,8 +982,14 @@ mu_stream_write (mu_stream_t stream, const void *buf, size_t size,
     }
 
   if (stream->buftype == mu_buffer_none)
-    rc = _stream_write_unbuffered (stream, buf, size,
-				   !pnwritten, pnwritten);
+    {
+      size_t nwritten;
+      rc = _stream_write_unbuffered (stream, buf, size,
+				     !pnwritten, &nwritten);
+      stream->offset += nwritten;
+      if (pnwritten)
+	*pnwritten = nwritten;
+    }
   else
     {
       size_t nbytes = 0;
diff --git a/libmailutils/tests/wsp.c b/libmailutils/tests/wsp.c
index bbb3416..b6c2a66 100644
--- a/libmailutils/tests/wsp.c
+++ b/libmailutils/tests/wsp.c
@@ -33,6 +33,7 @@ struct mu_kwd bool_keytab[] = {
   /*{ "reuse",  MU_WRDSF_REUSE },*/
   { "undef",  MU_WRDSF_UNDEF },
   { "novar",  MU_WRDSF_NOVAR },
+  { "nocmd",  MU_WRDSF_NOCMD },
   { "ws",     MU_WRDSF_WS },
   { "quote",  MU_WRDSF_QUOTE },
   { "squeeze_delims", MU_WRDSF_SQUEEZE_DELIMS },
@@ -205,7 +206,7 @@ main (int argc, char **argv)
 	  plaintext_option = !negate;
 	  continue;
 	}
-	  
+    
       if (mu_kwd_xlat_name (bool_keytab, opt, &flag) == 0)
 	{
 	  if (negate)
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index c4e3dfb..20b79db 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -88,7 +88,6 @@ sql_escape_string (const char *ustr)
 char *
 mu_sql_expand_query (const char *query, const char *ustr)
 {
-  int rc;
   char *res;
   char *esc_ustr;
   struct mu_wordsplit ws;
diff --git a/libproto/imap/Makefile.am b/libproto/imap/Makefile.am
index 7c01741..efbf0db 100644
--- a/libproto/imap/Makefile.am
+++ b/libproto/imap/Makefile.am
@@ -13,7 +13,7 @@
 ## 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/>. 
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
@@ -21,8 +21,26 @@ lib_LTLIBRARIES = libmu_imap.la
 libmu_imap_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
 libmu_imap_la_LIBADD = ${MU_LIB_AUTH} ${MU_LIB_MAILUTILS} @INTLLIBS@ 
 
+# FIXME: Put these back when ready
+
+#  folder.c\
+#  mbox.c\
+#  url.c
 libmu_imap_la_SOURCES = \
- folder.c\
- mbox.c\
- url.c
+ fake-folder.c\
+ capability.c\
+ capatst.c\
+ carrier.c\
+ connect.c\
+ create.c\
+ destroy.c\
+ disconnect.c\
+ err.c\
+ id.c\
+ login.c\
+ logout.c\
+ response.c\
+ state.c\
+ tag.c\
+ trace.c
 
diff --git a/libproto/imap/capability.c b/libproto/imap/capability.c
new file mode 100644
index 0000000..a2f1aac
--- /dev/null
+++ b/libproto/imap/capability.c
@@ -0,0 +1,147 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/list.h>
+#include <mailutils/wordsplit.h>
+#include <mailutils/sys/imap.h>
+
+static int
+capa_comp (const void *item, const void *value)
+{
+  const char *capa = item;
+  const char *needle = value;
+  for (; *needle; capa++, needle++)
+    {
+      if (!*capa)
+	return 1;
+      if (mu_tolower (*capa) != mu_tolower (*needle))
+	return 1;
+    }
+  return !(*capa == 0 || *capa == '=');
+}
+
+int
+mu_imap_capability (mu_imap_t imap, int reread, mu_iterator_t *piter)
+{
+  int status;
+  
+  if (imap == NULL)
+    return EINVAL;
+  if (!imap->carrier)
+    return MU_ERR_NO_TRANSPORT;
+  if (imap->state != MU_IMAP_CONNECTED)
+    return MU_ERR_SEQ;
+
+  if (imap->capa)
+    {
+      if (!reread)
+	{
+	  if (!piter)
+	    return 0;
+	  return mu_list_get_iterator (imap->capa, piter);
+	}
+      mu_list_clear (imap->capa);
+    }
+  else
+    {
+      status = mu_list_create (&imap->capa);
+      MU_IMAP_CHECK_ERROR (imap, status);
+      mu_list_set_comparator (imap->capa, capa_comp);
+      mu_list_set_destroy_item (imap->capa, mu_list_free_item);
+    }
+
+  switch (imap->state)
+    {
+    case MU_IMAP_CONNECTED:
+      status = _mu_imap_tag_next (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      status = mu_stream_printf (imap->carrier, "%s CAPABILITY\r\n",
+				 imap->tag_str); 
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      MU_IMAP_FCLR (imap, MU_IMAP_RESP);
+      imap->state = MU_IMAP_CAPABILITY_RX;
+
+    case MU_IMAP_CAPABILITY_RX:
+      status = _mu_imap_response (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      if (imap->resp_code != MU_IMAP_OK)
+	return MU_ERR_REPLY;
+      else
+	{
+	  size_t count;
+	  char *str;
+	  
+	  imap->state = MU_IMAP_CONNECTED;
+	  mu_list_count (imap->untagged_resp, &count);
+	  if (mu_list_get (imap->untagged_resp, 0, (void*)&str) == 0)
+	    {
+	      size_t i;
+	      
+	      struct mu_wordsplit ws;
+
+	      if (mu_wordsplit (str, &ws,
+				MU_WRDSF_NOVAR | MU_WRDSF_NOCMD |
+				MU_WRDSF_QUOTE | MU_WRDSF_SQUEEZE_DELIMS))
+		{
+		  int ec = errno;
+		  mu_error ("mu_imap_capability: cannot split line: %s",
+			    mu_wordsplit_strerror (&ws));
+		  return ec;
+		}
+	      if (ws.ws_wordc > 1 &&
+		  mu_c_strcasecmp (ws.ws_wordv[0], "CAPABILITY") == 0)
+		{
+		  for (i = 1; i < ws.ws_wordc; i++)
+		    {
+		      mu_list_append (imap->capa, ws.ws_wordv[i]);
+		      ws.ws_wordv[i] = NULL;
+		    }
+		}
+	      mu_wordsplit_free (&ws);
+	    }
+	  if (piter)
+	    status = mu_list_get_iterator (imap->capa, piter);
+	  else
+	    status = 0;
+	}  
+      break;
+      
+    case MU_IMAP_ERROR:
+      status = ECANCELED;
+      break;
+
+    default:
+      status = EINPROGRESS;
+    }
+  return status;
+}
+    
+
+  
+
+  
+  
+
diff --git a/libproto/pop/pop3_capatst.c b/libproto/imap/capatst.c
similarity index 73%
copy from libproto/pop/pop3_capatst.c
copy to libproto/imap/capatst.c
index 4fd4466..e14dff6 100644
--- a/libproto/pop/pop3_capatst.c
+++ b/libproto/imap/capatst.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2004, 2005, 2007, 2010 Free Software Foundation,
-   Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -20,17 +19,17 @@
 # include <config.h>
 #endif
 
-#include <stdlib.h>
+#include <mailutils/types.h>
 #include <mailutils/list.h>
-#include <mailutils/sys/pop3.h>
+#include <mailutils/sys/imap.h>
 
 int
-mu_pop3_capa_test (mu_pop3_t pop3, const char *name, const char **pret)
+mu_imap_capability_test (mu_imap_t imap, const char *name, const char **pret)
 {
   int rc;
 
-  rc = mu_pop3_capa (pop3, 0, NULL);
+  rc = mu_imap_capability (imap, 0, NULL);
   if (rc)
     return rc;
-  return mu_list_locate (pop3->capa, (void*) name, (void**)pret);
+  return mu_list_locate (imap->capa, (void*) name, (void**)pret);
 }
diff --git a/libproto/pop/pop3_carrier.c b/libproto/imap/carrier.c
similarity index 65%
copy from libproto/pop/pop3_carrier.c
copy to libproto/imap/carrier.c
index 265669d..78398c0 100644
--- a/libproto/pop/pop3_carrier.c
+++ b/libproto/imap/carrier.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2004, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -22,39 +22,41 @@
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <mailutils/sys/pop3.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/imap.h>
 
 int
-mu_pop3_set_carrier (mu_pop3_t pop3, mu_stream_t carrier)
+mu_imap_set_carrier (mu_imap_t imap, mu_stream_t carrier)
 {
   /* Sanity checks.  */
-  if (pop3 == NULL)
+  if (imap == NULL)
     return EINVAL;
 
-  if (pop3->carrier)
+  if (imap->carrier)
     {
       /* Close any old carrier.  */
-      mu_pop3_disconnect (pop3);
-      mu_stream_destroy (&pop3->carrier);
+      mu_imap_disconnect (imap);
+      mu_stream_destroy (&imap->carrier);
     }
   mu_stream_ref (carrier);
-  pop3->carrier = carrier;
-  if (MU_POP3_FISSET (pop3, MU_POP3_TRACE))
-    _mu_pop3_trace_enable (pop3);
-  pop3->state = MU_POP3_CONNECT;
+  imap->carrier = carrier;
+  if (MU_IMAP_FISSET (imap, MU_IMAP_TRACE))
+    _mu_imap_trace_enable (imap);
+  imap->state = MU_IMAP_CONNECT;
   return 0;
 }
 
-/* FIXME: Is it needed? */
 int
-mu_pop3_get_carrier (mu_pop3_t pop3, mu_stream_t *pcarrier)
+mu_imap_get_carrier (mu_imap_t imap, mu_stream_t *pcarrier)
 {
   /* Sanity checks.  */
-  if (pop3 == NULL)
+  if (imap == NULL)
     return EINVAL;
   if (pcarrier == NULL)
     return MU_ERR_OUT_PTR_NULL;
 
-  *pcarrier = pop3->carrier;
+  mu_stream_ref (imap->carrier);
+  *pcarrier = imap->carrier;
   return 0;
 }
+
diff --git a/libproto/imap/connect.c b/libproto/imap/connect.c
new file mode 100644
index 0000000..621035b
--- /dev/null
+++ b/libproto/imap/connect.c
@@ -0,0 +1,119 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <mailutils/errno.h>
+#include <mailutils/wordsplit.h>
+#include <mailutils/sys/imap.h>
+
+
+int
+mu_imap_connect (mu_imap_t imap)
+{
+  int status;
+
+  if (imap == NULL)
+    return EINVAL;
+  if (imap->carrier == NULL)
+    return EINVAL;
+  switch (imap->state)
+    {
+    default:
+    case MU_IMAP_NO_STATE:
+      status = mu_imap_disconnect (imap);
+      if (status != 0)
+	{
+	  /* Sleep for 2 seconds (FIXME: Must be configurable) */
+	  struct timeval tval;
+	  tval.tv_sec = 2;
+	  tval.tv_usec = 0;
+	  select (0, NULL, NULL, NULL, &tval);
+	}
+      imap->state = MU_IMAP_CONNECT;
+
+    case MU_IMAP_CONNECT:
+      /* Establish the connection.  */
+      if (!mu_stream_is_open (imap->carrier))
+        {
+          status = mu_stream_open (imap->carrier);
+          MU_IMAP_CHECK_EAGAIN (imap, status);
+          MU_IMAP_FCLR (imap, MU_IMAP_RESP);
+        }
+      imap->state = MU_IMAP_GREETINGS;
+
+    case MU_IMAP_GREETINGS:
+      status = mu_stream_getline (imap->carrier, &imap->rdbuf,
+				  &imap->rdsize, NULL);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      if (imap->rdsize < 2 ||
+	  !(imap->rdbuf[0] == '*' && imap->rdbuf[1] == ' '))
+	{
+	  mu_error ("mu_imap_connect: invalid server response: %s",
+		    imap->rdbuf);
+	  imap->state = MU_IMAP_ERROR;
+	  return MU_ERR_BADREPLY;
+	}
+      else
+	{
+	  struct mu_wordsplit ws;
+	  
+ 	  if (mu_wordsplit (imap->rdbuf, &ws,
+			    MU_WRDSF_NOVAR | MU_WRDSF_NOCMD |
+			    MU_WRDSF_SQUEEZE_DELIMS))
+	    {
+	      int ec = errno;
+	      mu_error ("mu_imap_connect: cannot split line: %s",
+			mu_wordsplit_strerror (&ws));
+	      imap->state = MU_IMAP_ERROR;
+	      return ec;
+	    }
+	  if (ws.ws_wordc < 2)
+	    status = MU_ERR_BADREPLY;
+	  else if (strcmp (ws.ws_wordv[1], "BYE") == 0)
+	    {
+	      status = EACCES;
+	      _mu_imap_seterrstr (imap, imap->rdbuf + 2,
+				  strlen (imap->rdbuf + 2));
+	    }
+	  else if (strcmp (ws.ws_wordv[1], "PREAUTH") == 0)
+	    {
+	      status = 0;
+	      imap->state = MU_IMAP_CONNECTED;
+	      imap->imap_state = MU_IMAP_STATE_AUTH;
+	    }
+	  else if (strcmp (ws.ws_wordv[1], "OK") == 0)
+	    {
+	      status = 0;
+	      imap->state = MU_IMAP_CONNECTED;
+	      imap->imap_state = MU_IMAP_STATE_NONAUTH;
+	    }
+	  else
+	    {
+	      status = MU_ERR_BADREPLY;
+	      imap->state = MU_IMAP_ERROR;
+	    }
+	  mu_wordsplit_free (&ws);
+	}
+    }
+  
+  return status;
+}
diff --git a/libproto/pop/pop3_create.c b/libproto/imap/create.c
similarity index 60%
copy from libproto/pop/pop3_create.c
copy to libproto/imap/create.c
index dbb7a4b..1832910 100644
--- a/libproto/pop/pop3_create.c
+++ b/libproto/imap/create.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -22,43 +22,46 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <mailutils/errno.h>
-#include <mailutils/sys/pop3.h>
+#include <mailutils/sys/imap.h>
 #include <mailutils/list.h>
 
-/* Initialise a mu_pop3_t handle.  */
-
 int
-mu_pop3_create (mu_pop3_t *ppop3)
+mu_imap_create (mu_imap_t *pimap)
 {
-  mu_pop3_t pop3;
+  mu_imap_t imap;
 
   /* Sanity check.  */
-  if (ppop3 == NULL)
+  if (pimap == NULL)
     return EINVAL;
 
-  pop3 = calloc (1, sizeof *pop3);
-  if (pop3 == NULL)
+  imap = calloc (1, sizeof *imap);
+  if (imap == NULL)
     return ENOMEM;
 
-  pop3->state = MU_POP3_NO_STATE; /* Init with no state.  */
-  pop3->timeout = (10 * 60) * 100; /* The default Timeout is 10 minutes.  */
-  MU_POP3_FCLR (pop3, MU_POP3_ACK); /* No Ack received.  */
+  _mu_imap_init (imap);
 
-  *ppop3 = pop3;
-  return 0; /* Okdoke.  */
+  *pimap = imap;
+  return 0;
 }
 
 int
-_mu_pop3_init (mu_pop3_t pop3)
+_mu_imap_init (mu_imap_t imap)
 {
-  if (pop3 == NULL)
+  if (imap == NULL)
     return EINVAL;
-  if (pop3->carrier == 0)
+  if (imap->carrier == 0)
     {
-      mu_list_destroy (&pop3->capa);
-      pop3->flags = 0;
+      int rc;
+      
+      if (imap->untagged_resp)
+	mu_list_clear (imap->untagged_resp);
+      mu_list_destroy (&imap->capa);
+      _mu_imap_clrerrstr (imap);
+      rc = _mu_imap_tag_clr (imap);
+      imap->flags = 0;
+      if (rc)
+	return rc;
     }
+  imap->state = MU_IMAP_NO_STATE; /* Init with no state.  */
   return 0;
 }
-
-  
diff --git a/libproto/pop/pop3_destroy.c b/libproto/imap/destroy.c
similarity index 62%
copy from libproto/pop/pop3_destroy.c
copy to libproto/imap/destroy.c
index de70748..707f09b 100644
--- a/libproto/pop/pop3_destroy.c
+++ b/libproto/imap/destroy.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2003, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -21,35 +21,38 @@
 
 #include <stdlib.h>
 #include <mailutils/errno.h>
-#include <mailutils/sys/pop3.h>
+#include <mailutils/sys/imap.h>
 #include <mailutils/list.h>
 
 void
-mu_pop3_destroy (mu_pop3_t *ppop3)
+mu_imap_destroy (mu_imap_t *pimap)
 {
-  if (ppop3 && *ppop3)
+  if (pimap && *pimap)
     {
-      mu_pop3_t pop3 = *ppop3;
-
+      mu_imap_t imap = *pimap;
+      
       /* Free the response buffer.  */
-      if (pop3->ackbuf)
-	free (pop3->ackbuf);
+      if (imap->tagbuf)
+	free (imap->tagbuf);
       /* Free the read buffer.  */
-      if (pop3->rdbuf)
-	free (pop3->rdbuf);
+      if (imap->rdbuf)
+	free (imap->rdbuf);
 
-      /* Free the timestamp use for APOP.  */
-      if (pop3->timestamp)
-	free (pop3->timestamp);
+      if (imap->errstr)
+	free (imap->errstr);
 
-      mu_list_destroy (&pop3->capa);
+      if (imap->tag_str)
+	free (imap->tag_str);
+      if (imap->tag_buf)
+	free (imap->tag_buf);
+      
+      mu_list_destroy (&imap->untagged_resp);
+      mu_list_destroy (&imap->capa);
       
-      /* Release the carrier.  */
-      if (pop3->carrier)
-	mu_stream_destroy (&pop3->carrier);
+      mu_stream_destroy (&imap->carrier);
 
-      free (pop3);
+      free (imap);
 
-      *ppop3 = NULL;
+      *pimap = NULL;
     }
 }
diff --git a/libproto/nntp/nntp_timeout.c b/libproto/imap/disconnect.c
similarity index 65%
copy from libproto/nntp/nntp_timeout.c
copy to libproto/imap/disconnect.c
index 8b35ed0..a376ace 100644
--- a/libproto/nntp/nntp_timeout.c
+++ b/libproto/imap/disconnect.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2004, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -20,29 +20,28 @@
 #endif
 
 #include <stdlib.h>
+#include <string.h>
 #include <errno.h>
-#include <mailutils/sys/nntp.h>
+#include <mailutils/sys/imap.h>
 
 int
-mu_nntp_set_timeout (mu_nntp_t nntp, int timeout)
+mu_imap_disconnect (mu_imap_t imap)
 {
   /* Sanity checks.  */
-  if (nntp == NULL)
+  if (imap == NULL)
     return EINVAL;
 
-  nntp->timeout = timeout;
-  return 0;
-}
+  imap->state = MU_IMAP_NO_STATE;
+  MU_IMAP_FCLR (imap, MU_IMAP_RESP);
 
-int
-mu_nntp_get_timeout (mu_nntp_t nntp, int *ptimeout)
-{
-  /* Sanity checks.  */
-  if (nntp == NULL)
-    return EINVAL;
-  if (ptimeout == NULL)
-    return MU_ERR_OUT_PTR_NULL;
+  if (imap->rdbuf)
+    imap->rdbuf[0] = 0;
 
-  *ptimeout = nntp->timeout;
+  mu_list_clear (imap->untagged_resp);
+  mu_list_clear (imap->capa);
+  
+  /* Close the stream.  */
+  if (mu_stream_is_open (imap->carrier))
+    return mu_stream_close (imap->carrier);
   return 0;
 }
diff --git a/libmailutils/mailbox/hdrfirst.c b/libproto/imap/err.c
similarity index 60%
copy from libmailutils/mailbox/hdrfirst.c
copy to libproto/imap/err.c
index 363021f..8b49072 100644
--- a/libmailutils/mailbox/hdrfirst.c
+++ b/libproto/imap/err.c
@@ -18,31 +18,42 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
 #include <stdlib.h>
-#include <mailutils/types.h>
-#include <mailutils/header.h>
+#include <string.h>
 #include <mailutils/errno.h>
+#include <mailutils/sys/imap.h>
 
 int
-mu_header_sget_firstof (mu_header_t hdr, char **names,
-			const char **pval, int *pidx)
+_mu_imap_seterrstr (mu_imap_t imap, const char *str, size_t len)
+{
+  if (len + 1 > imap->errsize)
+    {
+      char *p = realloc (imap->errstr, len + 1);
+      if (!p)
+	return ENOMEM;
+      imap->errsize = len + 1;
+      imap->errstr = p;
+    }
+  memcpy (imap->errstr, str, len);
+  imap->errstr[len] = 0;
+  return 0;
+}
+
+void
+_mu_imap_clrerrstr (mu_imap_t imap)
+{
+  if (imap->errstr)
+    imap->errstr[0] = 0;
+}
+    
+int
+mu_imap_strerror (mu_imap_t imap, const char **pstr)
 {
-  int status;
-  const char *s = NULL;
-  int i;
-  
-  for (i = 0; names[i]; i++)
+  if (imap->errstr)
     {
-      status = mu_header_sget_value (hdr, names[i], &s);
-      if (status == 0 && *s != 0)
-	{
-	  if (pval)
-	    *pval = s;
-	  if (pidx)
-	    *pidx = i;
-	  return 0;
-	}
+      *pstr = imap->errstr;
+      return 0;
     }
+  *pstr = "(no error)";
   return MU_ERR_NOENT;
 }
diff --git a/libproto/imap/fake-folder.c b/libproto/imap/fake-folder.c
new file mode 100644
index 0000000..fb59c49
--- /dev/null
+++ b/libproto/imap/fake-folder.c
@@ -0,0 +1,7 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/mailutils.h>
+
+mu_record_t mu_imap_record = NULL;
+mu_record_t mu_imaps_record = NULL;
diff --git a/libproto/imap/id.c b/libproto/imap/id.c
new file mode 100644
index 0000000..5513d54
--- /dev/null
+++ b/libproto/imap/id.c
@@ -0,0 +1,180 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/cstr.h>
+#include <mailutils/wordsplit.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imap.h>
+
+static int
+id_comp (const void *item, const void *value)
+{
+  const char *id = item;
+  const char *needle = value;
+  return mu_c_strcasecmp (id, needle);
+}
+
+static int
+parse_id_reply (mu_imap_t imap, mu_list_t *plist)
+{
+  mu_list_t list;
+  int rc;
+  const char *response;
+  struct mu_wordsplit ws;
+  size_t i;
+    
+  rc = mu_list_create (&list);
+  if (rc)
+    return rc;
+  mu_list_set_comparator (list, id_comp);
+  mu_list_set_destroy_item (list, mu_list_free_item);
+  
+  rc = mu_list_get (imap->untagged_resp, 0, (void*) &response);
+  if (rc == MU_ERR_NOENT)
+    {
+      *plist = list;
+      return 0;
+    }
+  else if (rc)
+    {
+      mu_list_destroy (&list);
+      return rc;
+    }
+
+  ws.ws_delim = "() \t";
+  if (mu_wordsplit (response, &ws,
+		    MU_WRDSF_NOVAR | MU_WRDSF_NOCMD |
+		    MU_WRDSF_QUOTE | MU_WRDSF_DELIM |
+		    MU_WRDSF_SQUEEZE_DELIMS |
+		    MU_WRDSF_WS))
+    {
+      int ec = errno;
+      mu_error ("mu_imap_id: cannot split line: %s",
+		mu_wordsplit_strerror (&ws));
+      mu_list_destroy (&list);
+      return ec;
+    }
+
+  for (i = 1; i < ws.ws_wordc; i += 2)
+    {
+      size_t len, l1, l2;
+      char *elt;
+      
+      if (i + 1 == ws.ws_wordc)
+	break;
+      l1 = strlen (ws.ws_wordv[i]);
+      l2 = strlen (ws.ws_wordv[i+1]);
+      len = l1 + l2 + 1;
+      elt = malloc (len + 1);
+      if (!elt)
+	break;
+
+      memcpy (elt, ws.ws_wordv[i], l1);
+      elt[l1] = 0;
+      memcpy (elt + l1 + 1, ws.ws_wordv[i+1], l2);
+      elt[len] = 0;
+      mu_list_append (list, elt);
+    }
+  mu_wordsplit_free (&ws);
+  *plist = list;
+  return 0;
+}
+
+int
+mu_imap_id (mu_imap_t imap, char **idenv, mu_list_t *plist)
+{
+  int status;
+  
+  if (imap == NULL)
+    return EINVAL;
+  if (!imap->carrier)
+    return MU_ERR_NO_TRANSPORT;
+  if (imap->state != MU_IMAP_CONNECTED)
+    return MU_ERR_SEQ;
+
+  switch (imap->state)
+    {
+    case MU_IMAP_CONNECTED:
+      status = _mu_imap_tag_next (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      status = mu_stream_printf (imap->carrier, "%s ID ",
+				 imap->tag_str);
+      MU_IMAP_CHECK_ERROR (imap, status);
+      if (!idenv)
+	status = mu_stream_printf (imap->carrier, "NIL");
+      else
+	{
+	  if (idenv[0])
+	    {
+	      int i;
+	      char *delim = "(";
+	      for (i = 0; idenv[i]; i++)
+		{
+		  status = mu_stream_printf (imap->carrier, "%s\"%s\"",
+					     delim, idenv[i]);
+		  MU_IMAP_CHECK_ERROR (imap, status);
+		  
+		  delim = " ";
+		  if (status)
+		    break;
+		}
+	      status = mu_stream_printf (imap->carrier, ")");
+	    }
+	  else
+	    status = mu_stream_printf (imap->carrier, "()");
+	}
+      MU_IMAP_CHECK_ERROR (imap, status);
+      status = mu_stream_printf (imap->carrier, "\r\n");
+      MU_IMAP_CHECK_ERROR (imap, status);
+      MU_IMAP_FCLR (imap, MU_IMAP_RESP);
+      imap->state = MU_IMAP_ID_RX;
+
+    case MU_IMAP_ID_RX:
+      status = _mu_imap_response (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      switch (imap->resp_code)
+	{
+	case MU_IMAP_OK:
+	  imap->imap_state = MU_IMAP_STATE_AUTH;
+	  if (plist)
+	    status = parse_id_reply (imap, plist);
+	  break;
+
+	case MU_IMAP_NO:
+	  status = EACCES;
+	  break;
+
+	case MU_IMAP_BAD:
+	  status = MU_ERR_BADREPLY;
+	  break;
+	}
+      imap->state = MU_IMAP_CONNECTED;
+      break;
+
+    default:
+      status = EINPROGRESS;
+    }
+  return status;
+}
+      
diff --git a/libproto/imap/login.c b/libproto/imap/login.c
new file mode 100644
index 0000000..94313e8
--- /dev/null
+++ b/libproto/imap/login.c
@@ -0,0 +1,80 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <mailutils/errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imap.h>
+
+int
+mu_imap_login (mu_imap_t imap, const char *user, const char *pass)
+{
+  int status;
+  
+  if (imap == NULL)
+    return EINVAL;
+  if (!imap->carrier)
+    return MU_ERR_NO_TRANSPORT;
+  if (imap->state != MU_IMAP_CONNECTED)
+    return MU_ERR_SEQ;
+  if (imap->imap_state != MU_IMAP_STATE_NONAUTH)
+    return MU_ERR_SEQ;
+  
+  switch (imap->state)
+    {
+    case MU_IMAP_CONNECTED:
+      if (mu_imap_trace_mask (imap, MU_IMAP_TRACE_QRY, MU_XSCRIPT_SECURE))
+	_mu_imap_xscript_level (imap, MU_XSCRIPT_SECURE);
+      status = _mu_imap_tag_next (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      status = mu_stream_printf (imap->carrier, "%s LOGIN \"%s\" \"%s\"\r\n",
+				 imap->tag_str, user, pass);
+      _mu_imap_xscript_level (imap, MU_XSCRIPT_NORMAL);
+      /* FIXME: how to obscure the passwd in the stream buffer? */
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      MU_IMAP_FCLR (imap, MU_IMAP_RESP);
+      imap->state = MU_IMAP_LOGIN_RX;
+
+    case MU_IMAP_LOGIN_RX:
+      status = _mu_imap_response (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      switch (imap->resp_code)
+	{
+	case MU_IMAP_OK:
+	  imap->imap_state = MU_IMAP_STATE_AUTH;
+	  break;
+
+	case MU_IMAP_NO:
+	  status = EACCES;
+	  break;
+
+	case MU_IMAP_BAD:
+	  status = MU_ERR_BADREPLY;
+	  break;
+	}
+      imap->state = MU_IMAP_CONNECTED;
+      break;
+
+    default:
+      status = EINPROGRESS;
+    }
+  return status;
+}
+
diff --git a/libproto/nntp/nntp_quit.c b/libproto/imap/logout.c
similarity index 51%
copy from libproto/nntp/nntp_quit.c
copy to libproto/imap/logout.c
index 5fcd091..925fd7f 100644
--- a/libproto/nntp/nntp_quit.c
+++ b/libproto/imap/logout.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2004, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -19,43 +19,43 @@
 # include <config.h>
 #endif
 
-#include <string.h>
-#include <errno.h>
-#include <mailutils/sys/nntp.h>
+#include <mailutils/errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/imap.h>
 
 int
-mu_nntp_quit (mu_nntp_t nntp)
+mu_imap_logout (mu_imap_t imap)
 {
   int status;
-
-  if (nntp == NULL)
+  
+  if (imap == NULL)
     return EINVAL;
+  if (!imap->carrier)
+    return MU_ERR_NO_TRANSPORT;
+  if (imap->state != MU_IMAP_CONNECTED)
+    return MU_ERR_SEQ;
 
-  switch (nntp->state)
+  switch (imap->state)
     {
-    case MU_NNTP_NO_STATE:
-      status = mu_nntp_writeline (nntp, "QUIT\r\n");
-      MU_NNTP_CHECK_ERROR (nntp, status);
-      mu_nntp_debug_cmd (nntp);
-      nntp->state = MU_NNTP_QUIT;
-
-    case MU_NNTP_QUIT:
-      status = mu_nntp_send (nntp);
-      MU_NNTP_CHECK_EAGAIN (nntp, status);
-      nntp->acknowledge = 0;
-      nntp->state = MU_NNTP_QUIT_ACK;
-
-    case MU_NNTP_QUIT_ACK:
-      status = mu_nntp_response (nntp, NULL, 0, NULL);
-      MU_NNTP_CHECK_EAGAIN (nntp, status);
-      mu_nntp_debug_ack (nntp);
-      MU_NNTP_CHECK_CODE (nntp, MU_NNTP_RESP_CODE_CLOSING);
-      nntp->state = MU_NNTP_NO_STATE;
+    case MU_IMAP_CONNECTED:
+      status = _mu_imap_tag_next (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      status = mu_stream_printf (imap->carrier, "%s LOGOUT\r\n",
+				 imap->tag_str); 
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      MU_IMAP_FCLR (imap, MU_IMAP_RESP);
+      imap->state = MU_IMAP_LOGOUT_RX;
+
+    case MU_IMAP_LOGOUT_RX:
+      status = _mu_imap_response (imap);
+      MU_IMAP_CHECK_EAGAIN (imap, status);
+      imap->state = MU_IMAP_NO_STATE;
+      imap->imap_state = MU_IMAP_STATE_LOGOUT;
       break;
 
     default:
       status = EINPROGRESS;
     }
-
   return status;
 }
+      
diff --git a/libproto/imap/response.c b/libproto/imap/response.c
new file mode 100644
index 0000000..dc5a7a9
--- /dev/null
+++ b/libproto/imap/response.c
@@ -0,0 +1,125 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
+#include <mailutils/stream.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/imap.h>
+
+#define IS_PREFIX(s, len, pfx)				\
+  ((len) >= sizeof (pfx) - 1 &&				\
+   memcmp ((s), (pfx), sizeof (pfx) - 1) == 0 &&	\
+   s[sizeof (pfx) - 1] == ' ')
+
+int
+_mu_imap_response (mu_imap_t imap)
+{
+  size_t n = 0;
+  int status = 0;
+
+  if (imap == NULL)
+    return EINVAL;
+
+  if (MU_IMAP_FISSET (imap, MU_IMAP_RESP))
+    return 0;
+
+  _mu_imap_clrerrstr (imap);
+  if (imap->untagged_resp)
+    mu_list_clear (imap->untagged_resp);
+  else
+    {
+      status = mu_list_create (&imap->untagged_resp);
+      MU_IMAP_CHECK_ERROR (imap, status);
+      mu_list_set_destroy_item (imap->untagged_resp, mu_list_free_item);
+    }
+
+  while (1)
+    {
+      status = mu_stream_getline (imap->carrier, &imap->rdbuf,
+				  &imap->rdsize, NULL);
+      if (status == 0)
+	{
+	  n = mu_rtrim_class (imap->rdbuf, MU_CTYPE_SPACE);
+	  if (imap->rdbuf[0] == '*' && imap->rdbuf[1] == ' ')
+	    {
+	      char *p = mu_str_skip_cset (imap->rdbuf + 2, " ");
+	      mu_list_append (imap->untagged_resp, strdup (p));
+	    }
+	  else if (n > imap->tag_len + 3 &&
+		   memcmp (imap->rdbuf, imap->tag_str, imap->tag_len) == 0
+		   && imap->rdbuf[imap->tag_len] == ' ')
+	    {
+	      char *p = mu_str_skip_cset (imap->rdbuf + imap->tag_len, " ");
+	      size_t len = strlen (p);
+
+	      if (len >= imap->tagsize)
+		{
+		  char *np = realloc (imap->tagbuf, len + 1);
+		  if (!np)
+		    {
+		      imap->state = MU_IMAP_ERROR;
+		      return ENOMEM;
+		    }
+		  imap->tagsize = len + 1;
+		  imap->tagbuf = np;
+		}
+	      strcpy (imap->tagbuf, p);
+	      if (IS_PREFIX (p, len, "OK"))
+		{
+		  imap->resp_code = MU_IMAP_OK;
+		  p = mu_str_skip_cset (p + 2, " ");
+		  _mu_imap_seterrstr (imap, p, strlen (p));
+		}
+	      else if (IS_PREFIX (p, len, "NO"))
+		{
+		  imap->resp_code = MU_IMAP_NO;
+		  p = mu_str_skip_cset (p + 2, " ");
+		  _mu_imap_seterrstr (imap, p, strlen (p));
+		}
+	      else if (IS_PREFIX (p, len, "BAD"))
+		{
+		  imap->resp_code = MU_IMAP_BAD;
+		  p = mu_str_skip_cset (p + 2, " ");
+		  _mu_imap_seterrstr (imap, p, strlen (p));
+		}
+	      else
+		status = MU_ERR_BADREPLY;
+	      MU_IMAP_FSET (imap, MU_IMAP_RESP);
+	      break;
+	    }
+	  else
+	    {
+	      imap->state = MU_IMAP_ERROR;
+	      return MU_ERR_BADREPLY;
+	    }
+	}
+      else
+	{
+	  imap->state = MU_IMAP_ERROR;
+	  return status;
+	}
+    }
+  return status;
+}
+	  
diff --git a/libproto/nntp/nntp_timeout.c b/libproto/imap/state.c
similarity index 60%
copy from libproto/nntp/nntp_timeout.c
copy to libproto/imap/state.c
index 8b35ed0..4ce3230 100644
--- a/libproto/nntp/nntp_timeout.c
+++ b/libproto/imap/state.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2004, 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -18,31 +18,33 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
-#include <stdlib.h>
 #include <errno.h>
-#include <mailutils/sys/nntp.h>
+#include <mailutils/nls.h>
+#include <mailutils/sys/imap.h>
+
+const char *_mu_imap_state_name[] = {
+  N_("initial"),
+  N_("non-authenticated"),
+  N_("authenticated"),
+  N_("selected"),
+  N_("logout")
+};
+int _mu_imap_state_count = MU_ARRAY_SIZE (_mu_imap_state_name);
 
 int
-mu_nntp_set_timeout (mu_nntp_t nntp, int timeout)
+mu_imap_state (mu_imap_t imap, int *pstate)
 {
-  /* Sanity checks.  */
-  if (nntp == NULL)
+  if (imap == NULL || pstate == NULL)
     return EINVAL;
-
-  nntp->timeout = timeout;
+  *pstate = imap->imap_state;
   return 0;
 }
 
 int
-mu_nntp_get_timeout (mu_nntp_t nntp, int *ptimeout)
+mu_imap_state_str (int state, const char **pstr)
 {
-  /* Sanity checks.  */
-  if (nntp == NULL)
+  if (state < 0 || state >= _mu_imap_state_count)
     return EINVAL;
-  if (ptimeout == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-
-  *ptimeout = nntp->timeout;
+  *pstr = gettext (_mu_imap_state_name[state]);
   return 0;
 }
diff --git a/libproto/imap/tag.c b/libproto/imap/tag.c
new file mode 100644
index 0000000..3317219
--- /dev/null
+++ b/libproto/imap/tag.c
@@ -0,0 +1,103 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <errno.h>
+#include <mailutils/sys/imap.h>
+
+static int
+_mu_imap_tag_incr (mu_imap_t imap)
+{
+  int i = 0;
+  
+  while (1)
+    {
+      if (++imap->tag_buf[i] <= 9)
+	break;
+      imap->tag_buf[i] = 0;
+      if (++i == imap->tag_len)
+	{
+	  char *sp;
+	  int *np = realloc (imap->tag_buf, imap->tag_len + 1);
+	  if (!np)
+	    return ENOMEM;
+	  imap->tag_buf = np;
+	  sp = realloc (imap->tag_str, imap->tag_len + 2);
+	  if (!sp)
+	    return ENOMEM;
+	  imap->tag_str = sp;
+	  imap->tag_len++;
+	}
+    }
+  return 0;
+}
+
+static void
+_mu_imap_tag_print (mu_imap_t imap)
+{
+  int i;
+
+  for (i = 0; i < imap->tag_len; i++)
+    imap->tag_str[imap->tag_len-i-1] = imap->tag_buf[i] + '0';
+  imap->tag_str[i] = 0;
+}
+
+int
+_mu_imap_tag_clr (mu_imap_t imap)
+{
+  int i;
+  
+  if (imap->tag_len == 0)
+    {
+      imap->tag_len = 2;
+      imap->tag_buf = calloc (imap->tag_len, sizeof (imap->tag_buf[0]));
+      if (!imap->tag_buf)
+	return ENOMEM;
+      imap->tag_str = calloc (imap->tag_len + 1, sizeof (imap->tag_str[0]));
+      if (!imap->tag_str)
+	{
+	  free (imap->tag_buf);
+	  return ENOMEM;
+	}
+    }
+  for (i = 0; i < imap->tag_len; i++)
+    imap->tag_buf[i] = 0;
+  _mu_imap_tag_print (imap);
+  return 0;
+}
+
+int
+_mu_imap_tag_next (mu_imap_t imap)
+{
+  int status;
+  status = _mu_imap_tag_incr (imap);
+  if (status == 0)
+    _mu_imap_tag_print (imap);
+  return status;
+}
+
+int
+mu_imap_tag (mu_imap_t imap, const char **ptag)
+{
+  if (!imap)
+    return EINVAL;
+  *ptag = imap->tag_str;
+  return 0;
+}
diff --git a/libproto/pop/pop3_trace.c b/libproto/imap/trace.c
similarity index 61%
copy from libproto/pop/pop3_trace.c
copy to libproto/imap/trace.c
index 8ed7eab..3fff598 100644
--- a/libproto/pop/pop3_trace.c
+++ b/libproto/imap/trace.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2007, 2009, 2010 Free Software
-   Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -24,24 +23,25 @@
 #include <errno.h>
 #include <stdio.h>
 #include <mailutils/error.h>
+#include <mailutils/errno.h>
 #include <mailutils/nls.h>
 #include <mailutils/stream.h>
-#include <mailutils/sys/pop3.h>
+#include <mailutils/sys/imap.h>
 
-static const char *pop3_prefix[] = {
+static const char *imap_prefix[] = {
   "S: ", "C: "
 };
 
 int
-_mu_pop3_trace_enable (mu_pop3_t pop3)
+_mu_imap_trace_enable (mu_imap_t imap)
 {
   int rc = 0;
   mu_debug_t debug;
   mu_stream_t dstr, xstr;
 
-  if (!pop3->carrier)
+  if (!imap->carrier)
     {
-      MU_POP3_FSET (pop3, MU_POP3_TRACE);
+      MU_IMAP_FSET (imap, MU_IMAP_TRACE);
       return 0;
     }
   
@@ -53,16 +53,16 @@ _mu_pop3_trace_enable (mu_pop3_t pop3)
 	      mu_strerror (rc));
   else
     {
-      rc = mu_xscript_stream_create (&xstr, pop3->carrier, dstr,
-				     pop3_prefix);
+      rc = mu_xscript_stream_create (&xstr, imap->carrier, dstr,
+				     imap_prefix);
       if (rc)
 	mu_error (_("cannot create transcript stream: %s"),
 		  mu_strerror (rc));
       else
 	{
-	  mu_stream_unref (pop3->carrier);
-	  pop3->carrier = xstr;
-	  MU_POP3_FSET (pop3, MU_POP3_TRACE);
+	  mu_stream_unref (imap->carrier);
+	  imap->carrier = xstr;
+	  MU_IMAP_FSET (imap, MU_IMAP_TRACE);
 	}
     }
 
@@ -70,9 +70,9 @@ _mu_pop3_trace_enable (mu_pop3_t pop3)
 }
 
 int
-_mu_pop3_trace_disable (mu_pop3_t pop3)
+_mu_imap_trace_disable (mu_imap_t imap)
 {
-  mu_stream_t xstr = pop3->carrier;
+  mu_stream_t xstr = imap->carrier;
   mu_stream_t stream[2];
   int rc;
 
@@ -83,30 +83,30 @@ _mu_pop3_trace_disable (mu_pop3_t pop3)
   if (rc)
     return rc;
 
-  pop3->carrier = stream[0];
+  imap->carrier = stream[0];
   mu_stream_destroy (&xstr);
-  MU_POP3_FCLR (pop3, MU_POP3_TRACE);
+  MU_IMAP_FCLR (imap, MU_IMAP_TRACE);
   return 0;
 }
 
 int
-mu_pop3_trace (mu_pop3_t pop3, int op)
+mu_imap_trace (mu_imap_t imap, int op)
 {
-  int trace_on = MU_POP3_FISSET (pop3, MU_POP3_TRACE);
+  int trace_on = MU_IMAP_FISSET (imap, MU_IMAP_TRACE);
   
   switch (op)
     {
-    case MU_POP3_TRACE_SET:
+    case MU_IMAP_TRACE_SET:
       if (trace_on)
 	return MU_ERR_EXISTS;
-      return _mu_pop3_trace_enable (pop3);
+      return _mu_imap_trace_enable (imap);
       
-    case MU_POP3_TRACE_CLR:
+    case MU_IMAP_TRACE_CLR:
       if (!trace_on)
 	return MU_ERR_NOENT;
-      return _mu_pop3_trace_disable (pop3);
+      return _mu_imap_trace_disable (imap);
 
-    case MU_POP3_TRACE_QRY:
+    case MU_IMAP_TRACE_QRY:
       if (!trace_on)
 	return MU_ERR_NOENT;
       return 0;
@@ -115,20 +115,20 @@ mu_pop3_trace (mu_pop3_t pop3, int op)
 }
 
 int
-mu_pop3_trace_mask (mu_pop3_t pop3, int op, int lev)
+mu_imap_trace_mask (mu_imap_t imap, int op, int lev)
 {
   switch (op)
     {
-    case MU_POP3_TRACE_SET:
-      pop3->flags |= MU_POP3_XSCRIPT_MASK(lev);
+    case MU_IMAP_TRACE_SET:
+      imap->flags |= MU_IMAP_XSCRIPT_MASK(lev);
       break;
       
-    case MU_POP3_TRACE_CLR:
-      pop3->flags &= ~MU_POP3_XSCRIPT_MASK(lev);
+    case MU_IMAP_TRACE_CLR:
+      imap->flags &= ~MU_IMAP_XSCRIPT_MASK(lev);
       break;
       
-    case MU_POP3_TRACE_QRY:
-      if (pop3->flags & MU_POP3_XSCRIPT_MASK(lev))
+    case MU_IMAP_TRACE_QRY:
+      if (imap->flags & MU_IMAP_XSCRIPT_MASK(lev))
 	break;
       return MU_ERR_NOENT;
       
@@ -139,11 +139,9 @@ mu_pop3_trace_mask (mu_pop3_t pop3, int op, int lev)
 }
 
 int
-_mu_pop3_xscript_level (mu_pop3_t pop3, int xlev)
+_mu_imap_xscript_level (mu_imap_t imap, int xlev)
 {
-  if (mu_stream_ioctl (pop3->carrier, MU_IOCTL_LEVEL, &xlev) == 0)
+  if (mu_stream_ioctl (imap->carrier, MU_IOCTL_LEVEL, &xlev) == 0)
     return xlev;
   return MU_XSCRIPT_NORMAL;
 }
-
-  
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index 0411c23..5c0dd1b 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -349,6 +349,7 @@ _msg_body_setup (mu_message_t msg, mbox_message_t mum)
       mu_body_set_stream (body, stream, msg);
       mu_body_set_size (body, mbox_body_size, msg);
       mu_body_set_lines (body, mbox_body_lines, msg);
+      mu_body_clear_modified (body);
       mu_message_set_body (msg, body, mum);
     }
   return status;
@@ -571,6 +572,8 @@ new_message (mu_mailbox_t mailbox, mbox_message_t mum, mu_message_t *pmsg)
   mum->message = msg;
   mu_message_set_mailbox (msg, mailbox, mum);
 
+  mu_message_clear_modified (msg);
+
   *pmsg = msg;
   
   return 0;
@@ -1149,37 +1152,18 @@ mbox_append_message (mu_mailbox_t mailbox, mu_message_t msg)
 
 
 static void
-mbox_reset (mu_mailbox_t mailbox, size_t dirty, int remove_deleted)
+mbox_reset (mu_mailbox_t mailbox)
 {
   mbox_data_t mud = mailbox->data;
   size_t i;
-  size_t dlast;
 
   mu_monitor_wrlock (mailbox->monitor);
-  for (i = dirty, dlast = mud->messages_count - 1; i <= dlast; i++)
+  for (i = 0; i < mud->messages_count; i++)
     {
       /* Clear all the references */
       mbox_message_t mum = mud->umessages[i];
-      if (remove_deleted && ATTRIBUTE_IS_DELETED (mum->attr_flags))
-	{
-	  if ((i + 1) <= dlast)
-	    {
-	      /* Move all the pointers up.  So the message pointer
-		 part of mum will be at the right position.  */
-	      memmove (mud->umessages + i, mud->umessages + i + 1,
-		       (dlast - i) * sizeof (mum));
-	      memset (mum, 0, sizeof (*mum));
-	      /* We are not free()ing the useless mum, but instead
-		 we put it back in the pool, to be reused.  */
-	      mud->umessages[dlast] = mum;
-	      dlast--;
-	      /* Set mum to the new value after the memmove so it
-		 gets cleared to.  */
-	      mum = mud->umessages[i];
-	    }
-	  else
-	    memset (mum, 0, sizeof (*mum));
-	}
+      mu_message_destroy (&mum->message, mum);
+      memset (mum, 0, sizeof (*mum));
       mum->envel_from = mum->envel_from_end = 0;
       mum->body = mum->body_end = 0;
       mum->header_lines = mum->body_lines = 0;
@@ -1187,7 +1171,7 @@ mbox_reset (mu_mailbox_t mailbox, size_t dirty, int remove_deleted)
   mu_monitor_unlock (mailbox->monitor);
   /* This resets the messages_count, the last argument 0 means
      not to send event notification.  */
-  mbox_scan0 (mailbox, dirty, NULL, 0);
+  mbox_scan0 (mailbox, 1, NULL, 0);
 }
 
 static int
@@ -1434,7 +1418,7 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted)
       mu_stream_destroy (&tempstr);
       
       if (status == 0)
-	mbox_reset (mailbox, dirty, remove_deleted);
+	mbox_reset (mailbox);
     }
   if (mailbox->locker)
     mu_locker_unlock (mailbox->locker);
diff --git a/libproto/mbox/mboxscan.c b/libproto/mbox/mboxscan.c
index 3a35e6f..90f4a6b 100644
--- a/libproto/mbox/mboxscan.c
+++ b/libproto/mbox/mboxscan.c
@@ -34,6 +34,8 @@
 
 #include <stdlib.h>
 #include <mbox0.h>
+#include <mailutils/cctype.h>
+#include <mailutils/cstr.h>
 
 /* Parsing.
    The approach is to detect the "From " as start of a new message, give the
@@ -279,6 +281,26 @@ do                                                                           \
  && (buf[5] == 'S' || buf[5] == 's')                                          \
  && (buf[6] == ':' || buf[6] == ' ' || buf[6] == '\t'))
 
+#define IS_X_UID(buf) (						\
+ (buf[0] == 'X' || buf[0] == 'x')		                \
+  && buf[1] == '-'						\
+  && (buf[2] == 'U' || buf[2] == 'u')				\
+  && (buf[3] == 'I' || buf[3] == 'i')				\
+  && (buf[4] == 'D' || buf[4] == 'd')				\
+  && (buf[5] == ':' || buf[5] == ' ' || buf[5] == '\t'))
+#define IS_X_IMAPBASE(buf) (					\
+ (buf[0] == 'X' || buf[0] == 'x')		                \
+  && buf[1] == '-'						\
+  && (buf[2] == 'I' || buf[2] == 'i')				\
+  && (buf[3] == 'M' || buf[3] == 'm')				\
+  && (buf[4] == 'A' || buf[4] == 'a')				\
+  && (buf[5] == 'P' || buf[5] == 'p')				\
+  && (buf[6] == 'B' || buf[6] == 'b')				\
+  && (buf[7] == 'A' || buf[7] == 'a')				\
+  && (buf[8] == 'S' || buf[8] == 's')				\
+  && (buf[9] == 'E' || buf[9] == 'e')				\
+  && (buf[10] == ':' || buf[10] == ' ' || buf[10] == '\t'))
+
 #define MBOX_SCAN_NOTIFY 0x1
 #define MBOX_SCAN_ONEMSG 0x2
 
@@ -298,7 +320,7 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum,
   int newline;
   size_t n = 0;
   mu_stream_t stream;
-  size_t min_uid = 0;
+  size_t min_uid = 1;
   int zn, isfrom = 0;
   char *temp;
   
@@ -345,9 +367,9 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum,
 		  mum->body_end = total - n - newline;
 		  mum->body_lines = --lines - newline;
 
-		  if (mum->uid <= min_uid)
+		  if (mum->uid < min_uid)
 		    {
-		      mum->uid = ++min_uid;
+		      mum->uid = min_uid++;
 		      /* Note that modification for when expunging.  */
 		      mum->attr_flags |= MU_ATTRIBUTE_MODIFIED;
 		    }
@@ -370,13 +392,32 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum,
 	      mum->attr_flags = 0;
 	      lines = 0;
 	    }
-	  else if (ISSTATUS(buf))
+	  else if (ISSTATUS (buf))
 	    {
 	      ATTRIBUTE_SET(buf, mum, 'r', 'R', MU_ATTRIBUTE_READ);
 	      ATTRIBUTE_SET(buf, mum, 'o', 'O', MU_ATTRIBUTE_SEEN);
 	      ATTRIBUTE_SET(buf, mum, 'a', 'A', MU_ATTRIBUTE_ANSWERED);
 	      ATTRIBUTE_SET(buf, mum, 'd', 'D', MU_ATTRIBUTE_DELETED);
 	    }
+	  else if (IS_X_UID (buf))
+	    {
+	      char *p;
+	      unsigned long n = strtoul (buf + 6, &p, 10);
+	      if (*p == 0 || mu_isspace (*p))
+		mum->uid = min_uid = n;
+	    }
+	  else if (mud->messages_count == 1 && IS_X_IMAPBASE (buf))
+	    {
+	      char *p;
+	      unsigned long n = strtoul (buf + 11, &p, 10);
+	      if (mu_isspace (*p))
+		mud->uidvalidity = n;
+	      n = strtoul (mu_str_skip_cset (p, " \t"), &p, 10);
+	      if (*p == 0 || mu_isspace (*p))
+		mud->uidnext = n;
+	      else
+		mud->uidvalidity = 0;
+	    }
 	}
 
       /* Body.  */
@@ -410,9 +451,9 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum,
       mum->body_end = total - newline;
       mum->body_lines = lines - newline;
 
-      if (mum->uid <= min_uid)
+      if (mum->uid < min_uid)
 	{
-	  mum->uid = ++min_uid;
+	  mum->uid = min_uid++;
 	  /* Note that modification for when expunging.  */
 	  mum->attr_flags |= MU_ATTRIBUTE_MODIFIED;
 	}
@@ -498,7 +539,7 @@ mbox_scan0 (mu_mailbox_t mailbox, size_t msgno, size_t *pcount, int do_notif)
 	}
     }
       
-  if (mud->messages_count > 0 && min_uid >= mud->uidnext)
+  if (mud->messages_count > 0 && min_uid > mud->uidnext)
     {
       mum = mud->umessages[0];
       mud->uidnext = min_uid + 1;
diff --git a/libproto/pop/Makefile.am b/libproto/pop/Makefile.am
index 749e515..258f8b7 100644
--- a/libproto/pop/Makefile.am
+++ b/libproto/pop/Makefile.am
@@ -13,7 +13,7 @@
 ## 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/>. 
+## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@
 
diff --git a/libproto/pop/pop3_carrier.c b/libproto/pop/pop3_carrier.c
index 265669d..b793be4 100644
--- a/libproto/pop/pop3_carrier.c
+++ b/libproto/pop/pop3_carrier.c
@@ -55,6 +55,7 @@ mu_pop3_get_carrier (mu_pop3_t pop3, mu_stream_t *pcarrier)
   if (pcarrier == NULL)
     return MU_ERR_OUT_PTR_NULL;
 
+  mu_stream_ref (pop3->carrier);
   *pcarrier = pop3->carrier;
   return 0;
 }
diff --git a/libproto/pop/pop3_response.c b/libproto/pop/pop3_response.c
index 63ecc7a..d56cad1 100644
--- a/libproto/pop/pop3_response.c
+++ b/libproto/pop/pop3_response.c
@@ -67,6 +67,13 @@ mu_pop3_response (mu_pop3_t pop3, size_t *pnread)
   else if (pop3->ackbuf)
     n = strlen (pop3->ackbuf);
 
+  if (n < 3)
+    status = MU_ERR_BADREPLY;
+  else if (strncmp (pop3->ackbuf, "-ERR", 4) == 0)
+    status = MU_ERR_REPLY;
+  else if (strncmp (pop3->ackbuf, "+OK", 3))
+    status = MU_ERR_BADREPLY;
+  
   if (pnread)
     *pnread = n;
   return status;
diff --git a/mu/Makefile.am b/mu/Makefile.am
index 52ab78c..dfd2c44 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -18,16 +18,24 @@
 bin_PROGRAMS = mu
 dist_bin_SCRIPTS = mailutils-config
 
+IDLE_MODULES=
+
 if MU_COND_SUPPORT_POP
  POP_C=pop.c
+else
+ IDLE_MODULES+=pop.c
 endif
 
-EXTRA_DIST=pop.c mu-setup.h mu-setup.c mu-setup.awk
-BUILT_SOURCES=mu-setup.h mu-setup.c
+if MU_COND_SUPPORT_IMAP
+ IMAP_C=imap.c
+else
+ IDLE_MODULES+=imap.c
+endif
 
 MODULES = \
  acl.c\
  cflags.c\
+ $(IMAP_C)\
  filter.c\
  flt2047.c\
  help.c\
@@ -39,9 +47,11 @@ MODULES = \
 
 mu_SOURCES = \
  dispatch.c\
+ getarg.c\
  mu.h\
  mu.c\
  shell.c\
+ verbose.c\
  $(MODULES)
 
 mu_LDADD = \
@@ -68,8 +78,10 @@ AM_CPPFLAGS = \
   -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
   -DI18NLIBS="\"$(LIBINTL)\""
 
-mu-setup.h: Makefile.am $(MODULES)
-	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=h $(MODULES) > mu-setup.h
+mu-setup.h: Makefile.am $(MODULES) $(IDLE_MODULES) 
+	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=h \
+           $(MODULES) $(IDLE_MODULES) > mu-setup.h
 
 mu-setup.c: Makefile.am $(MODULES)
-	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=c $(MODULES) > mu-setup.c
+	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=c \
+           $(MODULES) $(IDLE_MODULES) > mu-setup.c
diff --git a/mu/cflags.c b/mu/getarg.c
similarity index 50%
copy from mu/cflags.c
copy to mu/getarg.c
index ea510da..f86cc96 100644
--- a/mu/cflags.c
+++ b/mu/getarg.c
@@ -18,36 +18,56 @@
 # include <config.h>
 #endif
 #include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <netdb.h>
 #include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <argp.h>
-
-static char cflags_doc[] = N_("mu cflags - show compiler options");
-char cflags_docstring[] = N_("show compiler options");
-
-static struct argp cflags_argp = {
-  NULL,
-  NULL,
-  NULL,
-  cflags_doc,
-  NULL,
-  NULL,
-  NULL
-};
+#include "mu.h"
 
 int
-mutool_cflags (int argc, char **argv)
+get_bool (const char *str, int *pb)
 {
-  if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL))
+  if (mu_c_strcasecmp (str, "yes") == 0
+      || mu_c_strcasecmp (str, "on") == 0
+      || mu_c_strcasecmp (str, "true") == 0)
+    *pb = 1;
+  else if (mu_c_strcasecmp (str, "no") == 0
+      || mu_c_strcasecmp (str, "off") == 0
+      || mu_c_strcasecmp (str, "false") == 0)
+    *pb = 0;
+  else
     return 1;
-  printf ("%s\n", COMPILE_FLAGS);
+
   return 0;
 }
 
-/*
-  MU Setup: cflags
-  mu-handler: mutool_cflags
-  mu-docstring: cflags_docstring
-  End MU Setup:
-*/
+int
+get_port (const char *port_str, int *pn)
+{
+  short port_num;
+  long num;
+  char *p;
+  
+  num = port_num = strtol (port_str, &p, 0);
+  if (*p == 0)
+    {
+      if (num != port_num)
+	{
+	  mu_error ("bad port number: %s", port_str);
+	  return 1;
+	}
+    }
+  else
+    {
+      struct servent *sp = getservbyname (port_str, "tcp");
+      if (!sp)
+	{
+	  mu_error ("unknown port name");
+	  return 1;
+	}
+      port_num = ntohs (sp->s_port);
+    }
+  *pn = port_num;
+  return 0;
+}
 
diff --git a/mu/imap.c b/mu/imap.c
new file mode 100644
index 0000000..764547e
--- /dev/null
+++ b/mu/imap.c
@@ -0,0 +1,519 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <mailutils/mailutils.h>
+#include <mailutils/imap.h>
+#include "mu.h"
+#include "argp.h"
+#include "xalloc.h"
+
+static char imap_doc[] = N_("mu imap - IMAP4 client shell.");
+char imap_docstring[] = N_("IMAP4 client shell");
+static char imap_args_doc[] = "";
+
+static struct argp_option imap_options[] = {
+  { NULL }
+};
+
+static error_t
+imap_parse_opt (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+    {
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+static struct argp imap_argp = {
+  imap_options,
+  imap_parse_opt,
+  imap_args_doc,
+  imap_doc,
+  NULL,
+  NULL,
+  NULL
+};
+
+
+static mu_imap_t imap;
+
+static enum mu_imap_state
+current_imap_state ()
+{
+  int state;
+  if (imap == NULL)
+    state = MU_IMAP_STATE_INIT;
+  else
+    {
+      mu_imap_state (imap, &state);
+      if (state == MU_IMAP_STATE_LOGOUT)
+	state = MU_IMAP_STATE_INIT;
+    }
+  return state;
+}
+
+
+static void
+imap_set_verbose ()
+{
+  if (imap)
+    {
+      if (QRY_VERBOSE ())
+	mu_imap_trace (imap, MU_IMAP_TRACE_SET);
+      else
+	mu_imap_trace (imap, MU_IMAP_TRACE_CLR);
+    }
+}
+
+void
+imap_set_verbose_mask ()
+{
+  if (imap)
+    {
+      mu_imap_trace_mask (imap, QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE)
+			          ? MU_IMAP_TRACE_SET : MU_IMAP_TRACE_CLR,
+			      MU_XSCRIPT_SECURE);
+      mu_imap_trace_mask (imap, QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD)
+			          ? MU_IMAP_TRACE_SET : MU_IMAP_TRACE_CLR,
+			      MU_XSCRIPT_PAYLOAD);
+    }
+}
+
+static int
+com_verbose (int argc, char **argv)
+{
+  return shell_verbose (argc, argv,
+			imap_set_verbose, imap_set_verbose_mask);
+  
+}
+
+static int connect_argc;
+static char **connect_argv;
+#define host connect_argv[0]
+static int port = MU_IMAP_DEFAULT_PORT;
+
+static char *username;
+
+static void
+imap_prompt_env ()
+{
+  enum mu_imap_state state = current_imap_state ();
+  if (!mutool_prompt_env)
+    mutool_prompt_env = xcalloc (2*7 + 1, sizeof(mutool_prompt_env[0]));
+
+  mutool_prompt_env[0] = "user";
+  mutool_prompt_env[1] = (state >= MU_IMAP_STATE_AUTH && username) ?
+                           username : "[nouser]";
+
+  mutool_prompt_env[2] = "host"; 
+  mutool_prompt_env[3] = connect_argv ? host : "[nohost]";
+
+  mutool_prompt_env[4] = "program-name";
+  mutool_prompt_env[5] = (char*) mu_program_name;
+
+  mutool_prompt_env[6] = "canonical-program-name";
+  mutool_prompt_env[7] = "mu";
+
+  mutool_prompt_env[8] = "package";
+  mutool_prompt_env[9] = PACKAGE;
+
+  mutool_prompt_env[10] = "version";
+  mutool_prompt_env[11] = PACKAGE_VERSION;
+
+  mutool_prompt_env[12] = "status";
+  if (mu_imap_state_str (state, (const char **) &mutool_prompt_env[13]))
+    mutool_prompt_env[12] = NULL;
+
+  mutool_prompt_env[14] = NULL;
+}
+
+
+static int
+com_disconnect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
+{
+  if (imap)
+    {
+      mu_imap_disconnect (imap);
+      mu_imap_destroy (&imap);
+      
+      mu_argcv_free (connect_argc, connect_argv);
+      connect_argc = 0;
+      connect_argv = NULL;
+      imap_prompt_env ();
+    }
+  return 0;
+}
+
+static int
+com_connect (int argc, char **argv)
+{
+  int status;
+  int n = 0;
+  int tls = 0;
+  int i = 1;
+  enum mu_imap_state state;
+  
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], "-tls") == 0)
+	{
+	  if (WITH_TLS)
+	    tls = 1;
+	  else
+	    {
+	      mu_error ("TLS not supported");
+	      return 0;
+	    }
+	}
+      else
+	break;
+    }
+
+  argc -= i;
+  argv += i;
+  
+  if (argc >= 2)
+    {
+      if (get_port (argv[1], &n))
+	return 0;
+    }
+  else if (tls)
+    n = MU_IMAP_DEFAULT_SSL_PORT;
+  else
+    n = MU_IMAP_DEFAULT_PORT;
+
+  state = current_imap_state ();
+  
+  if (state != MU_IMAP_STATE_INIT)
+    com_disconnect (0, NULL);
+  
+  status = mu_imap_create (&imap);
+  if (status == 0)
+    {
+      mu_stream_t tcp;
+
+      if (QRY_VERBOSE ())
+	{
+	  imap_set_verbose ();
+	  imap_set_verbose_mask ();
+	}
+      status = mu_tcp_stream_create (&tcp, argv[0], n, MU_STREAM_READ);
+      if (status == 0)
+	{
+#ifdef WITH_TLS
+	  if (tls)
+	    {
+	      mu_stream_t tlsstream;
+	      
+	      status = mu_tls_client_stream_create (&tlsstream, tcp, tcp, 0);
+	      mu_stream_unref (tcp);
+	      if (status)
+		{
+		  mu_error ("cannot create TLS stream: %s",
+			    mu_strerror (status));
+		  return 0;
+		}
+	      tcp = tlsstream;
+	    }
+#endif
+	  mu_imap_set_carrier (imap, tcp);
+	  status = mu_imap_connect (imap);
+	  if (status)
+	    {
+	      const char *err;
+
+	      mu_error ("Failed to connect: %s", mu_strerror (status));
+	      if (mu_imap_strerror (imap, &err))
+		mu_error ("server response: %s", err);
+	      mu_imap_destroy (&imap);
+	    }
+	}
+      else
+	mu_imap_destroy (&imap);
+    }
+  else
+    mu_error ("Failed to create imap: %s", mu_strerror (status));
+  
+  if (!status)
+    {
+      connect_argc = argc;
+      connect_argv = xcalloc (argc, sizeof (*connect_argv));
+      for (i = 0; i < argc; i++)
+	connect_argv[i] = xstrdup (argv[i]);
+      connect_argv[i] = NULL;
+      port = n;
+    
+      imap_prompt_env ();
+    }
+  
+  return status;
+}
+
+static int
+com_logout (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
+{
+  int status = 0;
+  if (imap)
+    {
+      if (mu_imap_logout (imap) == 0)
+	{
+	  status = com_disconnect (0, NULL);
+	}
+      else
+	{
+	  mu_stream_printf (mustrout, "Try 'exit' to leave %s\n",
+			    mu_program_name);
+	}
+    }
+  else
+    mu_stream_printf (mustrout, "Try 'exit' to leave %s\n", mu_program_name);
+  return status;
+}
+
+static int
+com_capability (int argc, char **argv)
+{
+  mu_iterator_t iterator = NULL;
+  int status = 0;
+  int reread = 0;
+  int i = 1;
+  
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], "-reread") == 0)
+	reread = 1;
+      else
+	break;
+    }
+
+  if (i < argc)
+    {
+      if (reread)
+	{
+	  status = mu_imap_capability (imap, 1, NULL);
+	  if (status)
+	    return status;
+	}
+      for (; i < argc; i++)
+	{
+	  const char *elt;
+	  int rc = mu_imap_capability_test (imap, argv[i], &elt);
+	  switch (rc)
+	    {
+	    case 0:
+	      if (*elt)
+		mu_stream_printf (mustrout, "%s: %s\n", argv[i], elt);
+	      else
+		mu_stream_printf (mustrout, "%s is set\n", argv[i]);
+	      break;
+
+	    case MU_ERR_NOENT:
+	      mu_stream_printf (mustrout, "%s is not set\n", argv[i]);
+	      break;
+
+	    default:
+	      return rc;
+	    }
+	}
+    }
+  else
+    {
+      status = mu_imap_capability (imap, reread, &iterator);
+
+      if (status == 0)
+	{
+	  for (mu_iterator_first (iterator);
+	       !mu_iterator_is_done (iterator); mu_iterator_next (iterator))
+	    {
+	      char *capa = NULL;
+	      mu_iterator_current (iterator, (void **) &capa);
+	      mu_stream_printf (mustrout, "CAPA: %s\n", capa ? capa : "");
+	    }
+	  mu_iterator_destroy (&iterator);
+	}
+    }
+  return status;
+}
+
+static int
+com_login (int argc, char **argv)
+{
+  int status;
+  char *pwd, *passbuf = NULL;
+
+  if (argc == 2)
+    {
+      if (!mutool_shell_interactive)
+	{
+	  mu_error (_("login: password required"));
+	  return 1;
+	}
+      status = mu_getpass (mustrin, mustrout, "Password:", &passbuf);
+      if (status)
+	return status;
+      pwd = passbuf;
+    }
+  else
+    pwd = argv[2];
+
+  status = mu_imap_login (imap, argv[1], pwd);
+  memset (pwd, 0, strlen (pwd));
+  free (passbuf);
+  if (status == 0)
+    imap_prompt_env ();
+  else
+    {
+      const char *str;
+      
+      mu_error ("authentication failed: %s", mu_strerror (status));
+      if (mu_imap_strerror (imap, &str) == 0)
+	mu_error ("server reply: %s", str);
+    }
+  return 0;
+}
+
+
+static int
+_print_id (void *item, void *data)
+{
+  const char *id = item;
+  mu_stream_printf (mustrout, "ID: %s %s\n", id, id + strlen (id) + 1);
+  return 0;
+}
+
+static int
+com_id (int argc, char **argv)
+{
+  mu_list_t list;
+  char *test = NULL;
+  int status;
+  
+  argv++;
+  if (argv[0] && strcmp (argv[0], "-test") == 0)
+    {
+      argv++;
+      if (argv[0] == NULL)
+	{
+	  mu_error ("id -test requires an argument");
+	  return 0;
+	}
+      test = argv[0];
+      argv++;
+    }
+  
+  status = mu_imap_id (imap, argv + 1, &list);
+  if (status == 0)
+    {
+      if (test)
+	{
+	  const char *res;
+	  int rc = mu_list_locate (list, test, (void*)&res);
+
+	  switch (rc)
+	    {
+	    case 0:
+	      mu_stream_printf (mustrout, "%s: %s\n", test,
+				res + strlen (res) + 1);
+	      break;
+	      
+	    case MU_ERR_NOENT:
+	      mu_stream_printf (mustrout, "%s is not set\n", test);
+	      break;
+
+	    default:
+	      return rc;
+	    }
+	}
+      else
+	mu_list_do (list, _print_id, NULL);
+      mu_list_destroy (&list);
+    }
+  return status;
+}
+
+
+struct mutool_command imap_comtab[] = {
+  { "capability", 1, -1, com_capability,
+    /* TRANSLATORS: -reread is a keyword; do not translate. */
+    N_("[-reread] [NAME...]"),
+    N_("list server capabilities") },
+  { "verbose",    1, 4, com_verbose,
+    "[on|off|mask|unmask] [secure [payload]]",
+    N_("control the protocol tracing") },
+  { "connect",    1, 4, com_connect,
+    /* TRANSLATORS: --tls is a keyword. */
+    N_("[-tls] HOSTNAME [PORT]"),
+    N_("open connection") },
+  { "disconnect", 1, 1,
+    com_disconnect,
+    NULL,
+    N_("close connection") },
+  { "login",        2, 3, com_login,
+    N_("USER [PASS]"),
+    N_("login to the server") },
+  { "logout",       1, 1, com_logout,
+    NULL,
+    N_("quit imap session") },
+  { "id",           1, -1, com_id,
+    N_("[-test KW] [ARG [ARG...]]"),
+    N_("send ID command") },
+  { "quit",         1, 1, com_logout,
+    NULL,
+    N_("same as `logout'") },
+  { NULL }
+};
+
+int
+mutool_imap (int argc, char **argv)
+{
+  int index;
+
+  if (argp_parse (&imap_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
+    return 1;
+
+  argc -= index;
+  argv += index;
+
+  if (argc)
+    {
+      mu_error (_("too many arguments"));
+      return 1;
+    }
+
+  /* Command line prompt */
+  mutool_shell_prompt = xstrdup ("imap> ");
+  imap_prompt_env ();
+  mutool_shell ("imap", imap_comtab);
+  return 0;
+}
+
+/*
+  MU Setup: imap
+  mu-handler: mutool_imap
+  mu-docstring: imap_docstring
+  mu-cond: ENABLE_IMAP
+  End MU Setup:
+*/
diff --git a/mu/mu-setup.awk b/mu/mu-setup.awk
index 5d261f1..637fb2e 100644
--- a/mu/mu-setup.awk
+++ b/mu/mu-setup.awk
@@ -55,7 +55,11 @@ END {
       print "extern int", setup[name,"handler"], "(int argc, char **argv);"
       print "extern char " setup[name,"docstring"] "[];"
     } else {
+      if (setup[name,"cond"])
+	print "#ifdef", setup[name,"cond"]
       print "{", "\"" name "\",", setup[name,"handler"] ",", setup[name,"docstring"], "},"
+      if (setup[name,"cond"])
+	print "#endif"
     }
   }
 }
diff --git a/mu/mu.h b/mu/mu.h
index d46bc41..01150ae 100644
--- a/mu/mu.h
+++ b/mu/mu.h
@@ -40,3 +40,21 @@ mu_stream_t mutool_open_pager (void);
 int mu_help (void);
 mutool_action_t dispatch_find_action (const char *name);
 char *dispatch_docstring (const char *text);
+
+
+#define VERBOSE_MASK(n) (1<<((n)+1))
+#define SET_VERBOSE_MASK(n) (shell_verbose_flags |= VERBOSE_MASK (n))
+#define CLR_VERBOSE_MASK(n) (shell_verbose_flags &= ~VERBOSE_MASK (n))
+#define QRY_VERBOSE_MASK(n) (shell_verbose_flags & VERBOSE_MASK (n))
+#define HAS_VERBOSE_MASK(n) (shell_verbose_flags & ~1)
+#define SET_VERBOSE() (shell_verbose_flags |= 1)
+#define CLR_VERBOSE() (shell_verbose_flags &= ~1)
+#define QRY_VERBOSE() (shell_verbose_flags & 1)
+
+extern int shell_verbose_flags;
+int shell_verbose (int argc, char **argv,
+		   void (*set_verbose) (void), void (*set_mask) (void));
+
+
+int get_bool (const char *str, int *pb);
+int get_port (const char *port_str, int *pn);
diff --git a/mu/pop.c b/mu/pop.c
index bf2c938..5a77e56 100644
--- a/mu/pop.c
+++ b/mu/pop.c
@@ -19,9 +19,7 @@
 #endif
 #include <stdlib.h>
 #include <string.h>
-#include <termios.h>
 #include <unistd.h>
-#include <netdb.h>
 #include <mailutils/mailutils.h>
 #include "mu.h"
 #include "argp.h"
@@ -56,67 +54,8 @@ static struct argp pop_argp = {
   NULL
 };
 
-int
-get_bool (const char *str, int *pb)
-{
-  if (mu_c_strcasecmp (str, "yes") == 0
-      || mu_c_strcasecmp (str, "on") == 0
-      || mu_c_strcasecmp (str, "true") == 0)
-    *pb = 1;
-  else if (mu_c_strcasecmp (str, "no") == 0
-      || mu_c_strcasecmp (str, "off") == 0
-      || mu_c_strcasecmp (str, "false") == 0)
-    *pb = 0;
-  else
-    return 1;
-
-  return 0;
-}
-
-int
-get_port (const char *port_str, int *pn)
-{
-  short port_num;
-  long num;
-  char *p;
-  
-  num = port_num = strtol (port_str, &p, 0);
-  if (*p == 0)
-    {
-      if (num != port_num)
-	{
-	  mu_error ("bad port number: %s", port_str);
-	  return 1;
-	}
-    }
-  else
-    {
-      struct servent *sp = getservbyname (port_str, "tcp");
-      if (!sp)
-	{
-	  mu_error ("unknown port name");
-	  return 1;
-	}
-      port_num = ntohs (sp->s_port);
-    }
-  *pn = port_num;
-  return 0;
-}
-
-
 /* Global handle for pop3.  */
-mu_pop3_t pop3;
-
-/* Flag if verbosity is needed.  */
-int verbose;
-#define VERBOSE_MASK(n) (1<<((n)+1))
-#define SET_VERBOSE_MASK(n) (verbose |= VERBOSE_MASK (n))
-#define CLR_VERBOSE_MASK(n) (verbose &= VERBOSE_MASK (n))
-#define QRY_VERBOSE_MASK(n) (verbose & VERBOSE_MASK (n))
-#define HAS_VERBOSE_MASK(n) (verbose & ~1)
-#define SET_VERBOSE() (verbose |= 1)
-#define CLR_VERBOSE() (verbose &= ~1)
-#define QRY_VERBOSE() (verbose & 1)
+static mu_pop3_t pop3;
 
 enum pop_session_status
   {
@@ -125,15 +64,15 @@ enum pop_session_status
     pop_session_logged_in
   };
 
-enum pop_session_status pop_session_status;
+static enum pop_session_status pop_session_status;
 
-int connect_argc;
-char **connect_argv;
+static int connect_argc;
+static char **connect_argv;
 
 /* Host we are connected to. */
 #define host connect_argv[0]
-int port = 110;
-char *username;
+static int port = 110;
+static char *username;
 
 const char *
 pop_session_str (enum pop_session_status stat)
@@ -185,63 +124,27 @@ pop_prompt_env ()
 }
 
 
-static int
-string_to_xlev (const char *name, int *pv)
-{
-  if (strcmp (name, "secure") == 0)
-    *pv = MU_XSCRIPT_SECURE;
-  else if (strcmp (name, "payload") == 0)
-    *pv = MU_XSCRIPT_PAYLOAD;
-  else
-    return 1;
-  return 0;
-}
-
-static int
-change_verbose_mask (int set, int argc, char **argv)
-{
-  int i;
-  
-  for (i = 0; i < argc; i++)
-    {
-      int lev;
-      
-      if (string_to_xlev (argv[i], &lev))
-	{
-	  mu_error ("unknown level: %s", argv[i]);
-	  return 1;
-	}
-      if (set)
-	SET_VERBOSE_MASK (lev);
-      else
-	CLR_VERBOSE_MASK (lev);
-    }
-  return 0;
-}
-
-void
-set_verbose (mu_pop3_t p)
+static void
+pop_set_verbose (void)
 {
-  if (p)
+  if (pop3)
     {
       if (QRY_VERBOSE ())
-	{
-	  mu_pop3_trace (p, MU_POP3_TRACE_SET);
-	}
+	mu_pop3_trace (pop3, MU_POP3_TRACE_SET);
       else
-	mu_pop3_trace (p, MU_POP3_TRACE_CLR);
+	mu_pop3_trace (pop3, MU_POP3_TRACE_CLR);
     }
 }
 
-void
-set_verbose_mask (mu_pop3_t p)
+static void
+pop_set_verbose_mask (void)
 {
-  if (p)
+  if (pop3)
     {
-      mu_pop3_trace_mask (p, QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE)
+      mu_pop3_trace_mask (pop3, QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE)
 			          ? MU_POP3_TRACE_SET : MU_POP3_TRACE_CLR,
 			      MU_XSCRIPT_SECURE);
-      mu_pop3_trace_mask (p, QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD)
+      mu_pop3_trace_mask (pop3, QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD)
 			          ? MU_POP3_TRACE_SET : MU_POP3_TRACE_CLR,
 			      MU_XSCRIPT_PAYLOAD);
     }
@@ -250,50 +153,8 @@ set_verbose_mask (mu_pop3_t p)
 static int
 com_verbose (int argc, char **argv)
 {
-  if (argc == 1)
-    {
-      if (QRY_VERBOSE ())
-	{
-	  mu_stream_printf (mustrout, "verbose is on");
-	  if (HAS_VERBOSE_MASK ())
-	    {
-	      char *delim = " (";
-	    
-	      if (QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE))
-		{
-		  mu_stream_printf (mustrout, "%ssecure", delim);
-		  delim = ", ";
-		}
-	      if (QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD))
-		mu_stream_printf (mustrout, "%spayload", delim);
-	      mu_stream_printf (mustrout, ")");
-	    }
-	  mu_stream_printf (mustrout, "\n");
-	}
-      else
-	mu_stream_printf (mustrout, "verbose is off\n");
-    }
-  else
-    {
-      int bv;
-
-      if (get_bool (argv[1], &bv) == 0)
-	{
-	  verbose |= bv;
-	  if (argc > 2)
-	    change_verbose_mask (verbose, argc - 2, argv + 2);
-	  set_verbose (pop3);
-	}
-      else if (strcmp (argv[1], "mask") == 0)
-	change_verbose_mask (1, argc - 2, argv + 2);
-      else if (strcmp (argv[1], "unmask") == 0)
-	change_verbose_mask (0, argc - 2, argv + 2);
-      else
-	mu_error ("unknown subcommand");
-      set_verbose_mask (pop3);
-    }
-
-  return 0;
+  return shell_verbose (argc, argv,
+			pop_set_verbose, pop_set_verbose_mask);
 }
 
 static int
@@ -655,8 +516,8 @@ com_connect (int argc, char **argv)
 
       if (QRY_VERBOSE ())
 	{
-	  set_verbose (pop3);
-	  set_verbose_mask (pop3);
+	  pop_set_verbose ();
+	  pop_set_verbose_mask ();
 	}
       status = mu_tcp_stream_create (&tcp, argv[0], n, MU_STREAM_READ);
       if (status == 0)
@@ -779,7 +640,7 @@ struct mutool_command pop_comtab[] = {
     N_("NAME"),
     N_("send login") },
   { "verbose",    1, 4, com_verbose,
-    "[on|off|mask|unmask] [secret [payload]]",
+    "[on|off|mask|unmask] [secure [payload]]",
     N_("control the protocol tracing") },
   { NULL }
 };
@@ -813,5 +674,6 @@ mutool_pop (int argc, char **argv)
   MU Setup: pop
   mu-handler: mutool_pop
   mu-docstring: pop_docstring
+  mu-cond: ENABLE_POP
   End MU Setup:
 */
diff --git a/mu/verbose.c b/mu/verbose.c
new file mode 100644
index 0000000..e043abe
--- /dev/null
+++ b/mu/verbose.c
@@ -0,0 +1,114 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/mailutils.h>
+#include "mu.h"
+
+/* Manipulations with verbosity flags, which are common for pop and imap. */
+int shell_verbose_flags;
+
+static int
+string_to_xlev (const char *name, int *pv)
+{
+  if (strcmp (name, "secure") == 0)
+    *pv = MU_XSCRIPT_SECURE;
+  else if (strcmp (name, "payload") == 0)
+    *pv = MU_XSCRIPT_PAYLOAD;
+  else
+    return 1;
+  return 0;
+}
+
+static int
+change_verbose_mask (int set, int argc, char **argv)
+{
+  int i;
+  
+  for (i = 0; i < argc; i++)
+    {
+      int lev;
+      
+      if (string_to_xlev (argv[i], &lev))
+	{
+	  mu_error ("unknown level: %s", argv[i]);
+	  return 1;
+	}
+      if (set)
+	SET_VERBOSE_MASK (lev);
+      else
+	CLR_VERBOSE_MASK (lev);
+    }
+  return 0;
+}
+
+int
+shell_verbose (int argc, char **argv,
+	       void (*set_verbose) (void), void (*set_mask) (void))
+{
+  if (argc == 1)
+    {
+      if (QRY_VERBOSE ())
+	{
+	  mu_stream_printf (mustrout, "verbose is on");
+	  if (HAS_VERBOSE_MASK ())
+	    {
+	      char *delim = " (";
+	    
+	      if (QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE))
+		{
+		  mu_stream_printf (mustrout, "%ssecure", delim);
+		  delim = ", ";
+		}
+	      if (QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD))
+		mu_stream_printf (mustrout, "%spayload", delim);
+	      mu_stream_printf (mustrout, ")");
+	    }
+	  mu_stream_printf (mustrout, "\n");
+	}
+      else
+	mu_stream_printf (mustrout, "verbose is off\n");
+    }
+  else
+    {
+      int bv;
+
+      if (get_bool (argv[1], &bv) == 0)
+	{
+	  if (bv)
+	    SET_VERBOSE ();
+	  else
+	    CLR_VERBOSE ();
+	  if (argc > 2)
+	    change_verbose_mask (shell_verbose_flags, argc - 2, argv + 2);
+	  set_verbose ();
+	}
+      else if (strcmp (argv[1], "mask") == 0)
+	change_verbose_mask (1, argc - 2, argv + 2);
+      else if (strcmp (argv[1], "unmask") == 0)
+	change_verbose_mask (0, argc - 2, argv + 2);
+      else
+	mu_error ("unknown subcommand");
+      set_mask ();
+    }
+
+  return 0;
+}
+
diff --git a/testsuite/.gitignore b/testsuite/.gitignore
index b312f4d..9db984b 100644
--- a/testsuite/.gitignore
+++ b/testsuite/.gitignore
@@ -7,3 +7,4 @@ testsuite.log
 mbdel
 mimetest
 smtpsend
+ufms
diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am
index 5c243b1..6e36255 100644
--- a/testsuite/Makefile.am
+++ b/testsuite/Makefile.am
@@ -42,7 +42,8 @@ INCLUDES = @MU_LIB_COMMON_INCLUDES@
 noinst_PROGRAMS = \
  mbdel\
  mimetest\
- smtpsend
+ smtpsend\
+ ufms
 
 LDADD = \
  ${MU_LIB_MBOX}\
@@ -68,6 +69,7 @@ smtpsend_LDADD = \
 TESTSUITE_AT = \
  mbdel.at\
  mime.at\
+ ufms.at\
  testsuite.at
 
 TESTSUITE = $(srcdir)/testsuite
diff --git a/testsuite/testsuite.at b/testsuite/testsuite.at
index 7bb3e05..63553e7 100644
--- a/testsuite/testsuite.at
+++ b/testsuite/testsuite.at
@@ -20,3 +20,4 @@ AT_INIT
 
 m4_include([mime.at])
 m4_include([mbdel.at])
+m4_include([ufms.at])
diff --git a/readmsg/tests/twomsg.at b/testsuite/ufms.at
similarity index 69%
copy from readmsg/tests/twomsg.at
copy to testsuite/ufms.at
index 5de48b1..2811c5f 100644
--- a/readmsg/tests/twomsg.at
+++ b/testsuite/ufms.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,13 +14,29 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-READMSGTEST([readmsg 1 2],[twomsg],
-[1 2],
+# Check for "UNIX mbox 1st message symptom" bug.  See the description in
+# ufms.c, for a detailed description.
+
+AT_SETUP([UNIX mbox 1st message symptom])
+AT_KEYWORDS([mailbox mbox mbox-ufms ufms])
+AT_CHECK([
+MUT_MBCOPY($abs_top_srcdir/testsuite/spool/mbox1)
+ufms mbox:mbox1 || exit $?
+sed 's/^\(X-IMAPbase\): \([[0-9][0-9]*]\) \(.*\)/\1: UIDVALIDITY \3/' mbox1
+],
 [0],
-[Date: Fri, 28 Dec 2001 22:18:08 +0200
+[From foobar@nonexistent.net  Fri Dec 28 22:18:09 2001
+Received: (from foobar@nonexistent.net)
+	by nonexistent.net id fBSKI8N04906
+	for bar@dontmailme.org; Fri, 28 Dec 2001 22:18:08 +0200
+Date: Fri, 28 Dec 2001 22:18:08 +0200
 From: Foo Bar <foobar@nonexistent.net>
+Message-Id: <200112282018.fBSKI8N04906@nonexistent.net>
 To: Bar <bar@dontmailme.org>
 Subject: Jabberwocky
+X-IMAPbase: UIDVALIDITY 6
+Status: R
+X-UID: 1
 
 `Twas brillig, and the slithy toves
 Did gyre and gimble in the wabe;
@@ -58,16 +74,7 @@ All mimsy were the borogoves,
 And the mome raths outgrabe.
 
 
-Date: Fri, 28 Dec 2001 23:28:08 +0200
-From: Bar <bar@dontmailme.org>
-To: Foo Bar <foobar@nonexistent.net>
-Subject: Re: Jabberwocky
-
-It seems very pretty, but it's *rather* hard to understand!'
-Somehow it seems to fill my head with ideas -- only I don't
-exactly know what they are!  However, SOMEBODY killed SOMETHING:
-that's clear, at any rate...
-
-
 ])
 
+AT_CLEANUP
+
diff --git a/testsuite/ufms.c b/testsuite/ufms.c
new file mode 100644
index 0000000..e1c1c89
--- /dev/null
+++ b/testsuite/ufms.c
@@ -0,0 +1,100 @@
+/* ufms.c - a test of "UNIX mailbox first message symptom"
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <mailutils/mailutils.h>
+
+/* UFMS, or "UNIX mailbox first message symptom", is a bug that 
+   existed in all versions of Mailutils up to 2.2.1 and 2.9.90
+   as of 2010-11-07.
+
+   Due to improperly designed expunge routine, the body of the very
+   first message in a UNIX mailbox would get corrupted under certain
+   circumstances.  The following three lines would appear at the top
+   of the body:
+
+   -IMAPbase: X Y
+   Status: S
+   X-UID: Z
+
+   where (X, Y, Z are decimal numbers and S is a status string).
+
+   Prerequisites for triggering the bug:
+
+   1. Mailbox contains more than one message.
+   2. The first message does not carry X-IMAPbase and X-UID headers.
+
+   Recipe for triggering the bug:
+
+   1. Delete some messages.
+   2. Expunge the mailbox.
+   3. Modify attributes of the first message.
+   4. Flush your changes.
+*/   
+   
+
+int
+main (int argc, char **argv)
+{
+  mu_mailbox_t mbox;
+  size_t i, count;
+  mu_message_t msg;
+  mu_attribute_t attr;
+  
+  if (argc != 2)
+    {
+      fprintf (stderr, "usage: %s MBOX\n", argv[0]);
+      return 1;
+    }
+
+  mu_registrar_record (mu_mbox_record);
+
+  /* Open the mailbox */
+  MU_ASSERT (mu_mailbox_create (&mbox, argv[1]));
+  MU_ASSERT (mu_mailbox_open (mbox, MU_STREAM_RDWR));
+  mu_mailbox_messages_count (mbox, &count);
+  if (count < 2)
+    {
+      fprintf (stderr,
+	       "%s: input mailbox should contain at least two messages\n",
+	       argv[0]);
+      exit (1);
+    }
+  /* Delete all records except the first and expunge the mailbox. */
+  for (i = 2; i <= count; i++)
+    {
+      MU_ASSERT (mu_mailbox_get_message (mbox, i, &msg));
+      MU_ASSERT (mu_message_get_attribute (msg, &attr));
+      MU_ASSERT (mu_attribute_set_deleted (attr));
+    }
+  mu_mailbox_expunge (mbox);
+
+  /* Modify attributes on the remaining message and synch */
+  MU_ASSERT (mu_mailbox_get_message (mbox, 1, &msg));
+  MU_ASSERT (mu_message_get_attribute (msg, &attr));
+  MU_ASSERT (mu_attribute_set_read (attr));
+  mu_mailbox_sync (mbox);
+
+  /* Cleanup & exit */
+  mu_mailbox_close (mbox);
+  mu_mailbox_destroy (&mbox);
+  return 0;
+}


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 09 16:59:15 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PFwDj-0007gf-34
	for mharc-commit-mailutils@gnu.org; Tue, 09 Nov 2010 16:59:15 -0500
Received: from [140.186.70.92] (port=41075 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PFwDh-0007gJ-2F
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 16:59:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFwDf-0001Rr-RL
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 16:59:12 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:40464
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFwDf-0001Rn-Pt
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 16:59:11 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFwDf-0005Bn-69
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 21:59:11 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PFwDe-0005JE-SG
	for commit-mailutils@gnu.org; Tue, 09 Nov 2010 21:59:11 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 439f8c1a9f99409087694f95c82f40c12e286371
X-Git-Newrev: 64b00582e8b3b08cbf1b6e530583b1757a8bdf77
Message-Id: <E1PFwDe-0005JE-SG@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 09 Nov 2010 21:59:10 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-180-g64b0058
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 09 Nov 2010 21:59:14 -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=64b00582e8b3b08cbf1b6e530583b1757a8bdf77

The branch, master has been updated
       via  64b00582e8b3b08cbf1b6e530583b1757a8bdf77 (commit)
      from  439f8c1a9f99409087694f95c82f40c12e286371 (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 64b00582e8b3b08cbf1b6e530583b1757a8bdf77
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 9 23:54:56 2010 +0200

    filter subsystem: bugfixes.
    
    * include/mailutils/sys/filter.h (_mu_filter_stream)<eof>: New member.
    * libmailutils/filter/binflt.c (_bit8_filter): Change name initializer
    to "8bit".
    (_bit7_filter): Change name initializer to "7bit".
    * libmailutils/filter/filter.c (mu_filter_create): Limit line
    length for encoding streams only.
    * libmailutils/stream/fltstream.c (filter_read): Use fs->eof instead
    of the regular stream EOF marker.
    * libmailutils/stream/stream.c (mu_stream_eof): Bugfix: take into
    account eventual buffered data.
    (_stream_read_unbuffered): Call mu_stream_eof instead of checking
    the _MU_STR_EOF bit.

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

Summary of changes:
 include/mailutils/sys/filter.h  |    1 +
 libmailutils/filter/binflt.c    |    4 ++--
 libmailutils/filter/filter.c    |    2 +-
 libmailutils/stream/fltstream.c |    9 +++++++--
 libmailutils/stream/stream.c    |    4 ++--
 5 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/mailutils/sys/filter.h b/include/mailutils/sys/filter.h
index 5eb91f5..557a207 100644
--- a/include/mailutils/sys/filter.h
+++ b/include/mailutils/sys/filter.h
@@ -41,6 +41,7 @@ struct _mu_filter_stream
   struct _mu_stream stream;
   mu_stream_t transport;
   int mode;
+  int eof;
   
   struct _mu_filter_buffer inbuf, outbuf;
   mu_filter_xcode_t xcode;
diff --git a/libmailutils/filter/binflt.c b/libmailutils/filter/binflt.c
index d3de518..1faf88c 100644
--- a/libmailutils/filter/binflt.c
+++ b/libmailutils/filter/binflt.c
@@ -93,7 +93,7 @@ mu_filter_record_t mu_binary_filter = &_binary_filter;
 
 
 static struct _mu_filter_record _bit8_filter = {
-  "bit8",
+  "8bit",
   0,
   NULL,
   _copy_codec,
@@ -103,7 +103,7 @@ static struct _mu_filter_record _bit8_filter = {
 mu_filter_record_t mu_bit8_filter = &_bit8_filter;
 
 static struct _mu_filter_record _bit7_filter = {
-  "bit7",
+  "7bit",
   0,
   NULL,
   _bit7_coder,
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index a98d0a9..6ab3c92 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -182,7 +182,7 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
 
   status = ((flags & MU_STREAM_WRITE) ? filter_create_wr : filter_create_rd)
                    (pstream, stream,
-		    frec->max_line_length,
+		    mode == MU_FILTER_ENCODE ? frec->max_line_length : 0,
 		    mode,
 		    mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder,
 		    xdata,
diff --git a/libmailutils/stream/fltstream.c b/libmailutils/stream/fltstream.c
index f6fe6ad..a830957 100644
--- a/libmailutils/stream/fltstream.c
+++ b/libmailutils/stream/fltstream.c
@@ -127,6 +127,9 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
 	{
 	  enum mu_filter_result res;
 	  int rc;
+
+	  if (fs->eof)
+	    break;
 	  
 	  if (MFB_RDBYTES (fs->inbuf) < min_input_level && !again)
 	    {
@@ -174,7 +177,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
 	      again = 0;
 	      if (cmd == mu_filter_lastbuf || iobuf.eof)
 		{
-		  _mu_stream_seteof (stream);
+		  fs->eof = 1;
 		  stop = 1;
 		}
 	      break;
@@ -517,8 +520,10 @@ mu_filter_stream_create (mu_stream_t *pflt,
   fs->xcode = xcode;
   fs->xdata = xdata;
   fs->mode = mode;
+  fs->eof = 0;
   
-  mu_stream_set_buffer ((mu_stream_t) fs, mu_buffer_full, MU_FILTER_BUF_SIZE);
+  mu_stream_set_buffer ((mu_stream_t) fs, mu_buffer_full,
+			MU_FILTER_BUF_SIZE);
 
   rc = filter_stream_init (fs);
   if (rc)
diff --git a/libmailutils/stream/stream.c b/libmailutils/stream/stream.c
index 367db90..48ca32b 100644
--- a/libmailutils/stream/stream.c
+++ b/libmailutils/stream/stream.c
@@ -368,7 +368,7 @@ mu_stream_clearerr (mu_stream_t stream)
 int
 mu_stream_eof (mu_stream_t stream)
 {
-  return stream->flags & _MU_STR_EOF;
+  return (stream->flags & _MU_STR_EOF) && (stream->pos == stream->level);
 }
 
 int
@@ -589,7 +589,7 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size,
   if (stream->flags & _MU_STR_ERR)
     return stream->last_err;
     
-  if ((stream->flags & _MU_STR_EOF) || size == 0)
+  if (mu_stream_eof (stream) || size == 0)
     {
       if (pnread)
 	*pnread = 0;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 10 08:57:27 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PGBB1-0004s4-6B
	for mharc-commit-mailutils@gnu.org; Wed, 10 Nov 2010 08:57:27 -0500
Received: from [140.186.70.92] (port=48664 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PGBAp-0004RB-I1
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 08:57:25 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGBAQ-0006TY-Em
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 08:56:53 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:44495
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGBAQ-0006TU-CD
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 08:56:50 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGBAP-0007uA-TI
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 13:56:49 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGBAL-0002Ab-AA
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 13:56:49 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 64b00582e8b3b08cbf1b6e530583b1757a8bdf77
X-Git-Newrev: 50bf64db74ffa1d1cf1c5ebbda55cabdb530b8f5
Message-Id: <E1PGBAL-0002Ab-AA@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 10 Nov 2010 13:56:45 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-183-g50bf64d
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Nov 2010 13:57:25 -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=50bf64db74ffa1d1cf1c5ebbda55cabdb530b8f5

The branch, master has been updated
       via  50bf64db74ffa1d1cf1c5ebbda55cabdb530b8f5 (commit)
       via  e9580ebf7bd77a9d1c456c2138d38258275b454c (commit)
       via  90af346ddc4f730f2dd8b26fda528750af006b76 (commit)
      from  64b00582e8b3b08cbf1b6e530583b1757a8bdf77 (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 50bf64db74ffa1d1cf1c5ebbda55cabdb530b8f5
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 10 15:52:51 2010 +0200

    mhn: optimize using new API.
    
    * mh/mhn.c (_get_hdr_value): Remove.  All callers modified to use
    mu_header_aget_value_unfold instead.
    (mhn_message_size): Type of 2nd arg is mu_off_t *.
    Use null stream & stream stats in realsize mode.
    (list_handler): Fix rounding of the message size.
    (copy_header): Use mu_header_sget* to avoid unnecessary
    memory allocations.

commit e9580ebf7bd77a9d1c456c2138d38258275b454c
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 10 14:11:09 2010 +0200

    Improve stream statistics interface. Introduce "null stream".
    
    * include/mailutils/stream.h (MU_IOCTL_NULLSTREAM_SET_PATTERN)
    (MU_IOCTL_NULLSTREAM_SET_PATCLASS)
    (MU_IOCTL_NULLSTREAM_SETSIZE)
    (MU_IOCTL_NULLSTREAM_CLRSIZE): New ioctl opcodes.
    (mu_nullstream_pattern): New struct.
    (MU_STREAM_STAT_IN,MU_STREAM_STAT_OUT)
    (MU_STREAM_STAT_READS,MU_STREAM_STAT_WRITES)
    (MU_STREAM_STAT_SEEKS,_MU_STREAM_STAT_MAX): New defines.
    (MU_STREAM_STAT_MASK): New macro.
    (MU_STREAM_STAT_MASK_ALL): New define.
    (mu_stream_stat_buffer): New typedef.
    (mu_stream_set_stat, mu_stream_get_stat)
    (mu_nullstream_create): New protos.
    (mu_stream_bytes_in, mu_stream_bytes_out): Remove protos.
    
    * include/mailutils/sys/nullstream.h: New file.
    * include/mailutils/sys/stream.h (_mu_stream) <bytes_in>,
    <bytes_out>: Remove.
    <statmask,statbuf>: New members.
    * include/mailutils/sys/Makefile.am (sysinclude_HEADERS): Add nullstream.h.
    
    * libmailutils/stream/nullstream.c: New file.
    * libmailutils/stream/stream.c (_stream_read, _stream_write)
    (_stream_seek, _stream_stat_incr): New macros.
    (_stream_fill_buffer, mu_stream_seek)
    (_stream_read_unbuffered)
    (_stream_write_unbuffered): Use _stream_read, _stream_write
    and _stream_seek instead of calling the corresponding methods directly.
    (mu_stream_bytes_in, mu_stream_bytes_out): Remove.
    (mu_stream_unref): Clear statbuf, if provided.
    (mu_stream_set_stat, mu_stream_get_stat): New functions.
    
    * libmailutils/stream/Makefile.am (libstream_la_SOURCES): Add nullstream.c.
    
    * libmailutils/stream/fltstream.c (filter_wr_close): Check for fs->eof.
    
    * examples/base64.c (c_copy): Use new statistics interface.
    * libmailutils/tests/fltst.c: Likewise.

commit 90af346ddc4f730f2dd8b26fda528750af006b76
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 10 10:59:25 2010 +0200

    attachment.c: redesign/simplify using the new API.
    
    * libmailutils/mime/attachment.c (BUF_SIZE): Remove.
    (_mu_mime_io_buffer)<buf, bufsize>: Remove members.
    (MSG_HDR): Remove.
    (mu_message_create_attachment): Use mu_asprintf instead of
    manually crafting the string.
    (mu_mime_io_buffer_set_size)
    (mu_mime_io_buffer_get_size): Remove.
    (mu_message_save_attachment)
    (mu_message_encapsulate)
    (mu_message_unencapsulate): Use mu_header_sget to avoid
    unnecessary memory allocations.
    Use mu_stream_copy instead of (ineffective) loops.
    
    * include/mailutils/message.h (mu_mime_io_buffer_set_size)
    (mu_mime_io_buffer_get_size): Remove prototypes.
    * include/mailutils/header.h (MU_HEADER_RESENT_SENDER)
    (MU_HEADER_CONTENT_TRANSFER_ENCODING)
    (MU_HEADER_DELIVERY_DATE)
    (MU_HEADER_ENVELOPE_TO): Normalize spelling.

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

Summary of changes:
 doc/texinfo/mu-mh.texi                             |    2 +-
 examples/base64.c                                  |   36 +++-
 include/mailutils/header.h                         |    8 +-
 include/mailutils/message.h                        |    3 -
 include/mailutils/stream.h                         |   45 ++++-
 include/mailutils/sys/Makefile.am                  |    1 +
 .../mailutils/sys/{streamref.h => nullstream.h}    |   20 +-
 include/mailutils/sys/stream.h                     |    4 +-
 libmailutils/mime/attachment.c                     |  151 ++++-----------
 libmailutils/stream/Makefile.am                    |    1 +
 libmailutils/stream/fltstream.c                    |    2 +-
 libmailutils/stream/nullstream.c                   |  204 ++++++++++++++++++++
 libmailutils/stream/stream.c                       |   73 +++++---
 libmailutils/tests/fltst.c                         |   39 ++++-
 mh/mhn.c                                           |   81 ++++-----
 15 files changed, 459 insertions(+), 211 deletions(-)
 copy include/mailutils/sys/{streamref.h => nullstream.h} (62%)
 create mode 100644 libmailutils/stream/nullstream.c

diff --git a/doc/texinfo/mu-mh.texi b/doc/texinfo/mu-mh.texi
index 4f8d336..f25f625 100644
--- a/doc/texinfo/mu-mh.texi
+++ b/doc/texinfo/mu-mh.texi
@@ -4,7 +4,7 @@
 @comment *******************************************************************
 
 The primary aim of this implementation is to provide an interface
-between Mailutils and Emacs using mh-e module. 
+between Mailutils and Emacs using mh-e module.
 
 To use Mailutils MH with Emacs, add the following line to your
 site-start.el or .emacs file:
diff --git a/examples/base64.c b/examples/base64.c
index deadfd2..2e80a60 100644
--- a/examples/base64.c
+++ b/examples/base64.c
@@ -33,6 +33,22 @@ int printable = 0;
 static void
 c_copy (mu_stream_t out, mu_stream_t in)
 {
+  mu_stream_stat_buffer instat, outstat;
+
+  if (verbose)
+    {
+      mu_stream_set_stat (in,
+			  MU_STREAM_STAT_MASK (MU_STREAM_STAT_IN) |
+			  MU_STREAM_STAT_MASK (MU_STREAM_STAT_READS) |
+			  MU_STREAM_STAT_MASK (MU_STREAM_STAT_SEEKS),
+			  instat);
+      mu_stream_set_stat (out,
+			  MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUT) |
+			  MU_STREAM_STAT_MASK (MU_STREAM_STAT_WRITES) |
+			  MU_STREAM_STAT_MASK (MU_STREAM_STAT_SEEKS),
+			  outstat);
+    }
+
   if (printable)
     {
       char c;
@@ -58,9 +74,23 @@ c_copy (mu_stream_t out, mu_stream_t in)
   mu_stream_close (out);
   mu_stream_close (in);
   if (verbose)
-    fprintf (stderr, "\ntotal: %lu/%lu bytes\n",
-	     (unsigned long) mu_stream_bytes_in (in),
-	     (unsigned long) mu_stream_bytes_out (out));
+    {
+      fprintf (stderr, "\nInput stats:\n");
+      fprintf (stderr, "Bytes in: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_IN]);
+      fprintf (stderr, "Reads: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_READS]);
+      fprintf (stderr, "Seeks: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_SEEKS]);
+
+      fprintf (stderr, "\nOutput stats:\n");
+      fprintf (stderr, "Bytes out: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_OUT]);
+      fprintf (stderr, "Writes: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_WRITES]);
+      fprintf (stderr, "Seeks: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_SEEKS]);
+    }
 }
 
 /* Set the maximum line length for the filter NAME to LENGTH.
diff --git a/include/mailutils/header.h b/include/mailutils/header.h
index 0a73d52..c326c5c 100644
--- a/include/mailutils/header.h
+++ b/include/mailutils/header.h
@@ -35,7 +35,7 @@ extern "C" {
 #define MU_HEADER_RESENT_FROM               "Resent-From"
 #define MU_HEADER_SUBJECT                   "Subject"
 #define MU_HEADER_SENDER                    "Sender"
-#define MU_HEADER_RESENT_SENDER             "Resent-SENDER"
+#define MU_HEADER_RESENT_SENDER             "Resent-Sender"
 #define MU_HEADER_TO                        "To"
 #define MU_HEADER_RESENT_TO                 "Resent-To"
 #define MU_HEADER_CC                        "Cc"
@@ -54,7 +54,7 @@ extern "C" {
 #define MU_HEADER_STATUS                    "Status"
 #define MU_HEADER_CONTENT_LENGTH            "Content-Length"
 #define MU_HEADER_CONTENT_LANGUAGE          "Content-Language"
-#define MU_HEADER_CONTENT_TRANSFER_ENCODING "Content-transfer-encoding"
+#define MU_HEADER_CONTENT_TRANSFER_ENCODING "Content-Transfer-Encoding"
 #define MU_HEADER_CONTENT_ID                "Content-ID"
 #define MU_HEADER_CONTENT_TYPE              "Content-Type"
 #define MU_HEADER_CONTENT_DESCRIPTION       "Content-Description"
@@ -68,8 +68,8 @@ extern "C" {
 #define MU_HEADER_ENV_SENDER                "X-Envelope-Sender"
 #define MU_HEADER_ENV_DATE                  "X-Envelope-Date"
 #define MU_HEADER_FCC                       "Fcc"
-#define MU_HEADER_DELIVERY_DATE             "Delivery-date"
-#define MU_HEADER_ENVELOPE_TO               "Envelope-to"
+#define MU_HEADER_DELIVERY_DATE             "Delivery-Date"
+#define MU_HEADER_ENVELOPE_TO               "Envelope-To"
 #define MU_HEADER_X_EXPIRE_TIMESTAMP        "X-Expire-Timestamp"
   
 #define MU_HEADER_REPLACE 0x01
diff --git a/include/mailutils/message.h b/include/mailutils/message.h
index 09c7c9e..7208ee6 100644
--- a/include/mailutils/message.h
+++ b/include/mailutils/message.h
@@ -148,9 +148,6 @@ extern int mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
 extern int mu_mime_io_buffer_create (mu_mime_io_buffer_t *pinfo);
 extern void mu_mime_io_buffer_destroy (mu_mime_io_buffer_t *pinfo);
   
-extern void mu_mime_io_buffer_set_size (mu_mime_io_buffer_t info, size_t size);
-extern void mu_mime_io_buffer_get_size (mu_mime_io_buffer_t info,
-					size_t *psize);
 extern int mu_mime_io_buffer_set_charset (mu_mime_io_buffer_t info,
 					  const char *charset);
 extern void mu_mime_io_buffer_sget_charset (mu_mime_io_buffer_t info,
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index bb14186..444733e 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -76,12 +76,31 @@ enum mu_buffer_type
 
 #define MU_IOCTL_GET_ECHO        12     
 #define MU_IOCTL_SET_ECHO        13  
+
+/* The following ioctls are for nullstreams only: */  
+#define MU_IOCTL_NULLSTREAM_SET_PATTERN 14
+  /* Set read pattern.
+     Argument: struct mu_nullstream_pattern *pat.
+     If pat==NULL, any reads from that stream will return EOF. */
+#define MU_IOCTL_NULLSTREAM_SET_PATCLASS 15
+  /* Set pattern class for reads:  Argument int *pclass (a class mask
+     from mailutils/cctype.h */
+#define MU_IOCTL_NULLSTREAM_SETSIZE 16
+  /* Limit stream size.  Argument: mu_off_t *psize; */
+#define MU_IOCTL_NULLSTREAM_CLRSIZE 17
+  /* Lift the size limit.  Argument: NULL */
   
 #define MU_TRANSPORT_INPUT  0
 #define MU_TRANSPORT_OUTPUT 1
 #define MU_TRANSPORT_VALID_TYPE(n) \
   ((n) == MU_TRANSPORT_INPUT || (n) == MU_TRANSPORT_OUTPUT)
 
+struct mu_nullstream_pattern
+{
+  char *pattern;
+  size_t size;
+};
+  
 struct mu_buffer_query
 {
   int type;                     /* One of MU_TRANSPORT_ defines */
@@ -89,6 +108,28 @@ struct mu_buffer_query
   size_t bufsize;               /* Buffer size */
 };
 
+/* Statistics */  
+#define MU_STREAM_STAT_IN       0
+#define MU_STREAM_STAT_OUT      1
+#define MU_STREAM_STAT_READS    2 
+#define MU_STREAM_STAT_WRITES   3
+#define MU_STREAM_STAT_SEEKS    4
+#define _MU_STREAM_STAT_MAX     5   
+
+#define MU_STREAM_STAT_MASK(n)  (1U<<(n+1))
+#define MU_STREAM_STAT_MASK_ALL  \
+  (MU_STREAM_STAT_MASK (MU_STREAM_STAT_IN) | \
+   MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUT) |   \
+   MU_STREAM_STAT_MASK (MU_STREAM_STAT_READS) | \
+   MU_STREAM_STAT_MASK (MU_STREAM_STAT_WRITES) | \
+   MU_STREAM_STAT_MASK (MU_STREAM_STAT_SEEKS))
+
+typedef mu_off_t mu_stream_stat_buffer[_MU_STREAM_STAT_MAX];
+int mu_stream_set_stat (mu_stream_t stream, int statmask,
+			mu_stream_stat_buffer statbuf);
+int mu_stream_get_stat (mu_stream_t stream, int *pstatmask,
+			mu_off_t **pstatbuf);
+  
 #define MU_STREAM_DEFBUFSIZ 8192
 extern size_t mu_stream_default_buffer_size;
 
@@ -127,8 +168,6 @@ int mu_stream_writeline (mu_stream_t stream, const char *buf, size_t size);
 int mu_stream_flush (mu_stream_t stream);
 int mu_stream_close (mu_stream_t stream);
 int mu_stream_size (mu_stream_t stream, mu_off_t *psize);
-mu_off_t mu_stream_bytes_in (mu_stream_t stream);
-mu_off_t mu_stream_bytes_out (mu_stream_t stream);
 int mu_stream_ioctl (mu_stream_t stream, int code, void *ptr);
 int mu_stream_truncate (mu_stream_t stream, mu_off_t);
 int mu_stream_shutdown (mu_stream_t stream, int how);
@@ -202,6 +241,8 @@ int mu_dbgstream_create(mu_stream_t *pref, mu_debug_t debug,
 int mu_rdcache_stream_create (mu_stream_t *pstream, mu_stream_t transport,
 			      int flags);
 
+int mu_nullstream_create (mu_stream_t *pref, int flags);
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/sys/Makefile.am b/include/mailutils/sys/Makefile.am
index 90610cd..0ef9f33 100644
--- a/include/mailutils/sys/Makefile.am
+++ b/include/mailutils/sys/Makefile.am
@@ -42,6 +42,7 @@ sysinclude_HEADERS = \
  mime.h\
  monitor.h\
  nntp.h\
+ nullstream.h\
  observer.h\
  pop3.h\
  prog_stream.h\
diff --git a/include/mailutils/sys/streamref.h b/include/mailutils/sys/nullstream.h
similarity index 62%
copy from include/mailutils/sys/streamref.h
copy to include/mailutils/sys/nullstream.h
index 35f035e..0e906fe 100644
--- a/include/mailutils/sys/streamref.h
+++ b/include/mailutils/sys/nullstream.h
@@ -14,20 +14,22 @@
    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/>. */
 
-#ifndef _MAILUTILS_SYS_STREAMREF_H
-#define _MAILUTILS_SYS_STREAMREF_H
+#ifndef _MAILUTILS_SYS_NULLSTREAM_H
+#define _MAILUTILS_SYS_NULLSTREAM_H
 
 #include <mailutils/types.h>
 #include <mailutils/sys/stream.h>
 
-struct _mu_streamref
+#define MU_NULLSTREAM_SIZE     0x0001 /* Stream has a limited size */
+#define MU_NULLSTREAM_PATSTAT  0x0002 /* Pattern is allocated statically */
+
+struct _mu_nullstream
 {
-  struct _mu_stream stream;      /* Superclass */
-  mu_stream_t transport;         /* Transport stream */
-  mu_off_t offset;               /* Offset in transport stream */
-                            /* For abridged stream references: */
-  mu_off_t start;                /* Start offset */
-  mu_off_t end;                  /* End offset */
+  struct _mu_stream base;        /* Superclass */
+  int mode;                      /* Stream mode */
+  mu_off_t size;                 /* Stream size */
+  char *pattern;                 /* Fill pattern */
+  size_t patsize;                /* Size of pattern */
 };
 
 #endif
diff --git a/include/mailutils/sys/stream.h b/include/mailutils/sys/stream.h
index aa95f7e..2fe18ae 100644
--- a/include/mailutils/sys/stream.h
+++ b/include/mailutils/sys/stream.h
@@ -45,7 +45,9 @@ struct _mu_stream
 
   int flags;
   mu_off_t offset;
-  mu_off_t bytes_in, bytes_out;
+  
+  int statmask;
+  mu_off_t *statbuf;
   
   int last_err;
 
diff --git a/libmailutils/mime/attachment.c b/libmailutils/mime/attachment.c
index e4a09e3..7bd7a80 100644
--- a/libmailutils/mime/attachment.c
+++ b/libmailutils/mime/attachment.c
@@ -43,14 +43,11 @@
 #include <mailutils/stream.h>
 #include <mailutils/errno.h>
 #include <mailutils/util.h>
-
-#define BUF_SIZE	2048
+#include <mailutils/io.h>
 
 struct _mu_mime_io_buffer
 {
   unsigned int refcnt;
-  char *buf;
-  size_t bufsize;
   char *charset;
   mu_header_t hdr;
   mu_message_t msg;
@@ -58,8 +55,6 @@ struct _mu_mime_io_buffer
   mu_stream_t fstream;	/* output file stream for saving attachment */
 };
 
-#define MSG_HDR "Content-Type: %s; name=%s\nContent-Transfer-Encoding: %s\nContent-Disposition: attachment; filename=%s\n\n"
-
 int
 mu_message_create_attachment (const char *content_type, const char *encoding,
 			      const char *filename, mu_message_t *newmsg)
@@ -88,35 +83,34 @@ mu_message_create_attachment (const char *content_type, const char *encoding,
 	    name++;
 	  else
 	    name = fname;
-	  if ((header =
-	       malloc (strlen (MSG_HDR) + strlen (content_type) +
-		       strlen (name) * 2 + strlen (encoding) + 1)) == NULL)
-	    ret = ENOMEM;
-	  else
+	  ret = mu_asprintf (&header,
+			     "Content-Type: %s; name=%s\n"
+			     "Content-Transfer-Encoding: %s\n"
+			     "Content-Disposition: attachment; filename=%s\n\n",
+			     content_type, name, encoding, name);
+	  if (ret)
 	    {
-	      sprintf (header, MSG_HDR, content_type, name, encoding, name);
-	      if ((ret = mu_header_create (&hdr, header, strlen (header)))
-		  == 0)
+	      if ((ret = mu_header_create (&hdr, header,
+					   strlen (header))) == 0)
 		{
 		  mu_message_get_body (*newmsg, &body);
-		  if ((ret =
-		       mu_file_stream_create (&fstream, filename,
-					      MU_STREAM_READ)) == 0)
+		  if ((ret = mu_file_stream_create (&fstream, filename,
+						    MU_STREAM_READ)) == 0)
 		    {
-		      if ((ret =
-			   mu_filter_create (&tstream, fstream, encoding,
-					     MU_FILTER_ENCODE,
-					     MU_STREAM_READ)) == 0)
+		      if ((ret = mu_filter_create (&tstream, fstream, encoding,
+						   MU_FILTER_ENCODE,
+						   MU_STREAM_READ)) == 0)
 			{
 			  mu_body_set_stream (body, tstream, *newmsg);
 			  mu_message_set_header (*newmsg, hdr, NULL);
 			}
 		    }
+		  free (header);
 		}
-	      free (header);
 	    }
 	}
     }
+  
   if (ret)
     {
       if (*newmsg)
@@ -139,23 +133,10 @@ mu_mime_io_buffer_create (mu_mime_io_buffer_t *pinfo)
   if ((info = calloc (1, sizeof (*info))) == NULL)
     return ENOMEM;
   info->refcnt = 1;
-  info->bufsize = BUF_SIZE;
   *pinfo = info;
   return 0;
 }
 
-void
-mu_mime_io_buffer_set_size (mu_mime_io_buffer_t info, size_t size)
-{
-  info->bufsize = size;
-}
-
-void
-mu_mime_io_buffer_get_size (mu_mime_io_buffer_t info, size_t *psize)
-{
-  *psize = info->bufsize;
-}
-
 int
 mu_mime_io_buffer_set_charset (mu_mime_io_buffer_t info, const char *charset)
 {
@@ -189,7 +170,6 @@ mu_mime_io_buffer_destroy (mu_mime_io_buffer_t *pinfo)
     {
       mu_mime_io_buffer_t info = *pinfo;
       free (info->charset);
-      free (info->buf);
       free (info);
       *pinfo = NULL;
     }
@@ -212,7 +192,6 @@ _attachment_free (struct _mu_mime_io_buffer *info, int free_message)
   if (--info->refcnt == 0)
     {
       free (info->charset);
-      free (info->buf);
       free (info);
     }
 }
@@ -245,11 +224,6 @@ _attachment_setup (mu_mime_io_buffer_t *pinfo, mu_message_t msg,
 	return ret;
     }
   
-  if (!info->buf && ((info->buf = malloc (info->bufsize)) == NULL))
-    {
-      _attachment_free (info, 0);
-      return ENOMEM;
-    }
   info->msg = msg;
   *pinfo = info;
   return 0;
@@ -261,8 +235,6 @@ mu_message_save_attachment (mu_message_t msg, const char *filename,
 {
   mu_stream_t istream;
   int ret;
-  size_t size;
-  size_t nbytes;
   mu_header_t hdr;
   const char *fname = NULL;
   char *partname = NULL;
@@ -285,44 +257,22 @@ mu_message_save_attachment (mu_message_t msg, const char *filename,
       else
 	fname = filename;
       if (fname
-	  && (ret =
-	      mu_file_stream_create (&info->fstream, fname,
+	  && (ret = mu_file_stream_create (&info->fstream, fname,
 				     MU_STREAM_WRITE | MU_STREAM_CREAT)) == 0)
 	{
-	  char *content_encoding;
-	  char *content_encoding_mem = NULL;
-	  
-	  mu_header_get_value (hdr, "Content-Transfer-Encoding", NULL, 0,
-			       &size);
-	  if (size)
-	    {
-	      content_encoding_mem = malloc (size + 1);
-	      if (content_encoding_mem == NULL)
-		ret = ENOMEM;
-	      content_encoding = content_encoding_mem;
-	      mu_header_get_value (hdr, "Content-Transfer-Encoding",
-				   content_encoding, size + 1, 0);
-	    }
-	  else
+	  const char *content_encoding;
+
+	  if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+				    &content_encoding))
 	    content_encoding = "7bit";
-	  ret =
-	    mu_filter_create (&info->stream, istream, content_encoding,
-			      MU_FILTER_DECODE,
-			      MU_STREAM_READ);
-	  free (content_encoding_mem);
+	  ret = mu_filter_create (&info->stream, istream, content_encoding,
+				  MU_FILTER_DECODE,
+				  MU_STREAM_READ);
 	}
     }
   if (info->stream && istream)
-    {
-      while (((ret =
-	       mu_stream_read (info->stream, info->buf, BUF_SIZE, 
-			       &nbytes)) == 0 && nbytes))
-	{
-	  if ((ret =
-	       mu_stream_write (info->fstream, info->buf, nbytes, NULL)) != 0)
-	    break;
-	}
-    }
+    ret = mu_stream_copy (info->fstream, info->stream, 0, NULL);
+
   if (ret != EAGAIN && info)
     {
       mu_stream_close (info->fstream);
@@ -345,9 +295,7 @@ mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg,
 			mu_mime_io_buffer_t info)
 {
   mu_stream_t istream, ostream;
-  const char *header;
   int ret = 0;
-  size_t nbytes;
   mu_message_t tmsg = NULL;
   
   if (newmsg == NULL)
@@ -361,11 +309,13 @@ mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg,
       if (ret)
 	return ret;
       msg = tmsg;
-      header =
-	"Content-Type: message/rfc822\nContent-Transfer-Encoding: 7bit\n\n";
-      if ((ret =
-	   mu_header_create (&hdr, header, strlen (header))) == 0)
+#define MSG822_HEADER "Content-Type: message/rfc822\n" \
+ 	              "Content-Transfer-Encoding: 7bit\n\n"
+      if ((ret = mu_header_create (&hdr,
+				   MSG822_HEADER,
+				   sizeof (MSG822_HEADER) - 1)) == 0)
 	ret = mu_message_set_header (msg, hdr, NULL);
+#undef MSG822_HEADER
       if (ret)
 	{
 	  mu_message_destroy (&msg, NULL);
@@ -382,13 +332,7 @@ mu_message_encapsulate (mu_message_t msg, mu_message_t *newmsg,
   if (ret == 0 && (ret = mu_message_get_streamref (msg, &istream)) == 0)
     {
       mu_stream_seek (istream, 0, MU_SEEK_SET, NULL);
-      while (((ret = mu_stream_read (istream, info->buf, BUF_SIZE, 
-				     &nbytes)) == 0 && nbytes))
-	{
-	  if ((ret =
-	       mu_stream_write (ostream, info->buf, nbytes, NULL)) != 0)
-	    break;
-	}
+      ret = mu_stream_copy (ostream, istream, 0, NULL);
       mu_stream_destroy (&istream);
     }
   if (ret == 0)
@@ -404,7 +348,6 @@ int
 mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
 			  mu_mime_io_buffer_t info)
 {
-  size_t size, nbytes;
   int ret = 0;
   mu_header_t hdr;
   mu_stream_t istream, ostream;
@@ -417,21 +360,10 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
   if (info == NULL /* FIXME: not needed? */
       && (ret = mu_message_get_header (msg, &hdr)) == 0)
     {
-      mu_header_get_value (hdr, "Content-Type", NULL, 0, &size);
-      if (size)
-	{
-	  char *content_type;
-	  if ((content_type = malloc (size + 1)) == NULL)
-	    return ENOMEM;
-	  mu_header_get_value (hdr, "Content-Type", content_type, size + 1,
-			       0);
-	  ret = mu_c_strncasecmp (content_type, MESSAGE_RFC822_STR,
-				  sizeof (MESSAGE_RFC822_STR) - 1);
-	  free (content_type);
-	  if (ret != 0)
-	    return EINVAL;
-	}
-      else
+      const char *s;
+      if (!(mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE, &s) == 0 &&
+	    mu_c_strncasecmp (s, MESSAGE_RFC822_STR,
+			      sizeof (MESSAGE_RFC822_STR) - 1) == 0))
 	return EINVAL;
     }
   if ((ret = _attachment_setup (&info, msg, &istream)) != 0)
@@ -442,14 +374,7 @@ mu_message_unencapsulate (mu_message_t msg, mu_message_t *newmsg,
     {
       mu_message_get_streamref (info->msg, &ostream);
       mu_stream_seek (ostream, 0, MU_SEEK_SET, NULL);
-      while (((ret =
-	       mu_stream_read (istream, info->buf, BUF_SIZE, 
-			       &nbytes)) == 0 && nbytes))
-	{
-	  if ((ret =
-	       mu_stream_write (ostream, info->buf, nbytes, NULL)) != 0)
-	    break;
-	}
+      ret = mu_stream_copy (ostream, istream, 0, NULL);
       mu_stream_destroy (&ostream);
     }
   if (ret == 0)
diff --git a/libmailutils/stream/Makefile.am b/libmailutils/stream/Makefile.am
index c68e83a..82fa573 100644
--- a/libmailutils/stream/Makefile.am
+++ b/libmailutils/stream/Makefile.am
@@ -25,6 +25,7 @@ libstream_la_SOURCES = \
  mapfile_stream.c\
  memory_stream.c\
  message_stream.c\
+ nullstream.c\
  prog_stream.c\
  rdcache_stream.c\
  socket_stream.c\
diff --git a/libmailutils/stream/fltstream.c b/libmailutils/stream/fltstream.c
index a830957..ad4d0f1 100644
--- a/libmailutils/stream/fltstream.c
+++ b/libmailutils/stream/fltstream.c
@@ -407,7 +407,7 @@ static int
 filter_wr_close (mu_stream_t stream)
 {
   struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream;
-  if (!mu_stream_eof (stream))
+  if (!mu_stream_eof (stream) && !fs->eof)
     {
       size_t dummy;
       int rc = filter_write_internal (stream, mu_filter_lastbuf, NULL, 0,
diff --git a/libmailutils/stream/nullstream.c b/libmailutils/stream/nullstream.c
new file mode 100644
index 0000000..50c174f
--- /dev/null
+++ b/libmailutils/stream/nullstream.c
@@ -0,0 +1,204 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 3, 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 <errno.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/stream.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/nullstream.h>
+#include <mailutils/stream.h>
+#include <mailutils/cctype.h>
+
+static int
+_nullstream_read (struct _mu_stream *str, char *buf, size_t bufsize,
+		  size_t *pnread)
+{
+  struct _mu_nullstream *np = (struct _mu_nullstream *)str;
+  size_t i;
+  mu_off_t off;
+  
+  if (np->pattern == NULL)
+    {
+      *pnread = 0;
+      return 0;
+    }
+
+  off = np->base.offset + np->base.pos;
+  for (i = 0; i < bufsize; i++, off++)
+    {
+      if ((np->mode & MU_NULLSTREAM_SIZE) && off >= np->size)
+	break;
+      *buf++ = np->pattern[off % np->patsize];
+    }
+  *pnread = i;
+  return 0;
+}
+
+static int
+_nullstream_write (struct _mu_stream *str, const char *buf, size_t bufsize,
+		   size_t *pnwrite)
+{
+  *pnwrite = bufsize;
+  return 0;
+}
+
+static void
+_nullstream_free_pattern (struct _mu_nullstream *np)
+{
+  if (!(np->mode & MU_NULLSTREAM_PATSTAT))
+    {
+      free (np->pattern);
+      np->pattern = NULL;
+      np->patsize = 0;
+      np->mode &= ~MU_NULLSTREAM_PATSTAT;
+    }
+}
+
+static void
+_nullstream_done (struct _mu_stream *str)
+{
+  struct _mu_nullstream *np = (struct _mu_nullstream *)str;
+  _nullstream_free_pattern (np);
+}
+
+static int
+_nullstream_seek (struct _mu_stream *str, mu_off_t off, mu_off_t *ppos)
+{
+  struct _mu_nullstream *np = (struct _mu_nullstream *)str;
+  if ((np->mode & MU_NULLSTREAM_SIZE) && off >= np->size)
+    return ESPIPE;
+  *ppos = off;
+  return 0;
+}
+
+static int
+_nullstream_size (struct _mu_stream *str, mu_off_t *psize)
+{
+  struct _mu_nullstream *np = (struct _mu_nullstream *)str;
+  *psize = (np->mode & MU_NULLSTREAM_SIZE) ? np->size : 0;
+  return 0;
+}
+
+static int
+_nullstream_truncate (struct _mu_stream *str, mu_off_t size)
+{
+  struct _mu_nullstream *np = (struct _mu_nullstream *)str;
+  np->base.size = _nullstream_size;
+  np->size = size;
+  np->mode |= MU_NULLSTREAM_SIZE;
+  return 0;
+}
+
+static int
+_nullstream_ctl (struct _mu_stream *str, int op, void *arg)
+{
+  struct _mu_nullstream *np = (struct _mu_nullstream *)str;
+
+  switch (op)
+    {
+    case MU_IOCTL_NULLSTREAM_SET_PATTERN:
+      if (!arg)
+	_nullstream_free_pattern (np);
+      else
+	{
+	  struct mu_nullstream_pattern *pat = arg;
+	  char *p;
+	  
+	  p = malloc (pat->size);
+	  if (!p)
+	    return ENOMEM;
+	  memcpy (p, pat->pattern, pat->size);
+	  _nullstream_free_pattern (np);
+	  np->pattern = p;
+	  np->patsize = pat->size;
+	}
+      break;
+
+    case MU_IOCTL_NULLSTREAM_SET_PATCLASS:
+      if (!arg)
+	return EINVAL;
+      else
+	{
+	  char buf[256];
+	  int cnt = 0, i;
+	  int class = *(int*)arg;
+	  char *p;
+	  
+	  for (i = 0; i < 256; i++)
+	    {
+	      if (mu_c_is_class (i, class))
+		buf[cnt++] = i;
+	    }
+
+	  p = malloc (cnt);
+	  if (!p)
+	    return ENOMEM;
+	  memcpy (p, buf, cnt);
+	  _nullstream_free_pattern (np);
+	  np->pattern = p;
+	  np->patsize = cnt;
+	}
+      break;
+	  
+    case MU_IOCTL_NULLSTREAM_SETSIZE:
+      if (!arg)
+	return EINVAL;
+      else
+	return _nullstream_truncate (str, *(mu_off_t*)arg);
+      break;
+
+    case MU_IOCTL_NULLSTREAM_CLRSIZE:
+      np->mode &= ~MU_NULLSTREAM_SIZE;
+      np->base.size = NULL;
+      break;
+      
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
+
+int
+mu_nullstream_create (mu_stream_t *pref, int flags)
+{
+  struct _mu_nullstream *np;
+
+  np = (struct _mu_nullstream *)
+         _mu_stream_create (sizeof (*np),
+			    flags | MU_STREAM_SEEK | _MU_STR_OPEN);
+  if (!np)
+    return ENOMEM;
+  np->base.read = _nullstream_read; 
+  np->base.write = _nullstream_write;
+  np->base.seek = _nullstream_seek; 
+  np->base.ctl = _nullstream_ctl;
+  np->base.truncate = _nullstream_truncate;
+  np->base.done = _nullstream_done;
+
+  np->pattern = "";
+  np->patsize = 0;
+  np->mode = MU_NULLSTREAM_PATSTAT;
+  
+  *pref = (mu_stream_t) np;
+
+  mu_stream_set_buffer (*pref, mu_buffer_full, 0);
+  return 0;
+}
diff --git a/libmailutils/stream/stream.c b/libmailutils/stream/stream.c
index 48ca32b..f8834c1 100644
--- a/libmailutils/stream/stream.c
+++ b/libmailutils/stream/stream.c
@@ -46,6 +46,19 @@ size_t mu_stream_default_buffer_size = MU_STREAM_DEFBUFSIZ;
     }								\
   while (0)
 
+#define _stream_stat_incr(s, k, n) \
+  (((s)->statmask & MU_STREAM_STAT_MASK(k)) ? ((s)->statbuf[k] += n) : 0)
+
+#define _stream_read(str, buf, size, rdbytes) \
+  (_stream_stat_incr ((str), MU_STREAM_STAT_READS, 1),  \
+   (str)->read (str, buf, size, rdbytes))
+#define _stream_write(str, buf, size, wrbytes) \
+  (_stream_stat_incr ((str), MU_STREAM_STAT_WRITES, 1),  \
+   (str)->write (str, buf, size, wrbytes))
+#define _stream_seek(str, pos, poff)			\
+  (_stream_stat_incr ((str), MU_STREAM_STAT_SEEKS, 1),		\
+   (str)->seek (str, pos, poff))
+
 static int _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size,
 				    int full_read, size_t *pnread);
 static int _stream_write_unbuffered (mu_stream_t stream,
@@ -180,7 +193,7 @@ _stream_flush_buffer (struct _mu_stream *stream, int flags)
       if ((stream->flags & MU_STREAM_SEEK) && stream->seek)
 	{
 	  mu_off_t off;
-	  rc = stream->seek (stream, stream->offset, &off);
+	  rc = _stream_seek (stream, stream->offset, &off);
 	  if (rc)
 	    return rc;
 	}
@@ -306,7 +319,9 @@ mu_stream_unref (mu_stream_t stream)
 static void
 _stream_init (mu_stream_t stream)
 {
-  stream->bytes_in = stream->bytes_out = 0;
+  if (stream->statmask)
+    memset (stream->statbuf, 0,
+	    _MU_STREAM_STAT_MAX * sizeof (stream->statbuf[0]));
   stream->flags &= ~_MU_STR_INTERN_MASK;
   _stream_setflag (stream, _MU_STR_OPEN);
   stream->offset = 0;
@@ -431,7 +446,7 @@ mu_stream_seek (mu_stream_t stream, mu_off_t offset, int whence,
 	return rc;
       if (stream->offset != offset)
 	{
-	  rc = stream->seek (stream, offset, &stream->offset);
+	  rc = _stream_seek (stream, offset, &stream->offset);
 	  if (rc == ESPIPE)
 	    return rc;
 	  if (rc)
@@ -602,7 +617,7 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size,
 
       nread = 0;
       while (size > 0
-	     && (rc = stream->read (stream, buf, size, &rdbytes)) == 0)
+	     && (rc = _stream_read (stream, buf, size, &rdbytes)) == 0)
 	{
 	  if (rdbytes == 0)
 	    {
@@ -612,19 +627,19 @@ _stream_read_unbuffered (mu_stream_t stream, void *buf, size_t size,
 	  buf += rdbytes;
 	  nread += rdbytes;
 	  size -= rdbytes;
-	  stream->bytes_in += rdbytes;
+	  _stream_stat_incr (stream, MU_STREAM_STAT_IN, rdbytes);
 	}
       if (size && rc)
 	rc = mu_stream_seterr (stream, rc, 0);
     }
   else
     {
-      rc = stream->read (stream, buf, size, &nread);
+      rc = _stream_read (stream, buf, size, &nread);
       if (rc == 0)
 	{
 	  if (nread == 0)
 	    _stream_setflag (stream, _MU_STR_EOF);
-	  stream->bytes_in += nread;
+	  _stream_stat_incr (stream, MU_STREAM_STAT_IN, nread);
 	}
       mu_stream_seterr (stream, rc, rc != 0);
     }
@@ -665,7 +680,7 @@ _stream_write_unbuffered (mu_stream_t stream,
 
       nwritten = 0;
       while (size > 0
-	     && (rc = stream->write (stream, bufp, size, &wrbytes))
+	     && (rc = _stream_write (stream, bufp, size, &wrbytes))
 	     == 0)
 	{
 	  if (wrbytes == 0)
@@ -676,14 +691,14 @@ _stream_write_unbuffered (mu_stream_t stream,
 	  bufp += wrbytes;
 	  nwritten += wrbytes;
 	  size -= wrbytes;
-	  stream->bytes_out += wrbytes;
+	  _stream_stat_incr (stream, MU_STREAM_STAT_OUT, wrbytes);
 	}
     }
   else
     {
-      rc = stream->write (stream, buf, size, &nwritten);
+      rc = _stream_write (stream, buf, size, &nwritten);
       if (rc == 0)
-	stream->bytes_out += nwritten;
+	_stream_stat_incr (stream, MU_STREAM_STAT_OUT, nwritten);
     }
   _stream_setflag (stream, _MU_STR_WRT);
   if (pnwritten)
@@ -1101,18 +1116,6 @@ mu_stream_size (mu_stream_t stream, mu_off_t *psize)
   return mu_stream_seterr (stream, rc, rc != 0);
 }
 
-mu_off_t
-mu_stream_bytes_in (mu_stream_t stream)
-{
-  return stream->bytes_in;
-}
-
-mu_off_t
-mu_stream_bytes_out (mu_stream_t stream)
-{
-  return stream->bytes_out;
-}
-
 int
 mu_stream_ioctl (mu_stream_t stream, int code, void *ptr)
 {
@@ -1215,3 +1218,27 @@ mu_stream_clr_flags (mu_stream_t stream, int fl)
   return 0;
 }
 
+int
+mu_stream_set_stat (mu_stream_t stream, int statmask,
+		    mu_stream_stat_buffer statbuf)
+{
+  if (stream == NULL)
+    return EINVAL;
+  stream->statmask = statmask;
+  stream->statbuf = statbuf;
+  memset (stream->statbuf, 0,
+	  _MU_STREAM_STAT_MAX * sizeof (stream->statbuf[0]));
+  return 0;
+}
+
+int
+mu_stream_get_stat (mu_stream_t stream, int *pstatmask,
+		    mu_off_t **pstatbuf)
+{
+  if (stream == NULL)
+    return EINVAL;
+  *pstatmask = stream->statmask;
+  *pstatbuf = stream->statbuf;
+  return 0;
+}
+  
diff --git a/libmailutils/tests/fltst.c b/libmailutils/tests/fltst.c
index e5c0ae1..cc72f2d 100644
--- a/libmailutils/tests/fltst.c
+++ b/libmailutils/tests/fltst.c
@@ -29,10 +29,21 @@
 
 int verbose = 0;
 int printable = 0;
+mu_stream_stat_buffer instat, outstat;
 
 static void
 c_copy (mu_stream_t out, mu_stream_t in)
 {
+  if (verbose)
+    {
+      mu_stream_set_stat (in,
+			  MU_STREAM_STAT_MASK_ALL,
+			  instat);
+      mu_stream_set_stat (out,
+			  MU_STREAM_STAT_MASK_ALL,
+			  outstat);
+    }
+  
   if (printable)
     {
       char c;
@@ -55,11 +66,6 @@ c_copy (mu_stream_t out, mu_stream_t in)
   else
     MU_ASSERT (mu_stream_copy (out, in, 0, NULL));
 
-  if (verbose)
-    fprintf (stderr, "\ntotal: %lu/%lu bytes\n",
-	     (unsigned long) mu_stream_bytes_in (in),
-	     (unsigned long) mu_stream_bytes_out (out));
-  
 }
 
 /* Set the maximum line length for the filter NAME to LENGTH.
@@ -186,5 +192,28 @@ main (int argc, char * argv [])
   mu_stream_close (out);
   mu_stream_destroy (&out);
   
+  if (verbose)
+    {
+      fprintf (stderr, "\nInput stream stats:\n");
+      fprintf (stderr, "Bytes in: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_IN]);
+      fprintf (stderr, "Bytes out: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_OUT]);
+      fprintf (stderr, "Reads: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_READS]);
+      fprintf (stderr, "Seeks: %lu\n",
+	       (unsigned long) instat[MU_STREAM_STAT_SEEKS]);
+
+      fprintf (stderr, "\nOutput stream stats:\n");
+      fprintf (stderr, "Bytes in: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_IN]);
+      fprintf (stderr, "Bytes out: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_OUT]);
+      fprintf (stderr, "Writes: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_WRITES]);
+      fprintf (stderr, "Seeks: %lu\n",
+	       (unsigned long) outstat[MU_STREAM_STAT_SEEKS]);
+    }
+
   return 0;
 }
diff --git a/mh/mhn.c b/mh/mhn.c
index bc240cb..238761d 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -188,24 +188,10 @@ split_content (const char *content, char **type, char **subtype)
 }
 
 int
-_get_hdr_value (mu_header_t hdr, const char *name, char **value)
-{
-  int status = mu_header_aget_value (hdr, name, value);
-  if (status == 0)
-    {
-      /* Remove the newlines.  */
-      char *nl;
-      while ((nl = strchr (*value, '\n')) != NULL)
-	*nl = ' ';
-    }
-  return status;
-}
-
-int
 _get_content_type (mu_header_t hdr, char **value, char **rest)
 {
   char *type = NULL;
-  _get_hdr_value (hdr, MU_HEADER_CONTENT_TYPE, &type);
+  mu_header_aget_value_unfold (hdr, MU_HEADER_CONTENT_TYPE, &type);
   if (type == NULL || *type == '\0')
     {
       if (type)
@@ -230,7 +216,8 @@ static int
 _get_content_encoding (mu_header_t hdr, char **value)
 {
   char *encoding = NULL;
-  _get_hdr_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, &encoding);
+  mu_header_aget_value_unfold (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+			       &encoding);
   if (encoding == NULL || *encoding == '\0')
     {
       if (encoding)
@@ -406,7 +393,8 @@ opt_handler (int key, char *arg, struct argp_state *state)
 
 /* *********************** Message part functions ************************* */
 
-struct _msg_part {
+struct _msg_part
+{
   int level;
   int maxlevel;
   size_t *part;
@@ -1094,9 +1082,12 @@ handle_message (mu_message_t msg, msg_part_t part, msg_handler_t fun, void *data
 }
 
 int
-mhn_message_size (mu_message_t msg, size_t *psize)
+mhn_message_size (mu_message_t msg, mu_off_t *psize)
 {
+  int rc;
+  size_t size;
   mu_body_t body;
+  
   *psize = 0;
   mu_message_get_body (msg, &body);
   if (mode_options & OPT_REALSIZE)
@@ -1107,8 +1098,6 @@ mhn_message_size (mu_message_t msg, size_t *psize)
 	{
 	  mu_header_t hdr;
 	  char *encoding;
-	  size_t size = 0;
-	  int rc;
 	  
 	  mu_message_get_header (msg, &hdr);
 	  _get_content_encoding (hdr, &encoding);
@@ -1119,22 +1108,27 @@ mhn_message_size (mu_message_t msg, size_t *psize)
 	  free (encoding);
 	  if (rc == 0)
 	    {
-	      char buf[512];
-	      size_t n;
-
-	      while (mu_stream_read (dstr, buf, sizeof buf, &n) == 0
-		     && n > 0)
-		size += n;
-
+	      mu_stream_stat_buffer stat;
+	      mu_stream_t null;
+
+	      mu_nullstream_create (&null, MU_STREAM_WRITE);
+	      mu_stream_set_stat (null,
+				  MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUT),
+				  stat);
+	      mu_stream_copy (null, dstr, 0, NULL);
+	      mu_stream_destroy (&null);
 	      mu_stream_destroy (&dstr);
-	      *psize = size;
+	      *psize = stat[MU_STREAM_STAT_OUT];
 	      return 0;
 	    }
 	  mu_stream_destroy (&bstr);
 	}
     }
 
-  return mu_body_size (body, psize);
+  rc = mu_body_size (body, &size);
+  if (rc == 0)
+    *psize = size;
+  return rc;
 }
 
 
@@ -1144,7 +1138,7 @@ int
 list_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
 	      void *data)
 {
-  size_t size;
+  mu_off_t size;
   mu_header_t hdr;
   
   if (msg_part_level (part) == 0)
@@ -1161,9 +1155,9 @@ list_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
   if (size < 1024)
     printf (" %4lu", (unsigned long) size);
   else if (size < 1024*1024)
-    printf ("%4luK", (unsigned long) size / 1024);
+    printf ("%4luK", (unsigned long) (size + 1024 - 1) / 1024);
   else
-    printf ("%4luM", (unsigned long) size / 1024 / 1024);
+    printf ("%4luM", (unsigned long) (size + 1024*1024 - 1) / 1024 / 1024);
   
   if (mu_message_get_header (msg, &hdr) == 0)
     {
@@ -1360,7 +1354,7 @@ show_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
     {
       char *str;
       const char *p;
-      size_t size = 0;
+      mu_off_t size = 0;
 
       str = (char*) _("part ");
       mu_stream_write (out, str, strlen (str), NULL);
@@ -1662,7 +1656,8 @@ mhn_store ()
 
 /* ***************************** Compose Mode **************************** */
 
-struct compose_env {
+struct compose_env
+{
   mu_stream_t input;
   mu_mime_t mime;
   size_t line;
@@ -1881,20 +1876,13 @@ copy_header (mu_message_t msg, mu_header_t out)
   mu_header_get_field_count (hdr, &count);
   for (i = 1; i <= count; i++)
     {
-      char *name, *value;
+      const char *name, *value;
 
-      if (mu_header_aget_field_name (hdr, i, &name))
-        continue;
-
-      if (mu_header_aget_field_value (hdr, i, &value))
-	{
-          free (name);
-          continue;
-        }
+      if (mu_header_sget_field_name (hdr, i, &name) ||
+	  mu_header_sget_field_value (hdr, i, &value))
+	continue;
 
       mu_header_set_value (out, name, value, 0);
-      free (name);
-      free (value);
     }
 }
 
@@ -2216,7 +2204,8 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
   
   /* Create filter */
 
-  if (_get_hdr_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, &encoding))
+  if (mu_header_aget_value_unfold (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
+				   &encoding))
     {
       char *typestr, *type, *subtype;
       


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 10 18:22:20 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PGJzf-0002Qh-Vh
	for mharc-commit-mailutils@gnu.org; Wed, 10 Nov 2010 18:22:20 -0500
Received: from [140.186.70.92] (port=51160 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PGJzZ-0002Oq-8t
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 18:22:19 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGJzV-00015R-3u
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 18:22:13 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:37764
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGJzV-00015C-1M
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 18:22:09 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGJzU-00068g-MN
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 23:22:08 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGJzS-0008Ue-2R
	for commit-mailutils@gnu.org; Wed, 10 Nov 2010 23:22:08 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 50bf64db74ffa1d1cf1c5ebbda55cabdb530b8f5
X-Git-Newrev: 2662827ca1abe42442d14cc3cbf08d076b3ee1ab
Message-Id: <E1PGJzS-0008Ue-2R@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 10 Nov 2010 23:22:06 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-184-g2662827
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 10 Nov 2010 23:22:19 -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=2662827ca1abe42442d14cc3cbf08d076b3ee1ab

The branch, master has been updated
       via  2662827ca1abe42442d14cc3cbf08d076b3ee1ab (commit)
      from  50bf64db74ffa1d1cf1c5ebbda55cabdb530b8f5 (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 2662827ca1abe42442d14cc3cbf08d076b3ee1ab
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 10 22:40:41 2010 +0200

    Add MH testsuite.
    
    * configure.ac (mh/tests): New testdir
    * mh/Makefile.am (SUBDIRS): Add tests
    
    * tests/Makefile.am: New file.
    * mh/tests/Makefile.am: New file.
    * mh/tests/atlocal.in: New file.
    * mh/tests/folder.at: New file.
    * mh/tests/inc.at: New file.
    * mh/tests/mark.at: New file.
    * mh/tests/mhparam.at: New file.
    * mh/tests/mhpath.at: New file.
    * mh/tests/refile.at: New file.
    * mh/tests/rmf.at: New file.
    * mh/tests/rmm.at: New file.
    * mh/tests/scan.at: New file.
    * mh/tests/testsuite.at: New file.
    * mh/tests/.gitignore: New file.
    
    * testsuite/testsuite.inc (MUT_MBCOPY): Work correctly if
    DST is a directory name (for MH and maildir formats).
    
    * mh/folder.c (action_list): Treat empty value as
    equal to no value.
    * mh/install-mh.c (main): Honor MH environment variable.
    * mh/mh_ctx.c (mh_context_read, mh_context_write): Use MU streams
    instead of stdio FILE.
    (mh_context_iterate): Add error checking.
    Do not coredump on NULL header.
    * mh/mh_global.c (_mh_init_global_sequences): Destroy sequences.
    * mh/TODO: Update.
    
    * libmailutils/stream/message_stream.c (copy_trimmed_value): New
    static function.
    (scan_stream): Strip final newline from the saved envelope values.
    
    * mu/Makefile.am (BUILD_SOURCES, EXTRA_DIST): Add
    mu-setup.c and mu-setup.h.

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

Summary of changes:
 configure.ac                                |    5 +-
 libmailutils/stream/message_stream.c        |   28 ++++--
 mh/Makefile.am                              |    1 +
 mh/TODO                                     |    4 +-
 mh/folder.c                                 |    2 +-
 mh/install-mh.c                             |   17 ++-
 mh/mh_ctx.c                                 |  111 ++++++++++++--------
 mh/mh_global.c                              |    2 +-
 {frm => mh}/tests/.gitignore                |    0
 {frm => mh}/tests/Makefile.am               |   12 ++-
 {sieve => mh}/tests/atlocal.in              |    3 +-
 mh/tests/folder.at                          |  147 +++++++++++++++++++++++++++
 mh/tests/inc.at                             |   61 +++++++++++
 mh/tests/mark.at                            |  101 ++++++++++++++++++
 mh/tests/mhparam.at                         |   72 +++++++++++++
 mh/tests/mhpath.at                          |  110 ++++++++++++++++++++
 mh/tests/refile.at                          |   75 ++++++++++++++
 maidag/tests/url-mbox.at => mh/tests/rmf.at |   37 +++++---
 maidag/tests/url-mbox.at => mh/tests/rmm.at |   43 ++++++---
 mh/tests/scan.at                            |   82 +++++++++++++++
 {maidag => mh}/tests/testsuite.at           |   43 ++++++--
 mu/Makefile.am                              |    3 +
 testsuite/testsuite.inc                     |    8 +-
 23 files changed, 862 insertions(+), 105 deletions(-)
 copy {frm => mh}/tests/.gitignore (100%)
 copy {frm => mh}/tests/Makefile.am (94%)
 copy {sieve => mh}/tests/atlocal.in (73%)
 create mode 100644 mh/tests/folder.at
 create mode 100644 mh/tests/inc.at
 create mode 100644 mh/tests/mark.at
 create mode 100644 mh/tests/mhparam.at
 create mode 100644 mh/tests/mhpath.at
 create mode 100644 mh/tests/refile.at
 copy maidag/tests/url-mbox.at => mh/tests/rmf.at (54%)
 copy maidag/tests/url-mbox.at => mh/tests/rmm.at (52%)
 create mode 100644 mh/tests/scan.at
 copy {maidag => mh}/tests/testsuite.at (54%)

diff --git a/configure.ac b/configure.ac
index e20652d..67ddf6b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1217,6 +1217,7 @@ AC_CONFIG_TESTDIR(maidag/tests)
 AC_CONFIG_TESTDIR(messages/tests)
 AC_CONFIG_TESTDIR(readmsg/tests)
 AC_CONFIG_TESTDIR(sieve/tests)
+AC_CONFIG_TESTDIR(mh/tests)
 
 AC_CONFIG_FILES([libmailutils/tests/Makefile
                  libmailutils/tests/atlocal
@@ -1231,7 +1232,9 @@ AC_CONFIG_FILES([libmailutils/tests/Makefile
 		 readmsg/tests/Makefile
 		 readmsg/tests/atlocal
                  sieve/tests/Makefile
-                 sieve/tests/atlocal]) 
+                 sieve/tests/atlocal
+		 mh/tests/Makefile
+		 mh/tests/atlocal]) 
 AM_MISSING_PROG([AUTOM4TE], [autom4te])
 
 dnl Make sysconfdir available to the application
diff --git a/libmailutils/stream/message_stream.c b/libmailutils/stream/message_stream.c
index a404ccd..dfa8b70 100644
--- a/libmailutils/stream/message_stream.c
+++ b/libmailutils/stream/message_stream.c
@@ -129,6 +129,20 @@ _message_size (mu_stream_t stream, mu_off_t *psize)
     *psize -= s->envelope_length + s->mark_length;
   return rc;
 }
+
+static char *
+copy_trimmed_value (const char *str)
+{
+  char *p;
+  size_t len;
+  
+  str = mu_str_skip_class (str, MU_CTYPE_SPACE);
+  len = strlen (str) - 1;
+  p = malloc (len);
+  memcpy (p, str, len);
+  p[len] = 0;
+  return p;
+}
   
 static int
 scan_stream (struct _mu_message_stream *str)
@@ -180,21 +194,17 @@ scan_stream (struct _mu_message_stream *str)
       	  if (!from && mu_c_strncasecmp (buffer, MU_HEADER_FROM,
 				         sizeof (MU_HEADER_FROM) - 1) == 0)
 	    
-	    from = mu_strdup (mu_str_skip_class (buffer +
-						 sizeof (MU_HEADER_FROM),
-						 MU_CTYPE_SPACE));
+	    from = copy_trimmed_value (buffer + sizeof (MU_HEADER_FROM));
 	  else if (!env_from
 		   && mu_c_strncasecmp (buffer, MU_HEADER_ENV_SENDER,
 				        sizeof (MU_HEADER_ENV_SENDER) - 1) == 0)
-	    env_from = mu_strdup (mu_str_skip_class (buffer +
-					sizeof (MU_HEADER_ENV_SENDER),
-						     MU_CTYPE_SPACE));
+	    env_from = copy_trimmed_value (buffer +
+					   sizeof (MU_HEADER_ENV_SENDER));
 	  else if (!env_date
 		   && mu_c_strncasecmp (buffer, MU_HEADER_ENV_DATE,
 				        sizeof (MU_HEADER_ENV_DATE) - 1) == 0)
-	    env_date = mu_strdup (mu_str_skip_class (buffer +
-						  sizeof (MU_HEADER_ENV_DATE),
-						     MU_CTYPE_SPACE));
+	    env_date = copy_trimmed_value (buffer +
+					   sizeof (MU_HEADER_ENV_DATE));
 	}
     }
 
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 2cceef0..2c52f55 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -15,6 +15,7 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
+SUBDIRS = . tests
 bindir = @MH_BIN_DIR@
 mhlibdir = $(pkgdatadir)/mh
 bin_PROGRAMS = \
diff --git a/mh/TODO b/mh/TODO
index d58b4da..8dfe2c6 100644
--- a/mh/TODO
+++ b/mh/TODO
@@ -24,7 +24,7 @@ State	Nice	Utility		Comments
 *	-20	forw		--inplace,--whatnowproc
 *	-20	send		--alias,--filter,--format,--forward,--mime,
 				--width
-*	-20	refile		--link copies messages.
+*	-20	refile		--link copies messages; rmmproc ignored.
 *	-20	rmm		rmproc:	
 +	-15	folder(s)	
 +	-15	mhn		
@@ -34,7 +34,7 @@ State	Nice	Utility		Comments
 				center,split,datefield
 +	5	mark
 +	5	pick		See the README entry.
-+	10	anno
++	10	anno            -inplace
 +	10	burst		See the README entry.
 *	10	whom		--check 
 +	10	mhpath
diff --git a/mh/folder.c b/mh/folder.c
index 5dba885..2b8f04e 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -506,7 +506,7 @@ action_list ()
   const char *stack = mh_global_context_get ("Folder-Stack", NULL);
 
   printf ("%s", mh_current_folder ());
-  if (stack)
+  if (stack && stack[0])
     printf (" %s", stack);
   printf ("\n");
   return 0;
diff --git a/mh/install-mh.c b/mh/install-mh.c
index 4bf3cff..5b48244 100644
--- a/mh/install-mh.c
+++ b/mh/install-mh.c
@@ -57,7 +57,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
 int
 main (int argc, char **argv)
 {
-  char *home, *name;
+  char *name;
   extern int mh_auto_install;
   
   /* Native Language Support */
@@ -68,10 +68,17 @@ main (int argc, char **argv)
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, NULL);
 
-  home = mu_get_homedir ();
-  if (!home)
-    abort (); /* shouldn't happen */
-  name = mh_safe_make_file_name (home, MH_USER_PROFILE);
+  name = getenv ("MH");
+  if (name)
+    name = mu_tilde_expansion (name, "/", NULL);
+  else
+    {
+      char *home = mu_get_homedir ();
+      if (!home)
+	abort (); /* shouldn't happen */
+      name = mh_safe_make_file_name (home, MH_USER_PROFILE);
+      free (home);
+    }
   mh_install (name, automode);
   return 0;
 }
diff --git a/mh/mh_ctx.c b/mh/mh_ctx.c
index 33a1069..ca497f2 100644
--- a/mh/mh_ctx.c
+++ b/mh/mh_ctx.c
@@ -80,80 +80,81 @@ mh_context_merge (mh_context_t *dst, mh_context_t *src)
 int 
 mh_context_read (mh_context_t *ctx)
 {
-  int status;
+  int rc;
   char *blurb, *p;
-  struct stat st;
-  FILE *fp;
+  mu_stream_t stream;
+  mu_off_t stream_size;
   char *buf = NULL;
-  size_t size = 0;
+  size_t size = 0, n;
   
   if (!ctx)
     return MU_ERR_OUT_NULL;
   
-  if (stat (ctx->name, &st))
-    return errno;
+  rc = mu_file_stream_create (&stream, ctx->name, MU_STREAM_READ);
+  if (rc)
+    return rc;
 
-  blurb = malloc (st.st_size);
-  if (!blurb)
-    return ENOMEM;
-  
-  fp = fopen (ctx->name, "r");
-  if (!fp)
+  rc = mu_stream_size (stream, &stream_size);
+  if (rc)
     {
-      free (blurb);
-      return errno;
+      mu_stream_destroy (&stream);
+      return rc;
     }
 
+  blurb = malloc (stream_size + 1);
+  if (!blurb)
+    {
+      mu_stream_destroy (&stream);
+      return ENOMEM;
+    }
+  
   p = blurb;
-  while (getline (&buf, &size, fp) > 0)
+  while (mu_stream_getline (stream, &buf, &size, &n) == 0 && n > 0)
     {
-      char *q;
-
-      for (q = buf; *q && mu_isspace (*q); q++)
-	;
+      char *q = mu_str_skip_class (buf, MU_CTYPE_SPACE);
       if (!*q || *q == '#')
 	continue;
-      
       for (q = buf; *q;)
 	*p++ = *q++;
     }
-  fclose (fp);
-
-  status = mu_header_create (&ctx->header, blurb, p - blurb);
+  mu_stream_destroy (&stream);
+  rc = mu_header_create (&ctx->header, blurb, p - blurb);
   free (blurb);
 
-  return status;
+  return rc;
 }
 
 int 
 mh_context_write (mh_context_t *ctx)
 {
-  mu_stream_t stream;
-  char buffer[512];
-  size_t n;
-  FILE *fp;
+  int rc;
+  mu_stream_t instream, outstream;
+  mu_off_t size;
   
   if (!ctx)
     return MU_ERR_OUT_NULL;
 
-  fp = fopen (ctx->name, "w");
-  if (!fp)
+  rc = mu_file_stream_create (&outstream, ctx->name,
+			      MU_STREAM_WRITE|MU_STREAM_CREAT);
+  if (rc)
     {
-      mu_error (_("cannot open context file %s: %s"),
-		ctx->name, strerror (errno));
+      mu_error (_("cannot open context file %s for writing: %s"),
+		ctx->name, mu_strerror (rc));
       return MU_ERR_FAILURE;
     }
-
-  /* FIXME: Use mu_stream+copy */
-  mu_header_get_streamref (ctx->header, &stream);
-  while (mu_stream_read (stream, buffer, sizeof buffer - 1, &n) == 0
-	 && n != 0)
+  
+  mu_header_get_streamref (ctx->header, &instream);
+  rc = mu_stream_copy (outstream, instream, 0, &size);
+  if (rc)
     {
-      buffer[n] = '\0';
-      fprintf (fp, "%s", buffer);
+      mu_error (_("error writing to context file %s: %s"),
+		ctx->name, mu_strerror (rc));
+      return MU_ERR_FAILURE;
     }
-  mu_stream_destroy (&stream);
-  fclose (fp);
+  else
+    rc = mu_stream_truncate (outstream, size);
+  mu_stream_destroy (&instream);
+  mu_stream_destroy (&outstream);
   return 0;
 }
 
@@ -194,13 +195,35 @@ mh_context_iterate (mh_context_t *ctx, mh_context_iterator fp, void *data)
   
   if (!ctx)
     return EINVAL;
-  mu_header_get_field_count (ctx->header, &nfields);
+  if (!ctx->header)
+    return 0;
+  rc = mu_header_get_field_count (ctx->header, &nfields);
+  if (rc)
+    {
+      mu_error (_("cannot obtain field count for context %s"), ctx->name);
+      return rc;
+    }
+  
   for (i = 1; i <= nfields && rc == 0; i++)
     {
       const char *name, *value;
       
-      mu_header_sget_field_name (ctx->header, i, &name);
-      mu_header_sget_field_value (ctx->header, i, &value);
+      rc = mu_header_sget_field_name (ctx->header, i, &name);
+      if (rc)
+	{
+	  mu_error (_("cannot obtain field name for context %s:%d: %s"),
+		    ctx->name,i,mu_strerror (rc));
+	  break;
+	}
+      
+      rc = mu_header_sget_field_value (ctx->header, i, &value);
+      if (rc)
+	{
+	  mu_error (_("cannot obtain field value for context %s:%d: %s"),
+		    ctx->name,i,mu_strerror (rc));
+	  break;
+	}
+      
       rc = fp (name, value, data);
     }
 
diff --git a/mh/mh_global.c b/mh/mh_global.c
index 06b4417..25873dd 100644
--- a/mh/mh_global.c
+++ b/mh/mh_global.c
@@ -163,7 +163,7 @@ _mh_init_global_sequences ()
 void
 mh_global_sequences_drop ()
 {
-  sequences = NULL;
+  mh_context_destroy (&sequences);
 }
 
 const char *
diff --git a/frm/tests/.gitignore b/mh/tests/.gitignore
similarity index 100%
copy from frm/tests/.gitignore
copy to mh/tests/.gitignore
diff --git a/frm/tests/Makefile.am b/mh/tests/Makefile.am
similarity index 94%
copy from frm/tests/Makefile.am
copy to mh/tests/Makefile.am
index d587c2f..26be1c7 100644
--- a/frm/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -38,7 +38,17 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
 ## Test suite.  ##
 ## ------------ ##
 
-TESTSUITE_AT = testsuite.at
+TESTSUITE_AT = \
+ folder.at\
+ inc.at\
+ mark.at\
+ mhparam.at\
+ mhpath.at\
+ scan.at\
+ refile.at\
+ rmf.at\
+ rmm.at\
+ testsuite.at
 
 TESTSUITE = $(srcdir)/testsuite
 M4=m4
diff --git a/sieve/tests/atlocal.in b/mh/tests/atlocal.in
similarity index 73%
copy from sieve/tests/atlocal.in
copy to mh/tests/atlocal.in
index a50bc9c..66fb14c 100644
--- a/sieve/tests/atlocal.in
+++ b/mh/tests/atlocal.in
@@ -2,4 +2,5 @@
 # Configurable variable values for Mailutils test suite.
 # Copyright (C) 2004, 2010 Free Software Foundation, Inc.
 
-PATH=@abs_builddir@:@abs_top_builddir@/sieve:$top_srcdir:$srcdir:$PATH
+PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
+  
\ No newline at end of file
diff --git a/mh/tests/folder.at b/mh/tests/folder.at
new file mode 100644
index 0000000..c7d1d70
--- /dev/null
+++ b/mh/tests/folder.at
@@ -0,0 +1,147 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[folder])
+
+MH_CHECK([folder],[folder00 folder-print],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: inbox' > Mail/context
+folder
+],
+[0],
+[                 inbox+ has    5 messages (   1-   5).
+])
+
+MH_CHECK([folder -all],[folder01 folder-all],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: inbox' > Mail/context
+folder -all
+],
+[0],
+[dnl
+Folder                  # of messages     (  range  )  cur msg   (other files)
+                 inbox+ has    5 messages (   1-   5).
+              teaparty  has   95 messages (   1-  95).
+
+                   TOTAL= 100 messages in    2 folders
+])
+
+MH_CHECK([folder -all -fast],[folder02 folder-all folder-all-fast],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: inbox' > Mail/context
+folder -all -fast
+],
+[0],
+[inbox
+teaparty
+])
+
+MH_CHECK([folder +mbox],[folder03 folder+mbox],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: inbox' > Mail/context
+folder +teaparty
+sed -n 's/^\(Current-Folder\): *\(.*\)/\1: \2/p' Mail/context
+],
+[0],
+[dnl
+              teaparty+ has   95 messages (   1-  95).
+Current-Folder: teaparty	      
+])
+
+MH_CHECK([folder +mbox msg],[folder04 folder+mbox_msg],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: inbox' > Mail/context
+folder +teaparty 35
+sed -n 's/^\(Current-Folder\): *\(.*\)/context: \1: \2/p' Mail/context
+sed -n 's/^\(cur\): *\(.*\)/mh_sequences: \1: \2/p' Mail/teaparty/.mh_sequences
+],
+[0],
+[dnl
+              teaparty+ has   95 messages (   1-  95); cur=  35.
+context: Current-Folder: teaparty
+mh_sequences: cur: 35
+])
+
+MH_CHECK([folder -pack],[folder05 folder-pack],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+for i in 2 3 4 5
+do
+  mv Mail/inbox/$i Mail/inbox/${i}0
+done
+folder -pack || exit $?
+find Mail/inbox
+],
+[0],
+[Mail/inbox
+Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/4
+Mail/inbox/5
+Mail/inbox/.mh_sequences
+])
+
+MH_CHECK([folder --pack=N],[folder06 folder--pack=N],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+for i in 1 2 3 4 5
+do
+  mv Mail/inbox/$i Mail/inbox/${i}0
+done
+folder --pack=1 || exit $?
+find Mail/inbox
+],
+[0],
+[Mail/inbox
+Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/4
+Mail/inbox/5
+Mail/inbox/.mh_sequences
+])
+
+MH_CHECK([folder -push/-pop],[folder07 folder-push folder-pop folder-push-pop],
+[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+folder -push +teaparty
+folder -pop
+folder -push +teaparty
+folder -push
+folder -pop
+],
+[0],
+[teaparty inbox
+inbox
+teaparty inbox
+inbox teaparty
+teaparty
+])
+
+MH_CHECK([folder -create],[folder08 folder-create],[
+folder -create +new
+],
+[0],
+[                   new+ has no messages.
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of folder.at
diff --git a/mh/tests/inc.at b/mh/tests/inc.at
new file mode 100644
index 0000000..46b90a4
--- /dev/null
+++ b/mh/tests/inc.at
@@ -0,0 +1,61 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[inc])
+
+MH_CHECK([inc -notruncate],[inc00 inc-notruncate],[
+MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
+inc -notruncate -file ./mbox1 | sed 's/ *$//'
+cmp $abs_top_srcdir/testsuite/spool/mbox1 mbox1
+],
+[0],
+[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+])
+
+MH_CHECK([inc -truncate],[inc01 inc-truncate],[
+MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
+inc -truncate -file ./mbox1 | sed 's/ *$//'
+echo "Next"
+inc -truncate -file ./mbox1 | sed 's/ *$//'
+],
+[0],
+[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+Next    
+])
+
+MH_CHECK([inc -folder],[inc02 inc-folder],[
+MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
+mkdir Mail/new
+inc +new -file ./mbox1 | sed 's/ *$//'
+],
+[0],
+[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of inc.at
diff --git a/mh/tests/mark.at b/mh/tests/mark.at
new file mode 100644
index 0000000..65af674
--- /dev/null
+++ b/mh/tests/mark.at
@@ -0,0 +1,101 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[mark])
+
+MH_CHECK([mark -add],[mark00 mark-add],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+mark -sequence andro -add 2
+mark -sequence andro -add 3-5
+sed -n '/^andro:/{s/  */ /g;s/ $//;p}' Mail/inbox/.mh_sequences
+],
+[0],
+[andro: 2 3 4 5
+])
+
+MH_CHECK([mark -add -zero],[mark01 mark-add-zero],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+mark -sequence andro -add 2
+sed -n '/^andro:/{s/  */ /g;s/ $//;p}' Mail/inbox/.mh_sequences
+mark -zero -sequence andro -add 1 3
+sed -n '/^andro:/{s/  */ /g;s/ $//;p}' Mail/inbox/.mh_sequences
+],
+[0],
+[andro: 2
+andro: 1 3
+])
+
+MH_CHECK([mark -add -nopublic],[mark02 mark-add-nopublic],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+mark -nopublic -sequence andro -add 1 2 3
+dir=`pwd`
+sed -n '/^atr-andro/{s/  */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p}' Mail/context
+],
+[0],
+[atr-andro: 1 2 3
+])
+
+MH_CHECK([mark -del],[mark03 mark-del],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+echo 'andro: 2 3 4 5' > Mail/inbox/.mh_sequences
+mark -sequence andro -del 3
+sed -n '/^andro:/{s/  */ /g;s/ $//;p}' Mail/inbox/.mh_sequences
+],
+[0],
+[andro: 2 4 5
+])
+
+MH_CHECK([mark -del -nopublic],[mark04 mark-del-nopublic],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+inbox=`pwd`/Mail/inbox
+cat > Mail/context <<EOT
+atr-andro-$inbox: 2 3 4 5
+EOT
+mark -nopublic -sequence andro -del 3
+sed -n '/^atr-andro/{s/  */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p}' Mail/context
+],
+[0],
+[atr-andro: 2 4 5
+])
+
+MH_CHECK([mark -list],[mark05 mark-list],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+inbox=`pwd`/Mail/inbox
+cat > Mail/context <<EOT
+atr-andro-$inbox: 2 3
+EOT
+cat > Mail/inbox/.mh_sequences <<EOT
+cur: 1
+andro: 1 5
+gwerz: 4
+EOT
+mark -list
+],
+[0],
+[cur: 1
+andro: 1 5
+gwerz: 4
+andro (private): 2 3
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of mark.at
diff --git a/mh/tests/mhparam.at b/mh/tests/mhparam.at
new file mode 100644
index 0000000..5e03fb2
--- /dev/null
+++ b/mh/tests/mhparam.at
@@ -0,0 +1,72 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[mhparam])
+
+MH_CHECK([mhparam -all],[mhparam00 mhparam-all],[
+cat >>$MH <<EOT
+Sequence-Negation: not
+Draft-Folder: Mail/drafts
+Aliasfile: .mh_aliases
+EOT
+mhparam -all | tr '\t' ' ' | sed 's/^Path:.*/Path: Mail/;s/  */ /g'
+],
+[0],
+[Path: Mail
+Sequence-Negation: not
+Draft-Folder: Mail/drafts
+Aliasfile: .mh_aliases
+])
+
+MH_CHECK([mhparam comp],[mhparam01 mhparam_comp],[
+cat >>$MH <<EOT
+Sequence-Negation: not
+Draft-Folder: Mail/drafts
+Aliasfile: .mh_aliases
+EOT
+mhparam Sequence-Negation
+],
+[0],
+[not
+])
+
+MH_CHECK([mhparam comp comp],[mhparam02 mhparam_comp_comp],[
+cat >>$MH <<EOT
+Sequence-Negation: not
+Draft-Folder: Mail/drafts
+Aliasfile: .mh_aliases
+EOT
+mhparam Sequence-Negation Aliasfile | tr '\t' ' '
+],
+[0],
+[Sequence-Negation: not
+Aliasfile: .mh_aliases
+])
+
+MH_CHECK([mhparam -component comp],[mhparam03 mhparam-component_comp],[
+cat >>$MH <<EOT
+Sequence-Negation: not
+Draft-Folder: Mail/drafts
+Aliasfile: .mh_aliases
+EOT
+mhparam -component Sequence-Negation | tr '\t' ' ' | sed 's/  */ /g'
+],
+[0],
+[Sequence-Negation: not
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of mhparam.at
diff --git a/mh/tests/mhpath.at b/mh/tests/mhpath.at
new file mode 100644
index 0000000..45cef81
--- /dev/null
+++ b/mh/tests/mhpath.at
@@ -0,0 +1,110 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[mhpath])
+
+MH_CHECK([mhpath],[mhpath00],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+mhpath | sed 's|^'"$dir"'/||'
+],
+[0],
+[Mail/inbox
+])
+
+MH_CHECK([mhpath +],[mhpath01 mhpath+],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+mhpath +| sed 's|^'"$dir"'/||'
+],
+[0],
+[Mail
+])
+
+MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+dir=`pwd`
+mhpath 1-3 | sed 's|^'"$dir"'/||'
+],
+[0],
+[Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+])
+
+MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+dir=`pwd`
+mhpath 4-10 | sed 's|^'"$dir"'/||'
+],
+[0],
+[Mail/inbox/4
+Mail/inbox/5
+])
+
+MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+dir=`pwd`
+mhpath 8-10 | sed 's|^'"$dir"'/||'
+],
+[0],
+[],
+[mhpath: no messages in range 8-10
+])
+
+# FIXME: This test is dubious:
+#  1. Both MH and nmh manuals claim that:
+#
+#      2) Within a message list, the following designations may refer to  mes-
+#         sages that do not exist: a single numeric message name[...]
+#
+#     However, neither mhpath implementation follows this claim.  Should we?
+#  2. If a single non-existent message number is given, both MH and nmh
+#     implementations of mhpath produce the following error message:
+#
+#      mhpath: message N out of range X-Y
+#
+#     The diagnostics produced by my implementation differs.  This should
+#     be fixed, all the more that:
+#  3. The rest of utilities, when given a single non-existent message number,
+#     produce the following error message:
+#      
+#      folder: message N doesn't exist
+#
+#     Note the contracted negation, in place of a full one in MU diagnostics.
+#
+
+MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+dir=`pwd`
+mhpath 10 | sed 's|^'"$dir"'/||'
+],
+[0],
+[],
+[mhpath: message 10 does not exist
+])
+
+MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+dir=`pwd`
+mhpath new | sed 's|^'"$dir"'/||'
+],
+[0],
+[Mail/inbox/6
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of mhpath.at
diff --git a/mh/tests/refile.at b/mh/tests/refile.at
new file mode 100644
index 0000000..2fee41f
--- /dev/null
+++ b/mh/tests/refile.at
@@ -0,0 +1,75 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[refile])
+
+MH_CHECK([refile],[refile00],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/teaparty])
+echo 'Current-Folder: teaparty' > Mail/context
+refile 3 4 +inbox || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+cmp Mail/inbox/6 Mail/teaparty/,3 >/dev/null || echo "Message 3 differs"
+cmp Mail/inbox/7 Mail/teaparty/,4 >/dev/null || echo "Message 4 differs"
+],
+[0],
+[Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/4
+Mail/inbox/5
+Mail/inbox/6
+Mail/inbox/7
+])
+
+MH_CHECK([refile -file],[refile01 refile-file],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+cp Mail/inbox/2 message
+refile -file `pwd`/message +inbox || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+cmp Mail/inbox/2 Mail/inbox/6 >/dev/null || echo "Message differs"
+],
+[0],
+[Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/4
+Mail/inbox/5
+Mail/inbox/6
+])
+
+MH_CHECK([refile --copy],[refile02 refile--copy],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/teaparty])
+echo 'Current-Folder: teaparty' > Mail/context
+refile --copy 3 4 +inbox || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+cmp Mail/inbox/6 Mail/teaparty/3 >/dev/null || echo "Message 3 differs"
+cmp Mail/inbox/7 Mail/teaparty/4 >/dev/null || echo "Message 4 differs"
+],
+[0],
+[Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/4
+Mail/inbox/5
+Mail/inbox/6
+Mail/inbox/7
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of refile.at
diff --git a/maidag/tests/url-mbox.at b/mh/tests/rmf.at
similarity index 54%
copy from maidag/tests/url-mbox.at
copy to mh/tests/rmf.at
index dd29ab4..7b0b37a 100644
--- a/maidag/tests/url-mbox.at
+++ b/mh/tests/rmf.at
@@ -14,21 +14,32 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([URL mode])
-AT_KEYWORDS([maidag url-mbox url])
+m4_pushdef[MH_KEYWORDS],[rmm])
 
-AT_CHECK([
-echo ENVELOPE > expout
-cat $abs_top_srcdir/maidag/tests/input.msg >> expout
-echo "" >> expout
-mkdir spool
+MH_CHECK([rmf +folder],[rmf00 rmf+folder],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: inbox' > Mail/context
+rmf +teaparty || exit $?
+find Mail -type d
+],
+[0],
+[Mail
+Mail/inbox
+])
 
-maidag MAIDAG_OPTIONS --from 'gulliver@example.net' --url mbox:spool/out < dnl
- $abs_top_srcdir/maidag/tests/input.msg || exit $?
-sed '1s/From gulliver@example.net.*/ENVELOPE/' spool/out
+MH_CHECK([rmf],[rmf01 rmf_cur],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail])
+echo 'Current-Folder: teaparty' > Mail/context
+rmf || exit $?
+find Mail -type d
 ],
 [0],
-[expout])
+[[[+inbox now current]]
+Mail
+Mail/inbox
+])
 
-AT_CLEANUP
- 
\ No newline at end of file
+m4_popdef[MH_KEYWORDS])
+# End of rmf.at
diff --git a/maidag/tests/url-mbox.at b/mh/tests/rmm.at
similarity index 52%
copy from maidag/tests/url-mbox.at
copy to mh/tests/rmm.at
index dd29ab4..52ece5b 100644
--- a/maidag/tests/url-mbox.at
+++ b/mh/tests/rmm.at
@@ -14,21 +14,38 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([URL mode])
-AT_KEYWORDS([maidag url-mbox url])
+m4_pushdef[MH_KEYWORDS],[rmm])
 
-AT_CHECK([
-echo ENVELOPE > expout
-cat $abs_top_srcdir/maidag/tests/input.msg >> expout
-echo "" >> expout
-mkdir spool
+MH_CHECK([rmm msg],[rmm00 rmm-msg],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+rmm 4 || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+],
+[0],
+[Mail/inbox/1
+Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/5
+])
 
-maidag MAIDAG_OPTIONS --from 'gulliver@example.net' --url mbox:spool/out < dnl
- $abs_top_srcdir/maidag/tests/input.msg || exit $?
-sed '1s/From gulliver@example.net.*/ENVELOPE/' spool/out
+MH_CHECK([rmm seq],[rmm01 rmm-seq],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo 'Current-Folder: inbox' > Mail/context
+cat > Mail/inbox/.mh_sequences <<EOT
+test: 2 3 5 
+cur: 1
+EOT
+rmm test || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+sed '/^$/d' Mail/inbox/.mh_sequences
 ],
 [0],
-[expout])
+[Mail/inbox/1
+Mail/inbox/4
+test: 2 3 5 
+cur: 1
+])
 
-AT_CLEANUP
- 
\ No newline at end of file
+m4_popdef[MH_KEYWORDS])
+# End of rmm.at
diff --git a/mh/tests/scan.at b/mh/tests/scan.at
new file mode 100644
index 0000000..f62c0c6
--- /dev/null
+++ b/mh/tests/scan.at
@@ -0,0 +1,82 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[scan])
+
+MH_CHECK([scan],[scan00],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+scan | sed 's/ *$//'
+],
+[0],
+[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+])
+
+MH_CHECK([scan -folder],[scan01 scan-folder],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+scan +inbox | sed 's/ *$//'
+],
+[0],
+[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+])
+
+MH_CHECK([scan -format],[scan02 scan-format],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+scan +mbox1 -format '%4(msg) %(decode(friendly{from})) - %(decode(friendly{to}))'
+],
+[0],
+[   1 Foo Bar <foobar@nonexistent.net> - Bar <bar@dontmailme.org>
+   2 Bar <bar@dontmailme.org> - Foo Bar <foobar@nonexistent.net>
+   3 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+   4 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+   5 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+])
+
+MH_CHECK([scan -form],[scan03 scan-form],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+echo '%4(msg) %(decode(friendly{from})) - %(decode(friendly{to}))' > formfile
+scan +mbox1 -form formfile
+],
+[0],
+[   1 Foo Bar <foobar@nonexistent.net> - Bar <bar@dontmailme.org>
+   2 Bar <bar@dontmailme.org> - Foo Bar <foobar@nonexistent.net>
+   3 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+   4 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+   5 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+])
+
+MH_CHECK([scan -reverse],[scan04 scan-reverse],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+scan +mbox1 -reverse | sed 's/ *$//'
+],
+[0],
+[   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+   4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of scan.at
diff --git a/maidag/tests/testsuite.at b/mh/tests/testsuite.at
similarity index 54%
copy from maidag/tests/testsuite.at
copy to mh/tests/testsuite.at
index cb8ff4f..b992930 100644
--- a/maidag/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -16,18 +16,37 @@
 
 m4_include([testsuite.inc])
 
-m4_define([MAIDAG_OPTIONS],[dnl
---no-site-config dnl
---no-user-config dnl
---set '|mailbox|mailbox-pattern='`pwd`/spool/'${user}' dnl
---set .auth.authorization=system dnl
---stderr])
+m4_define([MH_SETUP],[
+test -d Mail || mkdir Mail
+dir=`pwd`
+MH=$dir/mh_profile
+export MH
+echo "Path: $dir/Mail" > $MH
+exec <&-
+])
+
+m4_define([MH_KEYWORDS])
+
+dnl --------------------------------------------------------------
+dnl MH_CHECK(DESCR, [KW = `'], COMMANDS, [STATUS = `0'],
+dnl          [STDOUT = `'], [STDERR = `']
+dnl
+m4_define([MH_CHECK],[
+AT_SETUP($1)
+AT_KEYWORDS(MH_KEYWORDS[ $2])
+MH_SETUP
+AT_CHECK([$3],[$4],[$5],[$6])
+AT_CLEANUP
+])
 
 AT_INIT
-AT_TESTED([maidag])
-MUT_VERSION(maidag)
-m4_include([mda.at])
-m4_include([lmtp.at])
-m4_include([url-mbox.at])
-m4_include([forward.at])
 
+m4_include([folder.at])
+m4_include([inc.at])
+m4_include([scan.at])
+m4_include([rmm.at])
+m4_include([rmf.at])
+m4_include([mark.at])
+m4_include([mhparam.at])
+m4_include([refile.at])
+m4_include([mhpath.at])
diff --git a/mu/Makefile.am b/mu/Makefile.am
index dfd2c44..7684892 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -78,6 +78,9 @@ AM_CPPFLAGS = \
   -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
   -DI18NLIBS="\"$(LIBINTL)\""
 
+BUILD_SOURCES=mu-setup.c mu-setup.h
+EXTRA_DIST=mu-setup.c mu-setup.h
+
 mu-setup.h: Makefile.am $(MODULES) $(IDLE_MODULES) 
 	$(AM_V_GEN)$(AWK) -f $(top_srcdir)/mu/mu-setup.awk -v mode=h \
            $(MODULES) $(IDLE_MODULES) > mu-setup.h
diff --git a/testsuite/testsuite.inc b/testsuite/testsuite.inc
index 363913f..8c4ab62 100644
--- a/testsuite/testsuite.inc
+++ b/testsuite/testsuite.inc
@@ -44,14 +44,18 @@ AT_CLEANUP
 ])
 
 dnl ------------------------------------------------------------
-dnl MUT_MBCOPY(SRC, DST)  -- Copy mailbox SRC to DST.
+dnl MUT_MBCOPY(SRC, [DST = `.'])  -- Copy mailbox SRC to DST.
 dnl 
 dnl
 m4_define([MUT_MBCOPY],[
 m4_pushdef([__dst],[m4_if([$2],,[.],[$2])])
 m4_pushdef([__basename],[m4_bregexp($1,[.*/\([^/]+\)$],\1)])
 cp -r $1 __dst
-chmod -R +w __dst/__basename
+if test -e __dst/__basename; then
+ chmod -R +w __dst/__basename
+else
+ chmod -R +w __dst
+fi
 m4_popdef([__basename])
 m4_popdef([__dst])
 ])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 11 08:33:20 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PGXHE-0005cW-I2
	for mharc-commit-mailutils@gnu.org; Thu, 11 Nov 2010 08:33:20 -0500
Received: from [140.186.70.92] (port=47011 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PGXH8-0005bz-0h
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 08:33:19 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGXH1-0007Ba-Fh
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 08:33:13 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:41288
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGXH1-0007BN-DW
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 08:33:07 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGXH0-0007cy-W5
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 13:33:07 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGXGv-000578-Mn
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 13:33:06 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 2662827ca1abe42442d14cc3cbf08d076b3ee1ab
X-Git-Newrev: c02201707fd4664252ba0e3fe93d3018ec816c89
Message-Id: <E1PGXGv-000578-Mn@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 11 Nov 2010 13:33:01 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-186-gc022017
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 11 Nov 2010 13:33:19 -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=c02201707fd4664252ba0e3fe93d3018ec816c89

The branch, master has been updated
       via  c02201707fd4664252ba0e3fe93d3018ec816c89 (commit)
       via  13c9419319e80c8c4967fa147ee910a5a8e7f3f1 (commit)
      from  2662827ca1abe42442d14cc3cbf08d076b3ee1ab (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 c02201707fd4664252ba0e3fe93d3018ec816c89
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 11 14:10:31 2010 +0200

    anno: Minor improvements.
    
    * mh/mh_init.c (mh_init): Make sure stdin is open.
    * mh/anno.c (main): Use mu_stream_t to read the answer from stdin.
    Do not display prompt if stdin is not connected to a tty.
    * mh/tests/anno.at: New testcase.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add anno.at
    * mh/tests/testsuite.at: Include anno.at.
    
    * doc/texinfo/mu-mh.texi: Document the changes in the behavior of anno.

commit 13c9419319e80c8c4967fa147ee910a5a8e7f3f1
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 11 11:56:49 2010 +0200

    mhl: Improve backward compatibility.  Provide a test case.
    
    Mhl now accepts the traditional use of "ignores=", i.e. as a single
    statement on a line and without double-quotes around the argument.
    
    Additional quotes around variable values are not needed in most
    cases.
    
    The name of a component is not printed if that component is not
    present.
    
    The offset variable works as in MH and nmh.
    
    * mh/mh_list.c (parse_variable): Accept traditional use of
    "ignores=", as a single statement on a line, without double-quotes around
    the argument.
    (mhl_format_compile): Use mu_streams instead of FILE.
    Fix line counting.
    (header_is_printed, want_header): Last argument is const char *.
    (ovf_print): Move to the specified offset no matter what the value
    of prefix is.
    (print_component_name): New function.
    (eval_component): Call print_component_name and newline, if necessary
    (eval_body): Likewise.
    (eval_extras): Likewise.
    (eval_comp): Do not print component name, leave that to the called
    function.  Ditto for the trailing newline.
    * mh/mhl.c: Ignore empty moreproc value.
    * mh/mhl.format: Remove extra double-quotes.
    
    * mh/tests/mhl.at: New testcase.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add mhl.at
    * mh/tests/testsuite.at: Include mhl.at
    
    * libmailutils/string/wordsplit.c (scan_qstring): Force _WSNF_EMPTYOK.
    (mu_wordsplit_len): Make sure the tail element is not joinable
    * libmailutils/tests/wordsplit.at: Test these changes.
    
    * doc/texinfo/mu-mh.texi: Update the description of mhl.

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

Summary of changes:
 doc/texinfo/mu-mh.texi                      |   34 ++++++-
 libmailutils/string/wordsplit.c             |    5 +-
 libmailutils/tests/wordsplit.at             |   16 +++-
 mh/anno.c                                   |   36 +++++++-
 mh/mh_init.c                                |   10 ++
 mh/mh_list.c                                |  128 +++++++++++++++------------
 mh/mhl.c                                    |    2 +-
 mh/mhl.format                               |    6 +-
 mh/tests/Makefile.am                        |    2 +
 mh/tests/anno.at                            |   62 +++++++++++++
 maidag/tests/url-mbox.at => mh/tests/mhl.at |   32 ++++---
 mh/tests/testsuite.at                       |    2 +
 12 files changed, 250 insertions(+), 85 deletions(-)
 create mode 100644 mh/tests/anno.at
 copy maidag/tests/url-mbox.at => mh/tests/mhl.at (60%)

diff --git a/doc/texinfo/mu-mh.texi b/doc/texinfo/mu-mh.texi
index f25f625..dc8567a 100644
--- a/doc/texinfo/mu-mh.texi
+++ b/doc/texinfo/mu-mh.texi
@@ -211,6 +211,16 @@ For more information, please see @xref{reply_regex function}.
 @subsubsection Differences in MH Program Behavior
 
 @table @command
+@item anno
+
+The prompt in interactive mode is @samp{Component name:}, instead
+of @samp{Enter component name:} displayed by the RAND @command{anno}.
+
+If a @option{-component field} is not specified and standard input
+is not connected to a terminal, @command{anno} does not display
+the prompt before reading the component from the standard input.
+RAND @command{anno} displays the prompt anyway.
+
 @item burst
 
 The utility is able to burst both RFC 934 digest messages and MIME
@@ -241,13 +251,29 @@ This command is not provided. Use @option{fmtcheck} instead.
 
 @item mhl
 
-If the argument to @code{ignores} contains more than one component name
-it must be enclosed in double-quotes. Dangling equal sign is an error,
-to set a string variable to the empty value assign it an empty string, e.g.:
-@code{overflowtext=""} (see the supplied @file{mhl.format} file).
+The @samp{ignores} keyword can be used in variable list.  In that
+case, if its value contains  more than one component name
+it must be enclosed in double-quotes, e.g.:
+
+@smallexample
+leftadjust,compwidth=9,"ignores=msgid,message-id,received"
+@end smallexample
+
+@noindent
+The above is equivalent to the following traditional notation:
+
+@smallexample
+leftadjust,compwidth=9
+ignores=msgid,message-id,received
+@end smallexample
+
+The @samp{MessageName} component is not yet implemented.
 
 Interactive prompting is not yet implemented.
 
+The following format variables are silently ignored: @samp{center},
+@samp{split}, @samp{datefield}.
+
 @item mhn
 
 @itemize @bullet
diff --git a/libmailutils/string/wordsplit.c b/libmailutils/string/wordsplit.c
index a7ed939..b5397ee 100644
--- a/libmailutils/string/wordsplit.c
+++ b/libmailutils/string/wordsplit.c
@@ -1028,7 +1028,7 @@ scan_qstring (struct mu_wordsplit *wsp, size_t start, size_t * end)
       j++;
   if (j < len && command[j] == q)
     {
-      int flags = _WSNF_QUOTE;
+      int flags = _WSNF_QUOTE|_WSNF_EMPTYOK;
       if (q == '\'')
 	flags |= _WSNF_NOEXPAND;
       if (mu_wordsplit_add_segm (wsp, start + 1, j, flags))
@@ -1355,6 +1355,9 @@ mu_wordsplit_len (const char *command, size_t len, struct mu_wordsplit *wsp,
     {
       while ((rc = scan_word (wsp, start)) == _MU_WRDS_OK)
 	start = skip_delim (wsp);
+      /* Make sure tail element is not joinable */
+      if (wsp->ws_tail)
+	wsp->ws_tail->flags &= ~_WSNF_JOIN;
     }
 
   if (wsp->ws_flags & MU_WRDSF_SHOWDBG)
diff --git a/libmailutils/tests/wordsplit.at b/libmailutils/tests/wordsplit.at
index 2159b7f..8bcd1bb 100644
--- a/libmailutils/tests/wordsplit.at
+++ b/libmailutils/tests/wordsplit.at
@@ -212,7 +212,6 @@ TESTWSP([K/V environment],[],[env_kv],
 [],
 [FOO=bar BAZ=qux])
 
-
 TESTWSP([nosplit with expansion],[],[nosplit],
 [a $FOO test],
 [NF: 1
@@ -311,4 +310,19 @@ TESTWSP([C escapes off],[],[-cescapes],
 3: newnline
 ])
 
+TESTWSP([empty quotes],[],[delim : ws return_delims],
+[t=""],
+[NF: 1
+0: t=
+])
+
+TESTWSP([delimiter following empty quotes],[],[delim : ws return_delims],
+[t="":r],
+[NF: 3
+0: t=
+1: :
+2: r
+])
+
+
 m4_popdef([TESTWSP])
diff --git a/mh/anno.c b/mh/anno.c
index aa16f32..972268c 100644
--- a/mh/anno.c
+++ b/mh/anno.c
@@ -109,7 +109,7 @@ main (int argc, char **argv)
   mu_mailbox_t mbox;
   mh_msgset_t msgset;
   size_t len;
-  
+
   MU_APP_INIT_NLS ();
 
   mh_argp_init ();
@@ -120,11 +120,37 @@ main (int argc, char **argv)
 
   if (!component)
     {
-      size_t n;
+      mu_stream_t in;
+      size_t size = 0;
+      char *p;
       
-      printf (_("Component name: "));
-      if (getline (&component, &n, stdin) <= 0 || *component == 0)
-	exit (1);
+      rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
+      if (rc)
+	{
+	  mu_error (_("cannot create input stream: %s"), mu_strerror (rc));
+	  exit (1);
+	}
+
+      if (isatty (0))
+	{
+	  printf (_("Component name: "));
+	  fflush (stdout);
+	}
+      rc = mu_stream_getline (in, &component, &size, NULL);
+      mu_stream_destroy (&in);
+      if (rc)
+	{
+	  mu_error (_("error reading input stream: %s"), mu_strerror (rc));
+	  exit (1);
+	}
+      p = mu_str_stripws (component);
+      if (*p == 0)
+	{
+	  mu_error (_("invalid component name"));
+	  exit (1);
+	}
+      if (p > component)
+	memmove (component, p, strlen (p) + 1);
     }
 
   if (!anno_text && !anno_date)
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 8fc0bda..016bf54 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -40,9 +40,19 @@ char mh_list_format[] =
   "%<(zero)%17(decode(friendly{from}))%>"
   "  %(decode{subject})%<{body}<<%{body}>>%>";
 
+/* Make sure stdin is open.  If not, connect it to /dev/null. */
+static void
+mh_ensure_stdin ()
+{
+  int fd = open ("/dev/null", O_RDONLY);
+  if (fd != 0)
+    close (fd);
+}
+
 void
 mh_init ()
 {
+  mh_ensure_stdin ();
   /* Register all mailbox and mailer formats */
   mu_register_all_formats ();
 #ifdef WITH_TLS
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 86b3c96..4761ace 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -152,11 +152,22 @@ parse_variable (locus_t *loc, mu_list_t formlist, char *str)
   size_t i;
   struct mu_wordsplit ws;
   mh_format_t fmt;
-
-  ws.ws_delim = ",=";
-  if (mu_wordsplit (str, &ws,
-		    MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|
-		    MU_WRDSF_WS|MU_WRDSF_RETURN_DELIMS))
+  int wsflags;
+  
+  if (strncmp (str, "ignores=", 8) == 0 && str[8] != '"')
+    {
+      /* A hack to allow for traditional use of "ignores=", i.e.
+	 as a single statement on a line, without double-quotes around
+	 the argument */
+      wsflags = MU_WRDSF_NOCMD | MU_WRDSF_NOVAR | MU_WRDSF_NOSPLIT;
+    }
+  else
+    {
+      ws.ws_delim = ",";
+      wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|
+	        MU_WRDSF_WS|MU_WRDSF_RETURN_DELIMS;
+    }
+  if (mu_wordsplit (str, &ws, wsflags))
     {
       mu_error ("%s:%d: mu_wordsplit(%s): %s",
 		loc->filename,
@@ -172,7 +183,10 @@ parse_variable (locus_t *loc, mu_list_t formlist, char *str)
       char *name = ws.ws_wordv[i];
       char *value = NULL;
       mhl_variable_t *var;
-
+      
+      value = strchr (name, '=');
+      if (value)
+	*value++ = 0;
       stmt = stmt_alloc (stmt_variable);
       var = variable_lookup (name);
       if (!var)
@@ -184,12 +198,6 @@ parse_variable (locus_t *loc, mu_list_t formlist, char *str)
 	  exit (1);
 	}
 
-      if (i + 1 < ws.ws_wordc && ws.ws_wordv[i+1][0] == '=')
-	{
-	  i++;
-	  value = ws.ws_wordv[++i];
-	}
-
       if ((var->type == dt_flag && value)
 	  || (var->type != dt_flag && !value))
 	{
@@ -256,45 +264,39 @@ parse_line (locus_t *loc, mu_list_t formlist, char *str)
 mu_list_t 
 mhl_format_compile (char *name)
 {
-  FILE *fp;
+  mu_stream_t stream;
   mu_list_t formlist;
   char *buf = NULL;
-  size_t n = 0;
+  size_t size = 0, n;
   locus_t loc;
   int rc;
-  
-  fp = fopen (name, "r");
-  if (!fp)
+
+  rc = mu_file_stream_create (&stream, name, MU_STREAM_READ);
+  if (rc)
     {
-      mu_error (_("cannot open file %s: %s"), name, mu_strerror (errno));
+      mu_error (_("cannot open format file %s: %s"), name, mu_strerror (rc));
       return NULL;
     }
 
   if ((rc = mu_list_create (&formlist)) != 0)
     {
-      fclose (fp);
       mu_diag_funcall (MU_DIAG_ERROR, "mu_list_create", NULL, rc);
+      mu_stream_destroy (&stream);
       return NULL;
     }
 
   loc.filename = name;
   loc.line = 1;
-  while (getline (&buf, &n, fp) > 0)
+  while (mu_stream_getline (stream, &buf, &size, &n) == 0 && n > 0)
     {
-      char *p = buf;
-
-      while (*p && mu_isspace (*p))
-	;
-
-      if (*p == 0 || *p == ';')
-	continue;
-
-      parse_line (&loc, formlist, p);
+      char *p = mu_str_stripws (buf);
+      if (!(*p == 0 || *p == ';'))
+	parse_line (&loc, formlist, p);
       loc.line++;
     }
 
   free (buf);
-  fclose (fp);
+  mu_stream_destroy (&stream);
   
   return formlist;
 }
@@ -470,13 +472,13 @@ _comp_name (void *item, void *date)
 }
 
 int
-header_is_printed (struct eval_env *env, char *name)
+header_is_printed (struct eval_env *env, const char *name)
 {
-  return mu_list_do (env->printed_fields, _comp_name, name) == 1;
+  return mu_list_do (env->printed_fields, _comp_name, (void*) name) == 1;
 }
 
 int
-want_header (struct eval_env *env, char *name)
+want_header (struct eval_env *env, const char *name)
 {
   char *p, *str = env->svar[S_IGNORES];
 
@@ -546,9 +548,8 @@ ovf_print (struct eval_env *env, char *str, int size, int nloff)
 	      mu_stream_write (env->output, env->prefix,
 			       strlen (env->prefix), NULL);
 	      env->pos += strlen (env->prefix);
-	      
-	      goto_offset (env, nloff);
 	    }
+	  goto_offset (env, nloff);
 	}
       
       if (env->pos + len > env->ivar[I_WIDTH])
@@ -656,19 +657,33 @@ print_header_value (struct eval_env *env, char *val)
   return 0;
 }
 
+void
+print_component_name (struct eval_env *env)
+{
+  if (!env->bvar[B_NOCOMPONENT])
+    {
+      print (env, env->svar[S_COMPONENT], 0);
+      if (mu_c_strcasecmp (env->svar[S_COMPONENT], "body"))
+	print (env, ": ", 0);
+    }
+}
+
 int
 eval_component (struct eval_env *env, char *name)
 {
   mu_header_t hdr;
   char *val;
-  
+
   mu_message_get_header (env->msg, &hdr);
   if (mu_header_aget_value (hdr, name, &val))
     return 0;
 
+  print_component_name (env);
   mu_list_append (env->printed_fields, name);
   print_header_value (env, val);
   free (val);
+  if (env->bvar[B_NEWLINE])
+    newline (env);
   return 0;
 }
 
@@ -680,9 +695,12 @@ eval_body (struct eval_env *env)
   char buf[128]; /* FIXME: Fixed size. Bad */
   size_t n;
   mu_body_t body = NULL;
-
+  int nl;
+  
   if (env->bvar[B_DISABLE_BODY])
     return 0;
+
+  print_component_name (env);
   
   env->prefix = env->svar[S_COMPONENT];
 
@@ -712,8 +730,11 @@ eval_body (struct eval_env *env)
     {
       buf[n] = 0;
       print (env, buf, 0);
+      nl = buf[n-1] == '\n';
     }
   mu_stream_destroy (&input);
+  if (!nl && env->bvar[B_NEWLINE])
+    newline (env);
   return 0;
 }
 
@@ -722,25 +743,30 @@ eval_extras (struct eval_env *env)
 {
   mu_header_t hdr;
   size_t i, num;
-  char buf[512];
+  char *str;
 
+  print_component_name (env);
   mu_message_get_header (env->msg, &hdr);
   mu_header_get_field_count (hdr, &num);
   for (i = 1; i <= num; i++)
     {
-      mu_header_get_field_name (hdr, i, buf, sizeof buf, NULL);
-      if (want_header (env, buf)
-	  && !header_is_printed (env, buf))
+      mu_header_aget_field_name (hdr, i, &str);
+      if (want_header (env, str)
+	  && !header_is_printed (env, str))
 	{
 	  goto_offset (env, env->ivar[I_OFFSET]);
-	  print (env, buf, 0);
-	  print (env, ":", 0);
-	  mu_header_get_field_value (hdr, i, buf, sizeof buf, NULL);
-	  print_header_value (env, buf);
-	  if (env->bvar[B_NEWLINE])
+	  print (env, str, 0);
+	  print (env, ": ", 0);
+	  free (str);
+	  mu_header_aget_field_value (hdr, i, &str);
+	  print_header_value (env, str);
+	  if (i < num && env->bvar[B_NEWLINE])
 	    newline (env);
 	}
+      free (str);
     }
+  if (env->bvar[B_NEWLINE])
+    newline (env);
   return 0;
 }
 
@@ -756,13 +782,6 @@ eval_comp (struct eval_env *env, char *compname, mu_list_t format)
   if (!lenv.svar[S_COMPONENT])
     lenv.svar[S_COMPONENT] = compname;
   
-  if (!lenv.bvar[B_NOCOMPONENT])
-    {
-      print (&lenv, lenv.svar[S_COMPONENT], 0);
-      if (strcmp (compname, "body"))
-	print (&lenv, ":", 0);
-    }
-
   if (strcmp (compname, "extras") == 0)
     eval_extras (&lenv);
   else if (strcmp (compname, "body") == 0)
@@ -770,9 +789,6 @@ eval_comp (struct eval_env *env, char *compname, mu_list_t format)
   else
     eval_component (&lenv, compname);
   
-  if (lenv.bvar[B_NEWLINE])
-    newline (&lenv);
-
   env->pos = lenv.pos;
   env->nlines = lenv.nlines;
   
diff --git a/mh/mhl.c b/mh/mhl.c
index 5f6b6fc..9b5abcb 100644
--- a/mh/mhl.c
+++ b/mh/mhl.c
@@ -142,7 +142,7 @@ open_output ()
 
   if (interactive && !nomoreproc)
     {
-      if (!moreproc)
+      if (!moreproc || !moreproc[0])
 	moreproc = mh_global_profile_get ("moreproc", getenv ("PAGER"));
     }
   else
diff --git a/mh/mhl.format b/mh/mhl.format
index 210d98d..4b6b7cb 100644
--- a/mh/mhl.format
+++ b/mh/mhl.format
@@ -2,12 +2,12 @@
 ;
 ; GNU Mailutils -- a suite of utilities for electronic mail
 ; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
-; Distributed under GPL.
+; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
 ;
 : -- using template mhl.format --
 overflowtext="***",overflowoffset=5
 leftadjust,compwidth=9
-ignores="msgid,message-id,received"
+ignores=msgid,message-id,received
 Date:formatfield="%<(nodate{text})%{text}%|%(pretty{text})%>"
 To:
 cc:
@@ -17,5 +17,5 @@ Subject:
 :
 extras:nocomponent
 :
-body:nocomponent,overflowtext="",overflowoffset=0,noleftadjust
+body:nocomponent,overflowtext=,overflowoffset=0,noleftadjust
 ; End of mhl.format
\ No newline at end of file
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 26be1c7..2006a35 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -39,9 +39,11 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
 ## ------------ ##
 
 TESTSUITE_AT = \
+ anno.at\
  folder.at\
  inc.at\
  mark.at\
+ mhl.at\
  mhparam.at\
  mhpath.at\
  scan.at\
diff --git a/mh/tests/anno.at b/mh/tests/anno.at
new file mode 100644
index 0000000..376d176
--- /dev/null
+++ b/mh/tests/anno.at
@@ -0,0 +1,62 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[anno])
+
+MH_CHECK([anno],[anno00],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+echo Replied | anno || exit $?
+sed -n '1{s/Replied: .*/REPLIED/p}' Mail/inbox/1
+],
+[0],
+[REPLIED
+])
+
+MH_CHECK([anno -component],[anno01 anno-component],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+anno -component Replied 1 || exit $?
+sed -n '1{s/Replied: .*/REPLIED/p}' Mail/inbox/1
+],
+[0],
+[REPLIED
+])
+
+MH_CHECK([anno -component -text],[anno02 anno-component-text],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+anno -component Replied -text OK 1 || exit $?
+sed -n '3,$d;/Replied/{s/Replied: [[A-Z][a-z][a-z], [0-9][0-9] [A-Z][a-z][a-z] [0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] .*]/Replied: DATE/;p}' Mail/inbox/1
+],
+[0],
+[Replied: OK
+Replied: DATE
+])
+
+MH_CHECK([anno -component -text -nodate],[anno03 anno-component-text-nodate],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+anno -component Replied -text OK -nodate 1 || exit $?
+sed -n '3,$d;/Replied/{s/Replied: [[A-Z][a-z][a-z], [0-9][0-9] [A-Z][a-z][a-z] [0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]:[0-9][0-9] .*]/Replied: DATE/;p}' Mail/inbox/1
+],
+[0],
+[Replied: OK
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of anno.at
diff --git a/maidag/tests/url-mbox.at b/mh/tests/mhl.at
similarity index 60%
copy from maidag/tests/url-mbox.at
copy to mh/tests/mhl.at
index dd29ab4..e8f17e6 100644
--- a/maidag/tests/url-mbox.at
+++ b/mh/tests/mhl.at
@@ -14,21 +14,25 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([URL mode])
-AT_KEYWORDS([maidag url-mbox url])
+m4_pushdef[MH_KEYWORDS],[mhl])
 
-AT_CHECK([
-echo ENVELOPE > expout
-cat $abs_top_srcdir/maidag/tests/input.msg >> expout
-echo "" >> expout
-mkdir spool
-
-maidag MAIDAG_OPTIONS --from 'gulliver@example.net' --url mbox:spool/out < dnl
- $abs_top_srcdir/maidag/tests/input.msg || exit $?
-sed '1s/From gulliver@example.net.*/ENVELOPE/' spool/out
+MH_CHECK([mhl],[mhl00],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+mhl -form $abs_top_srcdir/mh/mhl.format Mail/inbox/2
 ],
 [0],
-[expout])
+[ -- using template mhl.format --
+Date:    Mon, 29 Jul 2002 22:00:02 +0100
+To:      March Hare  <hare@wonder.land>
+
+From:    Alice  <alice@wonder.land>
+Subject: Re: Invitation
+
+X-Envelope-Date: Mon Jul 29 22:00:09 2002
+X-Envelope-Sender: alice@wonder.land
+
+I don't see any wine
+]) 
 
-AT_CLEANUP
- 
\ No newline at end of file
+m4_popdef[MH_KEYWORDS])
+# End of mhl.at
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index b992930..86bc7ba 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -50,3 +50,5 @@ m4_include([mark.at])
 m4_include([mhparam.at])
 m4_include([refile.at])
 m4_include([mhpath.at])
+m4_include([mhl.at])
+m4_include([anno.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 11 16:42:16 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PGeuN-0005Kz-Vw
	for mharc-commit-mailutils@gnu.org; Thu, 11 Nov 2010 16:42:16 -0500
Received: from [140.186.70.92] (port=52359 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PGeuK-0005Jm-Ut
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 16:42:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGeuJ-0003OS-GV
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 16:42:12 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:43946
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGeuJ-0003OO-BQ
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 16:42:11 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGeuJ-00050x-3V
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 21:42:11 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PGeuE-0000yK-B3
	for commit-mailutils@gnu.org; Thu, 11 Nov 2010 21:42:11 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: c02201707fd4664252ba0e3fe93d3018ec816c89
X-Git-Newrev: 3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204
Message-Id: <E1PGeuE-0000yK-B3@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 11 Nov 2010 21:42:06 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-187-g3fb87f6
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 11 Nov 2010 21:42:14 -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=3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204

The branch, master has been updated
       via  3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204 (commit)
      from  c02201707fd4664252ba0e3fe93d3018ec816c89 (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 3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 11 23:40:01 2010 +0200

    Document null streams
    
    * doc/texinfo/nullstream.texi: New file.
    
    * mh/mh_init.c (mh_real_install): Use mu_stream_t instead of
    FILE.
    * mh/mh_whatnow.c (_whatnow): Likewise.

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

Summary of changes:
 doc/texinfo/nullstream.texi |  279 +++++++++++++++++++++++++++++++++++++++++++
 mh/mh_init.c                |   30 +++--
 mh/mh_whatnow.c             |   34 ++++--
 3 files changed, 320 insertions(+), 23 deletions(-)
 create mode 100644 doc/texinfo/nullstream.texi

diff --git a/doc/texinfo/nullstream.texi b/doc/texinfo/nullstream.texi
new file mode 100644
index 0000000..a140150
--- /dev/null
+++ b/doc/texinfo/nullstream.texi
@@ -0,0 +1,279 @@
+@c This is part of the GNU Mailutils manual.
+@c Copyright (C) 2010 Free Software Foundation, Inc.
+@c See file mailutils.texi for copying conditions.
+@c *******************************************************************
+
+@section Null stream
+@cindex null stream
+@cindex stream, null
+
+A @dfn{null stream} is similar to the system @file{/dev/null} device.
+It is not connected to any particular physical storage.  Any data
+written to such stream are irrevocably lost.  Reading from such a
+stream returns fixed data, depending on the mode of the stream.
+
+An instance of the null stream is created using the following function:
+
+@deffn {stream function} int mu_nullstream_create (mu_stream_t *pstr, int mode)
+Create an instance of the null stream and return it in the memory
+location pointed to by @var{pstr}.  The @var{mode} argument specifies
+the access mode for this stream.  It can be a binary @samp{or} of the
+following values:
+
+@table @code
+@item MU_STREAM_READ
+Stream is opened for reading.
+@item MU_STREAM_WRITE
+Stream is opened for writing.
+@end table
+
+The returned stream is always seekable, so the @code{MU_STREAM_SEEK}
+mode is implied.
+
+Any other bits set in the @var{mode} argument are silently ignored.
+@end deffn
+
+Writing to an instance of null stream and seeking in such streams
+always succeeds.  If the stream was created with the
+@code{MU_STREAM_READ} on, the reads from it normally behave as if
+it were connected to an endless source of zero bytes, i.e. each call
+to:
+
+@smallexample
+  mu_stream_read (str, buf, size, &n);
+@end smallexample
+
+@noindent
+results in filling @var{buf} with @var{size} zeroes.  This is similar
+to reading from the system @file{/dev/zero} device@footnote{Note that
+the internal implementation of @dfn{null streams} has nothing to do
+with @file{/dev/null}, or @file{/dev/zero}.  We refer to these devices
+only to illustrate the behavior of @dfn{null streams}.}.
+
+This is the default behavior when reading.  It can be altered using
+the following @dfn{ioctls}.
+
+@defvr {ioctl} MU_IOCTL_NULLSTREAM_SET_PATTERN
+Set the @dfn{pattern} for reads.  The argument is a pointer to
+@dfn{struct mu_nullstream_pattern}, defined as:
+
+@smallexample
+@group
+struct mu_nullstream_pattern
+@{
+  char *pattern;   /* Return pattern */          
+  size_t size;     /* Number of bytes in pattern */
+@};
+@end group
+@end smallexample
+
+The @samp{pattern} member points to @samp{size} bytes of data which
+are returned cyclically at each read.  For example, suppose that
+@var{str} is a null stream instance, and consider the following code:
+
+@smallexample
+  struct mu_nullstream_pattern pat;
+  char buf[16];
+  size_t n;
+  
+  pat.pattern = "01234567";
+  pat.size = 8;
+  mu_stream_ioctl (str, MU_IOCTL_NULLSTREAM_SET_PATTERN, &pat);
+
+  mu_stream_read (str, buf, sizeof (buf), &n);
+@end smallexample
+
+Then, after the call to @code{mu_stream_read}, we will have:
+
+@smallexample
+@group
+n @result{} 16
+buf @result{} "0123456701234567"
+@end group
+@end smallexample
+
+Similarly, the following code:
+
+@smallexample
+  mu_stream_seek (str, 3, MU_SEEK_SET, NULL);
+  mu_stream_read (str, buf, sizeof (buf), &n);
+@end smallexample
+
+@noindent
+will yield:
+
+@smallexample
+@group
+n @result{} 16
+buf @result{} "3456701234567012"
+@end group
+@end smallexample
+
+The default behavior corresponds to the following initialization:
+
+@smallexample
+@group
+  pat.pattern = "";
+  pat.size = 1;
+  mu_stream_ioctl (str, MU_IOCTL_NULLSTREAM_SET_PATTERN, &pat);
+@end group  
+@end smallexample
+
+Calling the @samp{MU_IOCTL_NULLSTREAM_SET_PATTERN} with a @samp{NULL}
+argument causes all subsequent reads from that stream to return @samp{EOF}:
+
+@smallexample
+@group
+  mu_stream_ioctl (str, MU_IOCTL_NULLSTREAM_SET_PATTERN, NULL);
+  @dots{}
+  rc = mu_stream_read (str, buf, sizeof (buf), &n);
+
+  rc @result{} 0
+  n @result{} 0
+@end group  
+@end smallexample
+@end defvr
+
+@defvr {ioctl} MU_IOCTL_NULLSTREAM_SET_PATCLASS
+Set read pattern in terms of @dfn{C character classes}
+(@FIXME-pxref{C character classes}).  Argument is a pointer
+to an integer containing a bitwise @samp{OR} of the desired
+character classes from @file{mailutils/cctype.h}.  For example,
+the following code:
+
+@smallexample
+  int class = MU_CTYPE_DIGIT|MU_CTYPE_XLETR;
+  mu_stream_ioctl (str, MU_IOCTL_NULLSTREAM_SET_PATCLASS, &class);
+@end smallexample
+
+@noindent
+initializes the read pattern to the following string:
+
+@smallexample
+0123456789ABCDEFabcdef
+@end smallexample
+@end defvr
+
+Two ioctls are provided to control the @dfn{size} of a null stream
+available to seek and read operations.
+
+@defvr {ioctl} MU_IOCTL_NULLSTREAM_SETSIZE
+Limit the addressable size of a null stream.  Argument is a pointer
+to @samp{mu_off_t} object specifying the new size.  The example below
+limits the stream size to 32 bytes:
+
+@smallexample
+@group
+  mu_off_t limit = 32;
+  mu_stream_ioctl (str, MU_IOCTL_NULLSTREAM_SETSIZE, &limit);
+@end group  
+@end smallexample
+@end defvr
+
+Another way to set the null stream size is via the
+@samp{mu_stream_truncate} function:
+
+@smallexample
+  mu_stream_truncate (str, 32);
+@end smallexample
+
+Setting the stream size to @samp{0} causes all subsequent reads from
+that stream to return @samp{EOF}.  The similar effect has the
+@samp{MU_IOCTL_NULLSTREAM_SET_PATTERN} ioctl with the @samp{NULL} argument.
+
+@defvr {ioctl} MU_IOCTL_NULLSTREAM_CLRSIZE
+Cancel the size limitation imposed by a previous
+@samp{MU_IOCTL_NULLSTREAM_SETSIZE} ioctl or a call to
+@samp{mu_stream_truncate}.  Argument must be @samp{NULL}.
+@end defvr
+
+@menu
+* null stream usage::
+@end menu
+
+@node null stream usage
+@subsection null stream usage
+
+Due to their nature, null streams are not among the most used stream
+flavors.  They are mainly useful for testing or measuring purposes.
+
+The @command{mhn} utility from GNU Mailutils MH suite gives a nice
+example of using a null stream instance to compute the actual
+(decoded) size of a part of a MIME message.  In the example below
+we present a simplified version of this code.  It defines the
+function @samp{decoded_size}:
+
+@deffn {example function} mu_off_t decoded_size (mu_stream_t mime_str, @
+       const char *encoding)
+Return the size of the decoded input strem.  Arguments are:
+
+@table @var
+@item mime_str
+A stream obtained from the MIME part.
+
+@item encoding
+Encoding type, as obtained from the @samp{Content-Transfer-Encoding}
+MIME header.
+@end table
+
+@example
+mu_off_t
+decoded_size (mu_stream_t mime_str, const char *encoding)
+@{
+  int rc;           /* Result code */
+  mu_stream_t fstr  /* Filter stream */
+  mu_stream_stat_buffer stat; /* Statistics buffer */
+  mu_stream_t null; /* Null stream */
+@end example
+
+First, create the filter stream for decoding the message part:
+@example
+  rc = mu_filter_create (&fstr, mime_str, encoding,
+                         MU_FILTER_DECODE, MU_STREAM_READ);
+  if (rc)
+    abort ();
+@end example
+
+Then, create an instance of the null stream which will act
+as a receiver:
+
+@example
+  mu_nullstream_create (&null, MU_STREAM_WRITE);
+@end example
+
+The data will be read from @var{fstr} and written to @var{null}.
+Number of bytes written will give the decoded size of the message.
+To get this number, attach the statistics buffer to the null
+stream:
+
+@example
+  mu_stream_set_stat (null, MU_STREAM_STAT_MASK (MU_STREAM_STAT_OUT),
+                      stat);
+@end example
+
+The second argument instructs the stream to keep track of the
+bytes output (i.e. written) to the stream.
+
+Now, copy the entire contents of @var{fstr} to @var{null}:
+
+@example
+  rc = mu_stream_copy (null, fstr, 0, NULL);
+  if (rc)
+    abort ();
+@end example
+
+When done, destroy both streams (they are not needed any more), and
+return the value of @samp{MU_STREAM_STAT_OUT} element from @var{stat}:
+
+@example
+  mu_stream_destroy (&null);
+  mu_stream_destroy (&fstr);
+  return stat[MU_STREAM_STAT_OUT];
+@}  
+@end example
+
+
+
+
+
+
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 016bf54..7b2098f 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -707,14 +707,21 @@ mh_real_install (char *name, int automode)
   char *home = mu_get_homedir ();
   char *mhdir;
   char *ctx;
+  mu_stream_t in;
+  int rc;
   FILE *fp;
-  
+
+  rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
+  if (rc)
+    {
+      mu_error (_("cannot create input stream: %s"), mu_strerror (rc));
+      exit (1);
+    }
+
   mhdir = mh_safe_make_file_name (home, "Mail");
   
   if (!automode)
     {
-      size_t n = 0;
-      
       /* TRANSLATORS: This is a question and will be followed
 	 by question mark on output. */
       if (mh_getyn_interactive (_("Do you need help")))
@@ -725,7 +732,8 @@ mh_real_install (char *name, int automode)
       if (!mh_getyn_interactive (_("Do you want the standard MH path \"%s\""), mhdir))
 	{
 	  int local;
-	  char *p;
+	  char *p, *buf = NULL;
+	  size_t size = 0;
 	  
 	  /* TRANSLATORS: This is a question and will be followed
 	     by question mark on output. */
@@ -734,16 +742,12 @@ mh_real_install (char *name, int automode)
 	    printf (_("What is the path? "));
 	  else
 	    printf (_("What is the full path? "));
-	  if (getline (&p, &n, stdin) <= 0)
-	    exit (1);
-
-	  n = strlen (p);
-	  if (n == 0)
+	  if (mu_stream_getline (in, &buf, &size, NULL))
 	    exit (1);
-
-	  if (p[n-1] == '\n')
-	    p[n-1] = 0;
-
+	  p = mu_str_stripws (buf);
+	  if (p > buf)
+	    memmove (buf, p, strlen (p) + 1);
+	  
 	  free (mhdir);
 	  if (local)
 	    {
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 6582fd8..9ba2195 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -323,37 +323,51 @@ static int
 _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
 {
   int rc, status = 0;
+  mu_stream_t in;
+  char *line = NULL;
+  size_t size = 0;
+  struct mu_wordsplit ws;
+  int wsflags = MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT;
+  
+  rc = mu_stdio_stream_create (&in, MU_STDIN_FD, 0);
+  if (rc)
+    {
+      mu_error (_("cannot create input stream: %s"), mu_strerror (rc));
+      exit (1);
+    }
   
   do
     {
-      char *line = NULL;
-      size_t size = 0;
-      struct mu_wordsplit ws;
       handler_fp fun;
       
       printf ("%s ", wh->prompt);
-      getline (&line, &size, stdin);
-      if (!line)
-	continue;
+      fflush (stdout);
+      status = mu_stream_getline (in, &line, &size, NULL);
+      if (rc)
+	{
+	  mu_error (_("cannot read input stream: %s"), mu_strerror (rc));
+	  break;
+	}
 
       ws.ws_comment = "#";
-      rc = mu_wordsplit (line, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_COMMENT);
-      free (line);
+      rc = mu_wordsplit (line, &ws, wsflags);
       if (rc)
 	{
 	  mu_error (_("cannot split line `%s': %s"), line,
 		    mu_wordsplit_strerror (&ws));
 	  break;
 	}
-
+      wsflags |= MU_WRDSF_REUSE;
       fun = func (tab, ws.ws_wordv[0]);
       if (fun)
 	rc = fun (wh, ws.ws_wordc, ws.ws_wordv, &status);
       else
 	rc = 0;
-      mu_wordsplit_free (&ws);
     }
   while (rc == 0);
+  if (wsflags & MU_WRDSF_REUSE)
+    mu_wordsplit_free (&ws);
+  free (line);
   return status;
 }
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Nov 13 17:09:53 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PHOID-0003ba-8y
	for mharc-commit-mailutils@gnu.org; Sat, 13 Nov 2010 17:09:53 -0500
Received: from [140.186.70.92] (port=50180 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PHOI8-0003bO-7T
	for commit-mailutils@gnu.org; Sat, 13 Nov 2010 17:09:52 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHOI2-00085W-IB
	for commit-mailutils@gnu.org; Sat, 13 Nov 2010 17:09:48 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:33199
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHOI2-00085O-E0
	for commit-mailutils@gnu.org; Sat, 13 Nov 2010 17:09:42 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHOI2-0006sw-0D
	for commit-mailutils@gnu.org; Sat, 13 Nov 2010 22:09:42 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHOI0-0001KI-Iy
	for commit-mailutils@gnu.org; Sat, 13 Nov 2010 22:09:41 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204
X-Git-Newrev: 4ba094cd136becc8ad41bb7a98ffccec5e48d59b
Message-Id: <E1PHOI0-0001KI-Iy@vcs-noshell.in.savannah.gnu.org>
Date: Sat, 13 Nov 2010 22:09:40 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-188-g4ba094c
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 13 Nov 2010 22:09:52 -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=4ba094cd136becc8ad41bb7a98ffccec5e48d59b

The branch, master has been updated
       via  4ba094cd136becc8ad41bb7a98ffccec5e48d59b (commit)
      from  3fb87f63f3dc9dbbcf3cecc2a9ef2c85bd007204 (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 4ba094cd136becc8ad41bb7a98ffccec5e48d59b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Nov 12 23:08:54 2010 +0200

    Minor fix in the test suite.
    
    Replace 'Mirddin.farlep.net' with 'example.net' throughout the
    testsuite.  Change expected message/part sizes accordingly.
    Files changed:
    
    * imap4d/testsuite/imap4d/fetch.exp
    * mail/testsuite/mail/folder.exp
    * mail/testsuite/mail/read.exp
    * mail/testsuite/mail/write.exp
    * mh/tests/scan.at
    * readmsg/tests/all.at
    * testsuite/maildir/mbox1/new/1284628225.M20118P3883Q2.Trurl
    * testsuite/maildir/mbox1/new/1284628225.M21284P3883Q3.Trurl
    * testsuite/maildir/mbox1/new/1284628225.M22502P3883Q4.Trurl
    * testsuite/mh/mbox1/3
    * testsuite/mh/mbox1/4
    * testsuite/mh/mbox1/5
    * testsuite/mime.at
    * testsuite/spool/mbox
    * testsuite/spool/mbox1
    * testsuite/spool/relational.mbox

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

Summary of changes:
 imap4d/testsuite/imap4d/fetch.exp                  |   38 ++++++------
 mail/testsuite/mail/folder.exp                     |    2 +-
 mail/testsuite/mail/read.exp                       |   38 ++++++------
 mail/testsuite/mail/write.exp                      |   20 +++---
 mh/tests/scan.at                                   |   12 ++--
 readmsg/tests/all.at                               |   26 ++++----
 .../mbox1/new/1284628225.M20118P3883Q2.Trurl       |   18 +++---
 .../mbox1/new/1284628225.M21284P3883Q3.Trurl       |   26 ++++----
 .../mbox1/new/1284628225.M22502P3883Q4.Trurl       |   18 +++---
 testsuite/mh/mbox1/3                               |   18 +++---
 testsuite/mh/mbox1/4                               |   26 ++++----
 testsuite/mh/mbox1/5                               |   18 +++---
 testsuite/mime.at                                  |   32 +++++-----
 testsuite/spool/mbox                               |   12 ++--
 testsuite/spool/mbox1                              |   62 ++++++++++----------
 testsuite/spool/relational.mbox                    |    8 +-
 16 files changed, 187 insertions(+), 187 deletions(-)

diff --git a/imap4d/testsuite/imap4d/fetch.exp b/imap4d/testsuite/imap4d/fetch.exp
index dc04bf3..4c3db23 100644
--- a/imap4d/testsuite/imap4d/fetch.exp
+++ b/imap4d/testsuite/imap4d/fetch.exp
@@ -67,9 +67,9 @@ imap4d_test "FETCH 3 (FLAGS INTERNALDATE UID)"\
 imap4d_test "FETCH 1:* ENVELOPE"\
 "1 FETCH (ENVELOPE (\"Fri, 28 Dec 2001 22:18:08 +0200\" \"Jabberwocky\" ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) NIL NIL NIL \"<200112282018.fBSKI8N04906@nonexistent.net>\"))"\
 "2 FETCH (ENVELOPE (\"Fri, 28 Dec 2001 23:28:08 +0200\" \"Re: Jabberwocky\" ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200112232808.fERKR9N16790@dontmailme.org>\"))"\
-"3 FETCH (ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Simple MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@Mirddin.farlep.net>\"))"\
-"4 FETCH (ENVELOPE (\"Sat, 13 Jul 2002 00:50:58 +0300\" \"Nested MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122150.g6CLowb05126@Mirddin.farlep.net>\"))"\
-"5 FETCH (ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Empty MIME Parts\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@Mirddin.farlep.net>\"))"\
+"3 FETCH (ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Simple MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@example.net>\"))"\
+"4 FETCH (ENVELOPE (\"Sat, 13 Jul 2002 00:50:58 +0300\" \"Nested MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122150.g6CLowb05126@example.net>\"))"\
+"5 FETCH (ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Empty MIME Parts\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@example.net>\"))"\
 "OK"
 
 # ALL            Macro equivalent to: (FLAGS INTERNALDATE
@@ -78,9 +78,9 @@ imap4d_test "FETCH 1:* ENVELOPE"\
 imap4d_test "FETCH 1:\* ALL"\
 "1 FETCH (FLAGS (\\Recent) INTERNALDATE \"28-Dec-2001 22:18:09 +0000\" RFC822.SIZE 1298 ENVELOPE (\"Fri, 28 Dec 2001 22:18:08 +0200\" \"Jabberwocky\" ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) NIL NIL NIL \"<200112282018.fBSKI8N04906@nonexistent.net>\"))"\
 "2 FETCH (FLAGS (\\Recent) INTERNALDATE \"28-Dec-2001 23:28:09 +0000\" RFC822.SIZE 547 ENVELOPE (\"Fri, 28 Dec 2001 23:28:08 +0200\" \"Re: Jabberwocky\" ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) ((\"Bar\" NIL \"bar\" \"dontmailme.org\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200112232808.fERKR9N16790@dontmailme.org>\"))"\
-"3 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:43:18 +0000\" RFC822.SIZE 1667 ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Simple MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@Mirddin.farlep.net>\"))"\
-"4 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:50:58 +0000\" RFC822.SIZE 3567 ENVELOPE (\"Sat, 13 Jul 2002 00:50:58 +0300\" \"Nested MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122150.g6CLowb05126@Mirddin.farlep.net>\"))"\
-"5 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:43:18 +0000\" RFC822.SIZE 940 ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Empty MIME Parts\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@Mirddin.farlep.net>\"))"\
+"3 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:43:18 +0000\" RFC822.SIZE 1611 ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Simple MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@example.net>\"))"\
+"4 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:50:58 +0000\" RFC822.SIZE 3483 ENVELOPE (\"Sat, 13 Jul 2002 00:50:58 +0300\" \"Nested MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122150.g6CLowb05126@example.net>\"))"\
+"5 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:43:18 +0000\" RFC822.SIZE 884 ENVELOPE (\"Sat, 13 Jul 2002 00:43:18 +0300\" \"Empty MIME Parts\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122143.g6CLhIb05086@example.net>\"))"\
 "OK"
 
 # BODYSTRUCTURE  The [MIME-IMB] body structure of the message.  This
@@ -97,24 +97,24 @@ imap4d_test "FETCH 2 BODYSTRUCTURE"\
 "OK"
 
 imap4d_test "FETCH 3 BODYSTRUCTURE"\
-"3 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"name\" \"msg.1\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@Mirddin.farlep.net>\" \"How doth\" \"7BIT\" 239 9 NIL NIL NIL)(\"application\" \"octet-stream\" (\"name\" \"msg.21\") \"<5082.1026510189.2@Mirddin.farlep.net>\" \"Father William Part I\" \"base64\" 468 NIL NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa0\") NIL NIL))"\
+"3 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"name\" \"msg.1\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@example.net>\" \"How doth\" \"7BIT\" 239 9 NIL NIL NIL)(\"application\" \"octet-stream\" (\"name\" \"msg.21\") \"<5082.1026510189.2@example.net>\" \"Father William Part I\" \"base64\" 468 NIL NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa0\") NIL NIL))"\
 "OK"
 
 imap4d_test "FETCH 4 BODYSTRUCTURE"\
-"4 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"name\" \"msg.21\" \"charset\" \"us-ascii\") \"<5122.1026510654.2@Mirddin.farlep.net>\" \"Father William Part I\" \"7BIT\" 351 10 NIL NIL NIL)((\"application\" \"octet-stream\" (\"name\" \"msg.22\") \"<5122.1026510654.4@Mirddin.farlep.net>\" \"Father William Part II\" \"base64\" 486 NIL NIL NIL)((\"application\" \"octet-stream\" (\"name\" \"msg.23\") \"<5122.1026510654.6@Mirddin.farlep.net>\" \"Father William Part III\" \"base64\" 490 NIL NIL NIL)(\"application\" \"octet-stream\" (\"name\" \"msg.24\") \"<5122.1026510654.7@Mirddin.farlep.net>\" \"Father William Part IV\" \"base64\" 502 NIL NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa2\") NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa1\") NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa0\") NIL NIL))"\
+"4 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"name\" \"msg.21\" \"charset\" \"us-ascii\") \"<5122.1026510654.2@example.net>\" \"Father William Part I\" \"7BIT\" 351 10 NIL NIL NIL)((\"application\" \"octet-stream\" (\"name\" \"msg.22\") \"<5122.1026510654.4@example.net>\" \"Father William Part II\" \"base64\" 486 NIL NIL NIL)((\"application\" \"octet-stream\" (\"name\" \"msg.23\") \"<5122.1026510654.6@example.net>\" \"Father William Part III\" \"base64\" 490 NIL NIL NIL)(\"application\" \"octet-stream\" (\"name\" \"msg.24\") \"<5122.1026510654.7@example.net>\" \"Father William Part IV\" \"base64\" 502 NIL NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa2\") NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa1\") NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa0\") NIL NIL))"\
 "OK"
 
 imap4d_test "FETCH 5 BODYSTRUCTURE"\
-"5 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"name\" \"empty\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@Mirddin.farlep.net>\" \"Empty part\" \"7BIT\" 0 0 NIL NIL NIL)(\"text\" \"plain\" (\"name\" \"single.line\" \"charset\" \"us-ascii\") \"<5082.1026510189.2@Mirddin.farlep.net>\" \"Single line part\" \"7BIT\" 2 1 NIL NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa0\") NIL NIL))"\
+"5 FETCH (BODYSTRUCTURE ((\"text\" \"plain\" (\"name\" \"empty\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@example.net>\" \"Empty part\" \"7BIT\" 0 0 NIL NIL NIL)(\"text\" \"plain\" (\"name\" \"single.line\" \"charset\" \"us-ascii\") \"<5082.1026510189.2@example.net>\" \"Single line part\" \"7BIT\" 2 1 NIL NIL NIL) \"mixed\" (\"boundary\" \"----- =_aaaaaaaaaa0\") NIL NIL))"\
 "OK" 
 
 # BODY       The text of a particular body section. 
 imap4d_test "FETCH 1:* BODY"\
 "1 FETCH (BODY (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" 972 35))"\
 "2 FETCH (BODY (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" 219 4))"\
-"3 FETCH (BODY ((\"text\" \"plain\" (\"name\" \"msg.1\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@Mirddin.farlep.net>\" \"How doth\" \"7BIT\" 239 9)(\"application\" \"octet-stream\" (\"name\" \"msg.21\") \"<5082.1026510189.2@Mirddin.farlep.net>\" \"Father William Part I\" \"base64\" 468) \"mixed\" NIL NIL NIL))"\
-"4 FETCH (BODY ((\"text\" \"plain\" (\"name\" \"msg.21\" \"charset\" \"us-ascii\") \"<5122.1026510654.2@Mirddin.farlep.net>\" \"Father William Part I\" \"7BIT\" 351 10)((\"application\" \"octet-stream\" (\"name\" \"msg.22\") \"<5122.1026510654.4@Mirddin.farlep.net>\" \"Father William Part II\" \"base64\" 486)((\"application\" \"octet-stream\" (\"name\" \"msg.23\") \"<5122.1026510654.6@Mirddin.farlep.net>\" \"Father William Part III\" \"base64\" 490)(\"application\" \"octet-stream\" (\"name\" \"msg.24\") \"<5122.1026510654.7@Mirddin.farlep.net>\" \"Father William Part IV\" \"base64\" 502) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL))"\
-"5 FETCH (BODY ((\"text\" \"plain\" (\"name\" \"empty\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@Mirddin.farlep.net>\" \"Empty part\" \"7BIT\" 0 0)(\"text\" \"plain\" (\"name\" \"single.line\" \"charset\" \"us-ascii\") \"<5082.1026510189.2@Mirddin.farlep.net>\" \"Single line part\" \"7BIT\" 2 1) \"mixed\" NIL NIL NIL))"\
+"3 FETCH (BODY ((\"text\" \"plain\" (\"name\" \"msg.1\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@example.net>\" \"How doth\" \"7BIT\" 239 9)(\"application\" \"octet-stream\" (\"name\" \"msg.21\") \"<5082.1026510189.2@example.net>\" \"Father William Part I\" \"base64\" 468) \"mixed\" NIL NIL NIL))"\
+"4 FETCH (BODY ((\"text\" \"plain\" (\"name\" \"msg.21\" \"charset\" \"us-ascii\") \"<5122.1026510654.2@example.net>\" \"Father William Part I\" \"7BIT\" 351 10)((\"application\" \"octet-stream\" (\"name\" \"msg.22\") \"<5122.1026510654.4@example.net>\" \"Father William Part II\" \"base64\" 486)((\"application\" \"octet-stream\" (\"name\" \"msg.23\") \"<5122.1026510654.6@example.net>\" \"Father William Part III\" \"base64\" 490)(\"application\" \"octet-stream\" (\"name\" \"msg.24\") \"<5122.1026510654.7@example.net>\" \"Father William Part IV\" \"base64\" 502) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL))"\
+"5 FETCH (BODY ((\"text\" \"plain\" (\"name\" \"empty\" \"charset\" \"us-ascii\") \"<5082.1026510189.1@example.net>\" \"Empty part\" \"7BIT\" 0 0)(\"text\" \"plain\" (\"name\" \"single.line\" \"charset\" \"us-ascii\") \"<5082.1026510189.2@example.net>\" \"Single line part\" \"7BIT\" 2 1) \"mixed\" NIL NIL NIL))"\
 "OK"
 
 # BODY.PEEK[<section>]<<partial>>
@@ -318,10 +318,10 @@ imap4d_test "FETCH 1 BODY\[TEXT\]<0.4000>"\
 # more numeric part specifiers.
 
 imap4d_test "FETCH 3 BODY\[1.MIME\]"\
-"3 FETCH (FLAGS (\\Seen) BODY\[1.MIME\] {145}"\
+"3 FETCH (FLAGS (\\Seen) BODY\[1.MIME\] {138}"\
 -literal\
 "Content-Type: text/plain; name=\"msg.1\"; charset=\"us-ascii\""\
-"Content-ID: <5082.1026510189.1@Mirddin.farlep.net>"\
+"Content-ID: <5082.1026510189.1@example.net>"\
 "Content-Description: How doth"\
 ""\
 ")"\
@@ -354,11 +354,11 @@ imap4d_test "FETCH 4 BODY\[2.2.1.TEXT\]"\
 "OK"
 
 imap4d_test "FETCH 4 BODY\[2.2.TEXT\]"\
-"4 FETCH (BODY\[2.2.TEXT\] {1446}"\
+"4 FETCH (BODY\[2.2.TEXT\] {1432}"\
 -literal\
 -- "------- =_aaaaaaaaaa2"\
 "Content-Type: application/octet-stream; name=\"msg.23\""\
-"Content-ID: <5122.1026510654.6@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.6@example.net>"\
 "Content-Description: Father William Part III"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -372,7 +372,7 @@ imap4d_test "FETCH 4 BODY\[2.2.TEXT\]"\
 ""\
 -- "------- =_aaaaaaaaaa2"\
 "Content-Type: application/octet-stream; name=\"msg.24\""\
-"Content-ID: <5122.1026510654.7@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.7@example.net>"\
 "Content-Description: Father William Part IV"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -488,7 +488,7 @@ imap4d_test "FETCH 2 RFC822.HEADER"\
 # RFC822.SIZE    The [RFC-822] size of the message.
 
 imap4d_test "FETCH 3 RFC822.SIZE"\
-"3 FETCH (RFC822.SIZE 1667)"\
+"3 FETCH (RFC822.SIZE 1611)"\
 "OK"
 
 # RFC822.TEXT    Functionally equivalent to BODY[TEXT], differing in
@@ -515,7 +515,7 @@ imap4d_test "FETCH 1 FAST" \
 #                RFC822.SIZE ENVELOPE BODY)
 
 imap4d_test "FETCH 4 FULL"\
-"4 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:50:58 +0000\" RFC822.SIZE 3567 ENVELOPE (\"Sat, 13 Jul 2002 00:50:58 +0300\" \"Nested MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"Mirddin.farlep.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122150.g6CLowb05126@Mirddin.farlep.net>\") BODY ((\"text\" \"plain\" (\"name\" \"msg.21\" \"charset\" \"us-ascii\") \"<5122.1026510654.2@Mirddin.farlep.net>\" \"Father William Part I\" \"7BIT\" 351 10)((\"application\" \"octet-stream\" (\"name\" \"msg.22\") \"<5122.1026510654.4@Mirddin.farlep.net>\" \"Father William Part II\" \"base64\" 486)((\"application\" \"octet-stream\" (\"name\" \"msg.23\") \"<5122.1026510654.6@Mirddin.farlep.net>\" \"Father William Part III\" \"base64\" 490)(\"application\" \"octet-stream\" (\"name\" \"msg.24\") \"<5122.1026510654.7@Mirddin.farlep.net>\" \"Father William Part IV\" \"base64\" 502) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL))"\
+"4 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:50:58 +0000\" RFC822.SIZE 3483 ENVELOPE (\"Sat, 13 Jul 2002 00:50:58 +0300\" \"Nested MIME\" ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Sergey Poznyakoff\" NIL \"gray\" \"example.net\")) ((\"Foo Bar\" NIL \"foobar\" \"nonexistent.net\")) NIL NIL NIL \"<200207122150.g6CLowb05126@example.net>\") BODY ((\"text\" \"plain\" (\"name\" \"msg.21\" \"charset\" \"us-ascii\") \"<5122.1026510654.2@example.net>\" \"Father William Part I\" \"7BIT\" 351 10)((\"application\" \"octet-stream\" (\"name\" \"msg.22\") \"<5122.1026510654.4@example.net>\" \"Father William Part II\" \"base64\" 486)((\"application\" \"octet-stream\" (\"name\" \"msg.23\") \"<5122.1026510654.6@example.net>\" \"Father William Part III\" \"base64\" 490)(\"application\" \"octet-stream\" (\"name\" \"msg.24\") \"<5122.1026510654.7@example.net>\" \"Father William Part IV\" \"base64\" 502) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL) \"mixed\" NIL NIL NIL))"\
 "OK"
 
 imap4d_stop
diff --git a/mail/testsuite/mail/folder.exp b/mail/testsuite/mail/folder.exp
index 4ddcf06..448385a 100644
--- a/mail/testsuite/mail/folder.exp
+++ b/mail/testsuite/mail/folder.exp
@@ -53,7 +53,7 @@ mail_test "file &" \
 mail_test "sum" \
  "\"$MU_SPOOL_DIR/mbox\": 1 message 1 new"
 mail_test "headers" \
- ">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/425   MBOX"	
+ ">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/390   MBOX"	
 
 mail_stop
 
diff --git a/mail/testsuite/mail/read.exp b/mail/testsuite/mail/read.exp
index 7e02fe5..61f6379 100644
--- a/mail/testsuite/mail/read.exp
+++ b/mail/testsuite/mail/read.exp
@@ -27,16 +27,16 @@ mail_command "set readonly"
 mail_test "size *" \
 "> 1  44/1254 "\
 "  2  13/534  "\
-"  3  42/1625 "\
-"  4  84/3483 "
+"  3  42/1569 "\
+"  4  84/3399 "
 
 ###########################################################################
 # `headers' and `print'
 mail_test "headers" \
 ">N   1 Foo Bar            Fri Dec 28 22:18  44/1254  Jabberwocky" \
 " N   2 Bar                Fri Dec 28 23:28  13/534   Re: Jabberwocky" \
-" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1625  Simple MIME" \
-" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3483  Nested MIME" \
+" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1569  Simple MIME" \
+" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3399  Nested MIME" \
 
 mail_test "print"\
 	"Received: (from foobar@nonexistent.net)"\
@@ -158,8 +158,8 @@ mail_test -message "top (2)" "top" \
 mail_test -message "headers (2)" "headers" \
 ">R   1 Foo Bar            Fri Dec 28 22:18  44/1254  Jabberwocky" \
 " N   2 Bar                Fri Dec 28 23:28  13/534   Re: Jabberwocky" \
-" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1625  Simple MIME" \
-" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3483  Nested MIME" \
+" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1569  Simple MIME" \
+" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3399  Nested MIME" \
 
 ###########################################################################
 # `next' should display the 2nd message
@@ -185,8 +185,8 @@ mail_test "next" \
 mail_test -message "headers (3)" "headers" \
 " R   1 Foo Bar            Fri Dec 28 22:18  44/1254  Jabberwocky" \
 ">R   2 Bar                Fri Dec 28 23:28  13/534   Re: Jabberwocky" \
-" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1625  Simple MIME" \
-" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3483  Nested MIME" \
+" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1569  Simple MIME" \
+" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3399  Nested MIME" \
 
 ###########################################################################
 # Check for `prev'
@@ -212,8 +212,8 @@ mail_test "prev"\
 mail_test -message "headers (4)" "headers" \
 ">R   1 Foo Bar            Fri Dec 28 22:18  44/1254  Jabberwocky" \
 " R   2 Bar                Fri Dec 28 23:28  13/534   Re: Jabberwocky" \
-" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1625  Simple MIME" \
-" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3483  Nested MIME" \
+" N   3 Sergey Poznyakoff  Sat Jul 13 00:43  42/1569  Simple MIME" \
+" N   4 Sergey Poznyakoff  Sat Jul 13 00:50  84/3399  Nested MIME" \
 
 ###########################################################################
 # print with an argument
@@ -245,7 +245,7 @@ mail_test -message "decoding simple MIME messages" \
 "| Encoding=7bit"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: text/plain; name=\"msg.1\"; charset=\"us-ascii\""\
-"Content-ID: <5082.1026510189.1@Mirddin.farlep.net>"\
+"Content-ID: <5082.1026510189.1@example.net>"\
 "Content-Description: How doth"\
 ""\
 "How doth the little crocodile"\
@@ -263,7 +263,7 @@ mail_test -message "decoding simple MIME messages" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.21\""\
-"Content-ID: <5082.1026510189.2@Mirddin.farlep.net>"\
+"Content-ID: <5082.1026510189.2@example.net>"\
 "Content-Description: Father William Part I"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -285,7 +285,7 @@ mail_test -message "decoding nested MIME messages" \
 "| Encoding=7bit"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: text/plain; name=\"msg.21\"; charset=\"us-ascii\""\
-"Content-ID: <5122.1026510654.2@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.2@example.net>"\
 "Content-Description: Father William Part I"\
 ""\
 "`You are old, Father William,' the young man said,"\
@@ -304,7 +304,7 @@ mail_test -message "decoding nested MIME messages" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.22\""\
-"Content-ID: <5122.1026510654.4@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.4@example.net>"\
 "Content-Description: Father William Part II"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -323,7 +323,7 @@ mail_test -message "decoding nested MIME messages" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.23\""\
-"Content-ID: <5122.1026510654.6@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.6@example.net>"\
 "Content-Description: Father William Part III"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -342,7 +342,7 @@ mail_test -message "decoding nested MIME messages" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.24\""\
-"Content-ID: <5122.1026510654.7@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.7@example.net>"\
 "Content-Description: Father William Part IV"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -364,7 +364,7 @@ mail_test -message "Addressing parts of a MIME message" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.23\""\
-"Content-ID: <5122.1026510654.6@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.6@example.net>"\
 "Content-Description: Father William Part III"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -386,7 +386,7 @@ mail_test -message "Addressing parts of a MIME message (2)" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.23\""\
-"Content-ID: <5122.1026510654.6@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.6@example.net>"\
 "Content-Description: Father William Part III"\
 "Content-Transfer-Encoding: base64"\
 ""\
@@ -405,7 +405,7 @@ mail_test -message "Addressing parts of a MIME message (2)" \
 "| Encoding=base64"\
 "+------------------------------------------------------------------------------+"\
 "Content-Type: application/octet-stream; name=\"msg.24\""\
-"Content-ID: <5122.1026510654.7@Mirddin.farlep.net>"\
+"Content-ID: <5122.1026510654.7@example.net>"\
 "Content-Description: Father William Part IV"\
 "Content-Transfer-Encoding: base64"\
 ""\
diff --git a/mail/testsuite/mail/write.exp b/mail/testsuite/mail/write.exp
index 4743f95..ae420e7 100644
--- a/mail/testsuite/mail/write.exp
+++ b/mail/testsuite/mail/write.exp
@@ -41,15 +41,15 @@ mail_test "delete" "No applicable messages"
 mail_start -reuse-spool "--file=%mbox1"
 mail_test "h" \
 	">U   1 Bar                Fri Dec 28 23:28  16/578   Re: Jabberwocky"\
-	" U   2 Sergey Poznyakoff  Sat Jul 13 00:43  44/1644  Simple MIME"\
-	" U   3 Sergey Poznyakoff  Sat Jul 13 00:43  29/932   Empty MIME Parts"
+	" U   2 Sergey Poznyakoff  Sat Jul 13 00:43  44/1588  Simple MIME"\
+	" U   3 Sergey Poznyakoff  Sat Jul 13 00:43  29/876   Empty MIME Parts"
 
 # Send first message to mbox...
 mail_command "mbox 1"
 mail_test "h" \
 	">M   1 Bar                Fri Dec 28 23:28  16/578   Re: Jabberwocky"\
-	" U   2 Sergey Poznyakoff  Sat Jul 13 00:43  44/1644  Simple MIME"\
-	" U   3 Sergey Poznyakoff  Sat Jul 13 00:43  29/932   Empty MIME Parts"
+	" U   2 Sergey Poznyakoff  Sat Jul 13 00:43  44/1588  Simple MIME"\
+	" U   3 Sergey Poznyakoff  Sat Jul 13 00:43  29/876   Empty MIME Parts"
 
 # ... and quit
 mail_test -noprompt "quit" \
@@ -59,16 +59,16 @@ mail_test -noprompt "quit" \
 # Now check the mbox contents
 mail_start -reuse-spool "--file=%mbox"
 mail_test "headers" \
-	">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/425   MBOX"\
+	">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/390   MBOX"\
 	" U   2 Bar                Fri Dec 28 23:28  16/578   Re: Jabberwocky"
 
 # Save messages to the third mailbox
 mail_command "set folder=\"$MU_FOLDER_DIR\""
 mail_test "save 1 2 +three" \
-	"\"$MU_FOLDER_DIR/three\"  28/1003"
+	"\"$MU_FOLDER_DIR/three\"  28/968"
 
 mail_test "headers" \
-	">*   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/425   MBOX"\
+	">*   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/390   MBOX"\
 	" *   2 Bar                Fri Dec 28 23:28  16/578   Re: Jabberwocky"
 
 mail_test -noprompt "quit" \
@@ -77,19 +77,19 @@ mail_test -noprompt "quit" \
 # Examine its contents
 mail_start -reuse-spool "--file=$MU_FOLDER_DIR/three"
 mail_test "headers" \
-	">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/425   MBOX"\
+	">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/390   MBOX"\
 	" U   2 Bar                Fri Dec 28 23:28  16/578   Re: Jabberwocky"
 
 # Test uppercase commands (Save and Copy)
 mail_command "set outfolder=\"$MU_FOLDER_DIR\""
 mail_test "Save" \
-	"\"$MU_FOLDER_DIR/gray\"  12/425"
+	"\"$MU_FOLDER_DIR/gray\"  12/390"
 
 mail_test "file \"$MU_FOLDER_DIR/gray\"" \
 	"Held 2 messages in $MU_FOLDER_DIR/three"
 
 mail_test "headers" \
-	">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/425   MBOX"
+	">N   1 Sergey Poznyakoff  Tue Jul 16 12:11  12/390   MBOX"
 mail_exit
 
 # Test write 
diff --git a/mh/tests/scan.at b/mh/tests/scan.at
index f62c0c6..1b11828 100644
--- a/mh/tests/scan.at
+++ b/mh/tests/scan.at
@@ -48,9 +48,9 @@ scan +mbox1 -format '%4(msg) %(decode(friendly{from})) - %(decode(friendly{to}))
 [0],
 [   1 Foo Bar <foobar@nonexistent.net> - Bar <bar@dontmailme.org>
    2 Bar <bar@dontmailme.org> - Foo Bar <foobar@nonexistent.net>
-   3 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
-   4 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
-   5 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+   3 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
+   4 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
+   5 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
 ])
 
 MH_CHECK([scan -form],[scan03 scan-form],[
@@ -61,9 +61,9 @@ scan +mbox1 -form formfile
 [0],
 [   1 Foo Bar <foobar@nonexistent.net> - Bar <bar@dontmailme.org>
    2 Bar <bar@dontmailme.org> - Foo Bar <foobar@nonexistent.net>
-   3 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
-   4 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
-   5 Sergey Poznyakoff <gray@Mirddin.farlep.net> - Foo Bar <foobar@nonexistent.
+   3 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
+   4 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
+   5 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
 ])
 
 MH_CHECK([scan -reverse],[scan04 scan-reverse],[
diff --git a/readmsg/tests/all.at b/readmsg/tests/all.at
index fd54991..8db52a6 100644
--- a/readmsg/tests/all.at
+++ b/readmsg/tests/all.at
@@ -71,11 +71,11 @@ that's clear, at any rate...
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Simple MIME
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.1"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: How doth
 
 How doth the little crocodile
@@ -90,7 +90,7 @@ With gently smiling jaws!
 
 ------- =_aaaaaaaaaa0
 Content-Type: application/octet-stream; name="msg.21"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Father William Part I
 Content-Transfer-Encoding: base64
 
@@ -106,11 +106,11 @@ ZWN0bHkgc3VyZSBJIGhhdmUgbm9uZSwKV2h5LCBJIGRvIGl0IGFnYWluIGFuZCBhZ2Fpbi4nCgo=
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Nested MIME
 Date: Sat, 13 Jul 2002 00:50:58 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.21"; charset="us-ascii"
-Content-ID: <5122.1026510654.2@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.2@example.net>
 Content-Description: Father William Part I
 
 `You are old, Father William,' the young man said,
@@ -126,11 +126,11 @@ Why, I do it again and again.'
 
 ------- =_aaaaaaaaaa0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <5122.1026510654.3@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.3@example.net>
 
 ------- =_aaaaaaaaaa1
 Content-Type: application/octet-stream; name="msg.22"
-Content-ID: <5122.1026510654.4@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.4@example.net>
 Content-Description: Father William Part II
 Content-Transfer-Encoding: base64
 
@@ -144,11 +144,11 @@ IGNvdXBsZT8nCg==
 
 ------- =_aaaaaaaaaa1
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa2"
-Content-ID: <5122.1026510654.5@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.5@example.net>
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.23"
-Content-ID: <5122.1026510654.6@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.6@example.net>
 Content-Description: Father William Part III
 Content-Transfer-Encoding: base64
 
@@ -162,7 +162,7 @@ dCBvZiBteSBsaWZlLicK
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.24"
-Content-ID: <5122.1026510654.7@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.7@example.net>
 Content-Description: Father William Part IV
 Content-Transfer-Encoding: base64
 
@@ -183,17 +183,17 @@ IGtpY2sgeW91IGRvd24gc3RhaXJzIScK
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Empty MIME Parts
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="empty"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: Empty part
 
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="single.line"; charset="us-ascii"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Single line part
 
 
diff --git a/testsuite/maildir/mbox1/new/1284628225.M20118P3883Q2.Trurl b/testsuite/maildir/mbox1/new/1284628225.M20118P3883Q2.Trurl
index 2efcb9e..42e40bc 100644
--- a/testsuite/maildir/mbox1/new/1284628225.M20118P3883Q2.Trurl
+++ b/testsuite/maildir/mbox1/new/1284628225.M20118P3883Q2.Trurl
@@ -1,21 +1,21 @@
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLhIb05086
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:43:18 +0300
-Message-Id: <200207122143.g6CLhIb05086@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLhIb05086
+	for <gray@example.net>; Sat, 13 Jul 2002 00:43:18 +0300
+Message-Id: <200207122143.g6CLhIb05086@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Simple MIME
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5082.1026510189.0@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.0@example.net>
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 X-Envelope-Date: Sat Jul 13 00:43:18 2002
-X-Envelope-Sender: gray@Mirddin.farlep.net
+X-Envelope-Sender: gray@example.net
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.1"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: How doth
 
 How doth the little crocodile
@@ -30,7 +30,7 @@ With gently smiling jaws!
 
 ------- =_aaaaaaaaaa0
 Content-Type: application/octet-stream; name="msg.21"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Father William Part I
 Content-Transfer-Encoding: base64
 
diff --git a/testsuite/maildir/mbox1/new/1284628225.M21284P3883Q3.Trurl b/testsuite/maildir/mbox1/new/1284628225.M21284P3883Q3.Trurl
index 4763565..fa7be1d 100644
--- a/testsuite/maildir/mbox1/new/1284628225.M21284P3883Q3.Trurl
+++ b/testsuite/maildir/mbox1/new/1284628225.M21284P3883Q3.Trurl
@@ -1,21 +1,21 @@
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLowb05126
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:50:58 +0300
-Message-Id: <200207122150.g6CLowb05126@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLowb05126
+	for <gray@example.net>; Sat, 13 Jul 2002 00:50:58 +0300
+Message-Id: <200207122150.g6CLowb05126@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Nested MIME
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5122.1026510654.1@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.1@example.net>
 Date: Sat, 13 Jul 2002 00:50:58 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 X-Envelope-Date: Sat Jul 13 00:50:58 2002
-X-Envelope-Sender: gray@Mirddin.farlep.net
+X-Envelope-Sender: gray@example.net
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.21"; charset="us-ascii"
-Content-ID: <5122.1026510654.2@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.2@example.net>
 Content-Description: Father William Part I
 
 `You are old, Father William,' the young man said,
@@ -31,11 +31,11 @@ Why, I do it again and again.'
 
 ------- =_aaaaaaaaaa0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <5122.1026510654.3@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.3@example.net>
 
 ------- =_aaaaaaaaaa1
 Content-Type: application/octet-stream; name="msg.22"
-Content-ID: <5122.1026510654.4@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.4@example.net>
 Content-Description: Father William Part II
 Content-Transfer-Encoding: base64
 
@@ -49,11 +49,11 @@ IGNvdXBsZT8nCg==
 
 ------- =_aaaaaaaaaa1
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa2"
-Content-ID: <5122.1026510654.5@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.5@example.net>
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.23"
-Content-ID: <5122.1026510654.6@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.6@example.net>
 Content-Description: Father William Part III
 Content-Transfer-Encoding: base64
 
@@ -67,7 +67,7 @@ dCBvZiBteSBsaWZlLicK
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.24"
-Content-ID: <5122.1026510654.7@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.7@example.net>
 Content-Description: Father William Part IV
 Content-Transfer-Encoding: base64
 
diff --git a/testsuite/maildir/mbox1/new/1284628225.M22502P3883Q4.Trurl b/testsuite/maildir/mbox1/new/1284628225.M22502P3883Q4.Trurl
index 660803f..e4422e2 100644
--- a/testsuite/maildir/mbox1/new/1284628225.M22502P3883Q4.Trurl
+++ b/testsuite/maildir/mbox1/new/1284628225.M22502P3883Q4.Trurl
@@ -1,27 +1,27 @@
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLhIb05086
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:43:18 +0300
-Message-Id: <200207122143.g6CLhIb05086@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLhIb05086
+	for <gray@example.net>; Sat, 13 Jul 2002 00:43:18 +0300
+Message-Id: <200207122143.g6CLhIb05086@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Empty MIME Parts
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5082.1026510189.0@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.0@example.net>
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 X-Envelope-Date: Sat Jul 13 00:43:18 2002
-X-Envelope-Sender: gray@Mirddin.farlep.net
+X-Envelope-Sender: gray@example.net
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="empty"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: Empty part
 
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="single.line"; charset="us-ascii"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Single line part
 
 
diff --git a/testsuite/mh/mbox1/3 b/testsuite/mh/mbox1/3
index 2efcb9e..42e40bc 100644
--- a/testsuite/mh/mbox1/3
+++ b/testsuite/mh/mbox1/3
@@ -1,21 +1,21 @@
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLhIb05086
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:43:18 +0300
-Message-Id: <200207122143.g6CLhIb05086@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLhIb05086
+	for <gray@example.net>; Sat, 13 Jul 2002 00:43:18 +0300
+Message-Id: <200207122143.g6CLhIb05086@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Simple MIME
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5082.1026510189.0@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.0@example.net>
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 X-Envelope-Date: Sat Jul 13 00:43:18 2002
-X-Envelope-Sender: gray@Mirddin.farlep.net
+X-Envelope-Sender: gray@example.net
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.1"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: How doth
 
 How doth the little crocodile
@@ -30,7 +30,7 @@ With gently smiling jaws!
 
 ------- =_aaaaaaaaaa0
 Content-Type: application/octet-stream; name="msg.21"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Father William Part I
 Content-Transfer-Encoding: base64
 
diff --git a/testsuite/mh/mbox1/4 b/testsuite/mh/mbox1/4
index 4763565..fa7be1d 100644
--- a/testsuite/mh/mbox1/4
+++ b/testsuite/mh/mbox1/4
@@ -1,21 +1,21 @@
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLowb05126
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:50:58 +0300
-Message-Id: <200207122150.g6CLowb05126@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLowb05126
+	for <gray@example.net>; Sat, 13 Jul 2002 00:50:58 +0300
+Message-Id: <200207122150.g6CLowb05126@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Nested MIME
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5122.1026510654.1@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.1@example.net>
 Date: Sat, 13 Jul 2002 00:50:58 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 X-Envelope-Date: Sat Jul 13 00:50:58 2002
-X-Envelope-Sender: gray@Mirddin.farlep.net
+X-Envelope-Sender: gray@example.net
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.21"; charset="us-ascii"
-Content-ID: <5122.1026510654.2@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.2@example.net>
 Content-Description: Father William Part I
 
 `You are old, Father William,' the young man said,
@@ -31,11 +31,11 @@ Why, I do it again and again.'
 
 ------- =_aaaaaaaaaa0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <5122.1026510654.3@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.3@example.net>
 
 ------- =_aaaaaaaaaa1
 Content-Type: application/octet-stream; name="msg.22"
-Content-ID: <5122.1026510654.4@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.4@example.net>
 Content-Description: Father William Part II
 Content-Transfer-Encoding: base64
 
@@ -49,11 +49,11 @@ IGNvdXBsZT8nCg==
 
 ------- =_aaaaaaaaaa1
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa2"
-Content-ID: <5122.1026510654.5@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.5@example.net>
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.23"
-Content-ID: <5122.1026510654.6@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.6@example.net>
 Content-Description: Father William Part III
 Content-Transfer-Encoding: base64
 
@@ -67,7 +67,7 @@ dCBvZiBteSBsaWZlLicK
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.24"
-Content-ID: <5122.1026510654.7@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.7@example.net>
 Content-Description: Father William Part IV
 Content-Transfer-Encoding: base64
 
diff --git a/testsuite/mh/mbox1/5 b/testsuite/mh/mbox1/5
index 660803f..e4422e2 100644
--- a/testsuite/mh/mbox1/5
+++ b/testsuite/mh/mbox1/5
@@ -1,27 +1,27 @@
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLhIb05086
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:43:18 +0300
-Message-Id: <200207122143.g6CLhIb05086@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLhIb05086
+	for <gray@example.net>; Sat, 13 Jul 2002 00:43:18 +0300
+Message-Id: <200207122143.g6CLhIb05086@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Empty MIME Parts
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5082.1026510189.0@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.0@example.net>
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 X-Envelope-Date: Sat Jul 13 00:43:18 2002
-X-Envelope-Sender: gray@Mirddin.farlep.net
+X-Envelope-Sender: gray@example.net
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="empty"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: Empty part
 
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="single.line"; charset="us-ascii"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Single line part
 
 
diff --git a/testsuite/mime.at b/testsuite/mime.at
index cb023f7..8834562 100644
--- a/testsuite/mime.at
+++ b/testsuite/mime.at
@@ -83,12 +83,12 @@ that's clear, at any rate...
 
 End
 Message: 3
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 Subject: Simple MIME
 Number of parts in message - 2
-Total message size - 1625/42
+Total message size - 1569/42
 Type of part 1 = text/plain
-Message part size - 371/13: 141/4, 230/9
+Message part size - 364/13: 134/4, 230/9
 Text Message
 Begin
 How doth the little crocodile
@@ -103,7 +103,7 @@ With gently smiling jaws!
 
 End
 Type of part 2 = application/octet-stream
-Message part size - 645/11: 183/5, 462/6
+Message part size - 638/11: 176/5, 462/6
 Attachment - saving [[msg.21]]
 Begin
 `You are old, Father William,' the young man said,
@@ -119,12 +119,12 @@ Why, I do it again and again.'
 
 End
 Message: 4
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 Subject: Nested MIME
 Number of parts in message - 2
-Total message size - 3483/84
+Total message size - 3399/84
 Type of part 1 = text/plain
-Message part size - 496/14: 155/4, 341/10
+Message part size - 489/14: 148/4, 341/10
 Text Message
 Begin
 `You are old, Father William,' the young man said,
@@ -140,11 +140,11 @@ Why, I do it again and again.'
 
 End
 Type of part 2 = multipart/mixed
-Message part size - 2378/52: 114/3, 2264/49
+Message part size - 2343/52: 107/3, 2236/49
 Encapsulated message : 	
 Begin
 Type of part 1 = application/octet-stream
-Message part size - 663/12: 184/5, 479/7
+Message part size - 656/12: 177/5, 479/7
 Attachment - saving [[msg.22]]
 Begin
 `You are old,' said the youth, `as I mentioned before,
@@ -159,11 +159,11 @@ Allow me to sell you a couple?'
 
 End
 Type of part 2 = multipart/mixed
-Message part size - 1531/32: 114/3, 1417/29
+Message part size - 1510/32: 107/3, 1403/29
 Encapsulated message : 	
 Begin
 Type of part 1 = application/octet-stream
-Message part size - 668/12: 185/5, 483/7
+Message part size - 661/12: 178/5, 483/7
 Attachment - saving [[msg.23]]
 Begin
 `You are old,' said the youth, `and your jaws are too weak
@@ -178,7 +178,7 @@ Has lasted the rest of my life.'
 
 End
 Type of part 2 = application/octet-stream
-Message part size - 679/12: 184/5, 495/7
+Message part size - 672/12: 177/5, 495/7
 Attachment - saving [[msg.24]]
 Begin
 `You are old,' said the youth, `one would hardly suppose
@@ -197,18 +197,18 @@ End
 
 End
 Message: 5
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 Subject: Empty MIME Parts
 Number of parts in message - 2
-Total message size - 913/27
+Total message size - 857/27
 Type of part 1 = text/plain
-Message part size - 143/4: 143/4, 0/0
+Message part size - 136/4: 136/4, 0/0
 Text Message
 Begin
 
 End
 Type of part 2 = text/plain
-Message part size - 156/5: 155/4, 1/1
+Message part size - 149/5: 148/4, 1/1
 Text Message
 Begin
 
diff --git a/testsuite/spool/mbox b/testsuite/spool/mbox
index 67e9865..525ce77 100644
--- a/testsuite/spool/mbox
+++ b/testsuite/spool/mbox
@@ -1,13 +1,13 @@
-From gray@Mirddin.farlep.net Tue Jul 16 12:11:35 2002
+From gray@example.net Tue Jul 16 12:11:35 2002
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1]) 
-	by Mirddin.farlep.net with ESMTP id g6G9BZb00791
-	for <gray@mirddin.farlep.net>; Tue, 16 Jul 2002 12:11:35 +0300
-Message-Id: <200207160911.g6G9BZb00791@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1]) 
+	by example.net with ESMTP id g6G9BZb00791
+	for <gray@example.net>; Tue, 16 Jul 2002 12:11:35 +0300
+Message-Id: <200207160911.g6G9BZb00791@example.net>
 To: Bar <bar@dontmailme.org>
 Subject: MBOX
 Date: Tue, 16 Jul 2002 12:11:35 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 
 This is a sample user's mbox.
diff --git a/testsuite/spool/mbox1 b/testsuite/spool/mbox1
index dee5a97..302bb26 100644
--- a/testsuite/spool/mbox1
+++ b/testsuite/spool/mbox1
@@ -59,23 +59,23 @@ Somehow it seems to fill my head with ideas -- only I don't
 exactly know what they are!  However, SOMEBODY killed SOMETHING:
 that's clear, at any rate...
 
-From gray@Mirddin.farlep.net Sat Jul 13 00:43:18 2002
+From gray@example.net Sat Jul 13 00:43:18 2002
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLhIb05086
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:43:18 +0300
-Message-Id: <200207122143.g6CLhIb05086@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLhIb05086
+	for <gray@example.net>; Sat, 13 Jul 2002 00:43:18 +0300
+Message-Id: <200207122143.g6CLhIb05086@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Simple MIME
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5082.1026510189.0@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.0@example.net>
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.1"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: How doth
 
 How doth the little crocodile
@@ -90,7 +90,7 @@ With gently smiling jaws!
 
 ------- =_aaaaaaaaaa0
 Content-Type: application/octet-stream; name="msg.21"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Father William Part I
 Content-Transfer-Encoding: base64
 
@@ -103,23 +103,23 @@ ZWN0bHkgc3VyZSBJIGhhdmUgbm9uZSwKV2h5LCBJIGRvIGl0IGFnYWluIGFuZCBhZ2Fpbi4nCgo=
 
 ------- =_aaaaaaaaaa0--
 
-From gray@Mirddin.farlep.net Sat Jul 13 00:50:58 2002
+From gray@example.net Sat Jul 13 00:50:58 2002
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLowb05126
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:50:58 +0300
-Message-Id: <200207122150.g6CLowb05126@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLowb05126
+	for <gray@example.net>; Sat, 13 Jul 2002 00:50:58 +0300
+Message-Id: <200207122150.g6CLowb05126@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Nested MIME
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5122.1026510654.1@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.1@example.net>
 Date: Sat, 13 Jul 2002 00:50:58 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="msg.21"; charset="us-ascii"
-Content-ID: <5122.1026510654.2@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.2@example.net>
 Content-Description: Father William Part I
 
 `You are old, Father William,' the young man said,
@@ -135,11 +135,11 @@ Why, I do it again and again.'
 
 ------- =_aaaaaaaaaa0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <5122.1026510654.3@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.3@example.net>
 
 ------- =_aaaaaaaaaa1
 Content-Type: application/octet-stream; name="msg.22"
-Content-ID: <5122.1026510654.4@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.4@example.net>
 Content-Description: Father William Part II
 Content-Transfer-Encoding: base64
 
@@ -153,11 +153,11 @@ IGNvdXBsZT8nCg==
 
 ------- =_aaaaaaaaaa1
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa2"
-Content-ID: <5122.1026510654.5@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.5@example.net>
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.23"
-Content-ID: <5122.1026510654.6@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.6@example.net>
 Content-Description: Father William Part III
 Content-Transfer-Encoding: base64
 
@@ -171,7 +171,7 @@ dCBvZiBteSBsaWZlLicK
 
 ------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.24"
-Content-ID: <5122.1026510654.7@Mirddin.farlep.net>
+Content-ID: <5122.1026510654.7@example.net>
 Content-Description: Father William Part IV
 Content-Transfer-Encoding: base64
 
@@ -189,29 +189,29 @@ IGtpY2sgeW91IGRvd24gc3RhaXJzIScK
 
 ------- =_aaaaaaaaaa0--
 
-From gray@Mirddin.farlep.net Sat Jul 13 00:43:18 2002
+From gray@example.net Sat Jul 13 00:43:18 2002
 Organization: Mailutils-tests
-Received: from Mirddin.farlep.net (localhost [127.0.0.1])
-	by Mirddin.farlep.net with ESMTP id g6CLhIb05086
-	for <gray@mirddin.farlep.net>; Sat, 13 Jul 2002 00:43:18 +0300
-Message-Id: <200207122143.g6CLhIb05086@Mirddin.farlep.net>
+Received: from example.net (localhost [127.0.0.1])
+	by example.net with ESMTP id g6CLhIb05086
+	for <gray@example.net>; Sat, 13 Jul 2002 00:43:18 +0300
+Message-Id: <200207122143.g6CLhIb05086@example.net>
 To: Foo Bar <foobar@nonexistent.net>
 Subject: Empty MIME Parts
 MIME-Version: 1.0
 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
-Content-ID: <5082.1026510189.0@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.0@example.net>
 Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@Mirddin.farlep.net>
+From: Sergey Poznyakoff <gray@example.net>
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="empty"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.1@example.net>
 Content-Description: Empty part
 
 
 ------- =_aaaaaaaaaa0
 Content-Type: text/plain; name="single.line"; charset="us-ascii"
-Content-ID: <5082.1026510189.2@Mirddin.farlep.net>
+Content-ID: <5082.1026510189.2@example.net>
 Content-Description: Single line part
 
 
diff --git a/testsuite/spool/relational.mbox b/testsuite/spool/relational.mbox
index 58bd695..5f79148 100644
--- a/testsuite/spool/relational.mbox
+++ b/testsuite/spool/relational.mbox
@@ -62,14 +62,14 @@ contradict to RFC 3028.
 From bar@dontmailme.org Sun May  6 22:17:15 2001
 From: Bar <bar@dontmailme.org>
 Received: from c.host.net ([1.1.1.3]) 
-	by Mirddin.farlep.net with ESMTP id g6G9BZb00791
-	for <gray@mirddin.farlep.net>; Tue, 16 Jul 2002 12:11:35 +0300
+	by example.net with ESMTP id g6G9BZb00791
+	for <gray@example.net>; Tue, 16 Jul 2002 12:11:35 +0300
 Received: from b.host.net ([1.1.1.2]) 
 	by c.host.net with ESMTP id g6G9BZb00791
-	for <gray@mirddin.farlep.net>; Tue, 16 Jul 2002 12:11:35 +0300
+	for <gray@example.net>; Tue, 16 Jul 2002 12:11:35 +0300
 Received: from a.host.net ([1.1.1.1]) 
 	by b.host.net with ESMTP id g6G9BZb00791
-	for <gray@mirddin.farlep.net>; Tue, 16 Jul 2002 12:11:35 +0300
+	for <gray@example.net>; Tue, 16 Jul 2002 12:11:35 +0300
 To: foo@example.com.invalid, baz@example.com.invalid, qux@example.com.invalid,
     me@foo.example.com.invalid, b1ff@de.res.example.com,
     roadrunner@acme.example.com


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Nov 14 05:54:20 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PHaE0-0004A4-1W
	for mharc-commit-mailutils@gnu.org; Sun, 14 Nov 2010 05:54:20 -0500
Received: from [140.186.70.92] (port=57150 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PHaDy-00047D-1E
	for commit-mailutils@gnu.org; Sun, 14 Nov 2010 05:54:19 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHaDt-00046V-25
	for commit-mailutils@gnu.org; Sun, 14 Nov 2010 05:54:17 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:37513
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHaDt-00046P-0S
	for commit-mailutils@gnu.org; Sun, 14 Nov 2010 05:54:13 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHaDs-0007UR-LO
	for commit-mailutils@gnu.org; Sun, 14 Nov 2010 10:54:12 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PHaDp-0006DZ-UZ
	for commit-mailutils@gnu.org; Sun, 14 Nov 2010 10:54:12 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 4ba094cd136becc8ad41bb7a98ffccec5e48d59b
X-Git-Newrev: d4582ca1b9a2d117f6f8db8fc5963c27f8c1fad4
Message-Id: <E1PHaDp-0006DZ-UZ@vcs-noshell.in.savannah.gnu.org>
Date: Sun, 14 Nov 2010 10:54:11 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-189-gd4582ca
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 14 Nov 2010 10:54:19 -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=d4582ca1b9a2d117f6f8db8fc5963c27f8c1fad4

The branch, master has been updated
       via  d4582ca1b9a2d117f6f8db8fc5963c27f8c1fad4 (commit)
      from  4ba094cd136becc8ad41bb7a98ffccec5e48d59b (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 d4582ca1b9a2d117f6f8db8fc5963c27f8c1fad4
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Nov 14 12:47:32 2010 +0200

    pick: improve compatibility.
    
    The traditional component matching syntax, `--COMP STRING', is
    accepted, provided at least one of the following conditions is met:
    
    1. The word `COMP' contains at least one capital letter;
    2. The word `COMP' ends with a colon;
    3. Standard input is not connected to a terminal.
    
    * mh/mh_getopt.c (mh_help_hook): New global variable.
    (mh_help): Call mh_help_hook, if set.
    * mh/mh_getopt.h (mh_help_hook): New extern.
    * mh/pick.c (doc): Update.
    (opt_handler): Remove ARGP_KEY_ERROR case.
    (pick_help_hook): New function.
    (main): Convert any instance of `--comp string' to
    `--component=comp --pattern=string', if comp contains a
    capital letter or ends with a colon, or fd 0 is not connected
    to terminal.
    * doc/texinfo/mu-mh.texi: Document changes to pick.

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

Summary of changes:
 doc/texinfo/mu-mh.texi |   19 ++++++--
 mh/mh_getopt.c         |    4 ++
 mh/mh_getopt.h         |    2 +
 mh/pick.c              |  116 +++++++++++++++++++++++++++++-------------------
 4 files changed, 90 insertions(+), 51 deletions(-)

diff --git a/doc/texinfo/mu-mh.texi b/doc/texinfo/mu-mh.texi
index dc8567a..b04a34c 100644
--- a/doc/texinfo/mu-mh.texi
+++ b/doc/texinfo/mu-mh.texi
@@ -332,11 +332,20 @@ The @code{rmmproc} profile component is not used.
 
 @item pick
 
-The non-standard command line syntax @option{--@var{field}
-@var{string}}), where @var{field} is any string, is deprecated. It is
-recognized only if @command{pick} is called from within another
-program, so that existing application continue to work. Please use the
-following syntax instead:
+The command line syntax @option{--@var{component} @var{string}}) is
+recognized only if at least one of the following conditions is met:
+
+@itemize @bullet
+@item The word @var{component} contains at least one capital letter.
+E.g. @option{--User-Agent Mailutils}.
+
+@item The word @var{component} ends with a colon, as in
+@option{user-agent: Mailutils}.
+
+@item Standard input is not connected to a terminal.
+@end itemize
+
+The GNU syntax for component matching is:
 
 @smallexample
 pick --component @var{field} --pattern @var{string}
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 138baa7..a90d943 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -31,6 +31,8 @@ static int mh_optind = 1;
 static char *mh_optarg;
 static char *mh_optptr;
 
+void (*mh_help_hook) ();
+
 int
 mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc)
 {
@@ -142,6 +144,8 @@ mh_help (struct mh_option *mh_opt, const char *doc)
 	printf (" %s", p->arg);
       printf ("\n");
     }
+  if (mh_help_hook)
+    mh_help_hook ();
   printf ("  -help\n");
   printf ("  -version\n");
   printf (_("\nPlease use GNU long options instead.\n"
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index 9aff8c9..b66026c 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -181,6 +181,8 @@ enum mh_arg {
   ARG_ZERO
 };
 
+extern void (*mh_help_hook) (void);
+
 void mh_argp_init (void);
 void mh_argv_preproc (int argc, char **argv, struct mh_argp_data *data);
 int mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc);
diff --git a/mh/pick.c b/mh/pick.c
index 122734c..91d202b 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -26,7 +26,17 @@
 #include <obstack.h>
 
 static char doc[] = N_("GNU MH pick")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+N_("Compatibility syntax for picking a matching component is:\n\
+\n\
+  --Component pattern\n\
+\n\
+where Component is the component name, containing at least one capital\n\
+letter or followed by a colon, e.g.:\n\
+\n\
+  --User-Agent Mailutils\n\
+  --user-agent: Mailutils\n\
+\n\
+Use -help to obtain a list of traditional MH options.");
 static char args_doc[] = N_("[messages]");
 
 /* GNU options */
@@ -140,8 +150,6 @@ add_sequence (char *name)
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
 {
-  char *s, *p;
-  
   switch (key)
     {
     case ARG_FOLDER: 
@@ -254,32 +262,6 @@ opt_handler (int key, char *arg, struct argp_state *state)
       seq_flags &= ~SEQ_ZERO;
       break;
 	
-    case ARGP_KEY_ERROR:
-      s = state->argv[state->next - 1];
-      if (memcmp (s, "--", 2))
-	{
-	  argp_error (state, _("invalid option -- %s"), s);
-	  exit (1);
-	}
-      p = strchr (s, '=');
-      if (p)
-	*p++ = 0;
-	
-      pick_add_token (&lexlist, T_COMP, s + 2);
-
-      if (!p)
-	{
-	  if (state->next == state->argc)
-	    {
-	      mu_error (_("invalid option -- %s"), s);
-	      exit (1);
-	    }
-	  p = state->argv[state->next++];
-	}
-      
-      pick_add_token (&lexlist, T_STRING, p);
-      break;
-
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -310,24 +292,43 @@ action_add (void *item, void *data)
   return 0;
 }
 
-/* NOTICE: For the compatibility with the RAND MH we have to support
+void
+pick_help_hook (void)
+{
+  printf ("\n");
+  printf (_("To match another component, use:\n\n"));
+  printf (_("  --Component pattern\n\n"));
+  printf (_("Note, that the component name must either be capitalized,\n"
+	    "or followed by a colon.\n"));
+  printf ("\n");
+}
+
+/* NOTICE: For compatibility with RAND MH we have to support
    the following command line syntax:
 
-       --FIELD STRING
+       --COMP STRING
 
-   where `FIELD' may be any string and which is equivalent to
-   `--field FIELD --pattern STRING'. Obviously this is in conflict
+   where `COMP' may be any string and which is equivalent to
+   `--component FIELD --pattern STRING'. Obviously this is in conflict
    with the usual GNU long options paradigm which requires that any
-   unrecognized long option produce an error. Unfortunately, mh-pick.el
-   relies heavily on this syntax, so it can't be simply removed.
-   The approach taken here allows to properly recognize such syntax,
-   however it has an undesirable side effect: due to the specifics of
-   the underlying arpg library the --help and --usage options get
-   disabled. To make them work as well, the following approach is
-   taken: the mh-compatible syntax gets enabled only if the file
-   descriptor of stdin is not connected to a terminal, which is true
-   when invoked from mh-pick.el module. Otherwise, it is disabled
-   and the standard GNU long option syntax is in force. */
+   unrecognized long option produce an error. The following
+   compromise solution is used:
+
+   The arguments `--COMP STRING' is recognized as a component matching
+   request if any of the following conditions is met:
+
+   1. The word `COMP' contains at least one capital letter.  E.g.:
+
+       --User-Agent Mailutils
+       
+   2. The word `COMP' ends with a colon, e.g.:
+
+       --user-agent: Mailutils
+   
+   3. Standard input is not connected to a terminal.  This is always
+      true when pick is invoked from mh-pick.el Emacs module.
+*/
+
 int
 main (int argc, char **argv)
 {
@@ -335,12 +336,35 @@ main (int argc, char **argv)
   int index;
   mu_mailbox_t mbox;
   mh_msgset_t msgset;
-  int flags;
+  int interactive = mh_interactive_mode_p ();
 
-  flags = mh_interactive_mode_p () ? 0 : ARGP_NO_ERRS;
   MU_APP_INIT_NLS ();
+
+  for (index = 1; index < argc; index++)
+    {
+      int colon = 0, cpos;
+      if (argv[index][0] == '-' && argv[index][1] == '-' &&
+	  !strchr (argv[index], '=') &&
+	  (!interactive ||
+	   (colon = argv[index][cpos = strlen (argv[index]) - 1] == ':') ||
+	   *mu_str_skip_class_comp (argv[index], MU_CTYPE_UPPER)) &&
+	  index + 1 < argc)
+	{
+	  if (colon)
+	    {
+	      cpos -= 2;
+	      mu_asprintf (&argv[index], "--component=%*.*s", cpos, cpos,
+			   argv[index] + 2);
+	    }
+	  else
+	    mu_asprintf (&argv[index], "--component=%s", argv[index] + 2);
+	  mu_asprintf (&argv[index + 1], "--pattern=%s", argv[index + 1]);
+	  index++;
+	}
+    }
+  mh_help_hook = pick_help_hook;
   mh_argp_init ();
-  mh_argp_parse (&argc, &argv, flags, options, mh_option,
+  mh_argp_parse (&argc, &argv, 0, options, mh_option,
 		 args_doc, doc, opt_handler, NULL, &index);
   if (pick_parse (lexlist))
     return 1;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Nov 15 10:15:47 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PI0mZ-0003YY-NS
	for mharc-commit-mailutils@gnu.org; Mon, 15 Nov 2010 10:15:47 -0500
Received: from [140.186.70.92] (port=53766 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PI0mR-0003Xp-G1
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 10:15:43 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI0mK-0001tE-W5
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 10:15:39 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:40466
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI0mK-0001sr-SY
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 10:15:32 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI0mK-0003Gw-DM
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 15:15:32 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI0mC-0003PE-IW
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 15:15:32 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d4582ca1b9a2d117f6f8db8fc5963c27f8c1fad4
X-Git-Newrev: c2a942772fc73a7b6f48766982f12fbc3dee4f71
Message-Id: <E1PI0mC-0003PE-IW@vcs-noshell.in.savannah.gnu.org>
Date: Mon, 15 Nov 2010 15:15:25 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-192-gc2a9427
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 15 Nov 2010 15:15:43 -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=c2a942772fc73a7b6f48766982f12fbc3dee4f71

The branch, master has been updated
       via  c2a942772fc73a7b6f48766982f12fbc3dee4f71 (commit)
       via  7a9a5c138a9d226632a4b8c2fa16e4ba22c42697 (commit)
       via  7717d6fab8dd9168864990714574a82aa85f7229 (commit)
      from  d4582ca1b9a2d117f6f8db8fc5963c27f8c1fad4 (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 c2a942772fc73a7b6f48766982f12fbc3dee4f71
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 15 16:28:26 2010 +0200

    mh: Add new tests.
    
    * mh/mh_init.c (mh_install): Exit with code 1 on errors.
    * mh/tests/install-mh.at: New file.
    * mh/tests/pick.at: New file.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add install-mh.at, pick.at.
    * mh/tests/testsuite.at: Include install-mh.at and pick.at.

commit 7a9a5c138a9d226632a4b8c2fa16e4ba22c42697
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 15 13:19:09 2010 +0200

    mh: improve GNU option parser and help output.
    
    * mh/mh_argp.c (mh_argp_children): Set group number -2, to place
    help output between the application help and informational options.
    * mh/mhn.c (options): Regroup options,
    * mh/pick.c: Likewise.
    
    * mh/ali.c: Reword arg docs.
    * mh/anno.c: Likewise.
    * mh/burst.c: Likewise.
    * mh/comp.c: Likewise.
    * mh/fmtcheck.c: Likewise.
    * mh/folder.c: Likewise.
    * mh/forw.c: Likewise.
    * mh/inc.c: Likewise.
    * mh/install-mh.c: Likewise.
    * mh/mark.c: Likewise.
    * mh/mh_argp.c: Likewise.
    * mh/mhl.c: Likewise.
    * mh/mhn.c: Likewise.
    * mh/mhparam.c: Likewise.
    * mh/mhpath.c: Likewise.
    * mh/pick.c: Likewise.
    * mh/refile.c: Likewise.
    * mh/repl.c: Likewise.
    * mh/rmf.c: Likewise.
    * mh/rmm.c: Likewise.
    * mh/scan.c: Likewise.
    * mh/send.c: Likewise.
    * mh/sortm.c: Likewise.
    * mh/whom.c: Likewise.

commit 7717d6fab8dd9168864990714574a82aa85f7229
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 15 12:37:11 2010 +0200

    mh: improve traditional option parser and help output.
    
    * mh/mh_getopt.h (mh_option): Move match_len to the end of the
    structure.  It should not be initialized.
    (mh_option_init): New prototype.
    
    * mh/mh_getopt.c (mh_option_init): New function.
    * mh/mh_argp.c (mh_argp_parse): Call mh_option_init.
    
    * mh/ali.c: Update mh_option declaration.
    * mh/anno.c: Likewise.
    * mh/burst.c: Likewise.
    * mh/comp.c: Likewise.
    * mh/fmtcheck.c: Likewise.
    * mh/folder.c: Likewise.
    * mh/forw.c: Likewise.
    * mh/inc.c: Likewise.
    * mh/install-mh.c: Likewise.
    * mh/mark.c: Likewise.
    * mh/mhl.c: Likewise.
    * mh/mhn.c: Likewise.
    * mh/mhparam.c: Likewise.
    * mh/mhpath.c: Likewise.
    * mh/pick.c: Likewise.
    * mh/refile.c: Likewise.
    * mh/repl.c: Likewise.
    * mh/rmf.c: Likewise.
    * mh/rmm.c: Likewise.
    * mh/scan.c: Likewise.
    * mh/send.c: Likewise.
    * mh/sortm.c: Likewise.
    * mh/whatnow.c: Likewise.
    * mh/whom.c: Likewise.

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

Summary of changes:
 mh/ali.c               |   14 +-
 mh/anno.c              |   10 +-
 mh/burst.c             |   10 +-
 mh/comp.c              |   24 ++--
 mh/fmtcheck.c          |   11 +-
 mh/folder.c            |   26 ++--
 mh/forw.c              |   32 +++---
 mh/inc.c               |   22 ++--
 mh/install-mh.c        |    7 +-
 mh/mark.c              |   14 +-
 mh/mh_argp.c           |    5 +-
 mh/mh_getopt.c         |   46 +++++++
 mh/mh_getopt.h         |    4 +-
 mh/mh_init.c           |    7 +-
 mh/mhl.c               |   16 ++--
 mh/mhn.c               |  106 +++++++++--------
 mh/mhparam.c           |    8 +-
 mh/mhpath.c            |    4 +-
 mh/pick.c              |  163 ++++++++++++++------------
 mh/refile.c            |   14 +-
 mh/repl.c              |   42 ++++----
 mh/rmf.c               |    4 +-
 mh/rmm.c               |    4 +-
 mh/scan.c              |   18 ++--
 mh/send.c              |   40 +++---
 mh/sortm.c             |   16 ++--
 mh/tests/Makefile.am   |    2 +
 mh/tests/install-mh.at |   63 ++++++++++
 mh/tests/pick.at       |  313 ++++++++++++++++++++++++++++++++++++++++++++++++
 mh/tests/testsuite.at  |    2 +
 mh/whatnow.c           |   14 +-
 mh/whom.c              |   14 +-
 32 files changed, 760 insertions(+), 315 deletions(-)
 create mode 100644 mh/tests/install-mh.at
 create mode 100644 mh/tests/pick.at

diff --git a/mh/ali.c b/mh/ali.c
index fa11429..9785574 100644
--- a/mh/ali.c
+++ b/mh/ali.c
@@ -26,7 +26,7 @@
 
 static char doc[] = N_("GNU MH ali")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("aliases ...");
+static char args_doc[] = N_("ALIAS [ALIAS...]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -45,12 +45,12 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  { "alias", 1, MH_OPT_ARG, "aliasfile" },
-  { "noalias", 3, },
-  { "list", 1, MH_OPT_BOOL },
-  { "normalize", 3, MH_OPT_BOOL },
-  { "user", 1, MH_OPT_BOOL },
-  { 0 }
+  { "alias", MH_OPT_ARG, "aliasfile" },
+  { "noalias", },
+  { "list", MH_OPT_BOOL },
+  { "normalize", MH_OPT_BOOL },
+  { "user", MH_OPT_BOOL },
+  { NULL }
 };
 
 static int list_mode;
diff --git a/mh/anno.c b/mh/anno.c
index 972268c..2e17f7e 100644
--- a/mh/anno.c
+++ b/mh/anno.c
@@ -22,7 +22,7 @@
 static char doc[] = N_("GNU MH anno")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[msg [msg...]]");
+static char args_doc[] = N_("[MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -42,10 +42,10 @@ static struct argp_option options[] = {
 };
 
 struct mh_option mh_option[] = {
-  {"inplace",   1, MH_OPT_BOOL },
-  {"date",      1, MH_OPT_BOOL },
-  {"component", 1, MH_OPT_ARG, "field"},
-  {"text",      1, MH_OPT_ARG, "body"},
+  { "inplace",   MH_OPT_BOOL },
+  { "date",      MH_OPT_BOOL },
+  { "component", MH_OPT_ARG, "field" },
+  { "text",      MH_OPT_ARG, "body" },
   { NULL }
 };
 
diff --git a/mh/burst.c b/mh/burst.c
index 8dc9163..5751513 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -25,7 +25,7 @@
 static char doc[] = N_("GNU MH burst")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "[msgs]";
+static char args_doc[] = N_("[MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -50,10 +50,10 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"inplace",    1, MH_OPT_BOOL },
-  {"quiet",      1, MH_OPT_BOOL },
-  {"verbose",    1, MH_OPT_BOOL },
-  {NULL}
+  { "inplace",    MH_OPT_BOOL },
+  { "quiet",      MH_OPT_BOOL },
+  { "verbose",    MH_OPT_BOOL },
+  { NULL }
 };
 
 /* Command line switches */
diff --git a/mh/comp.c b/mh/comp.c
index 0f8830d..4def4f8 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -24,7 +24,7 @@
 static char doc[] = N_("GNU MH comp")"\v"
 N_("Options marked with `*' are not yet implemented.\n"
 "Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "[msg]";
+static char args_doc[] = N_("[MSG]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -58,17 +58,17 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"build",         1, },
-  {"file",          2, MH_OPT_ARG, "draftfile"},
-  {"form",          2, MH_OPT_ARG, "formatfile"},
-  {"draftfolder",   6, MH_OPT_ARG, "folder"},
-  {"nodraftfolder", 3, },
-  {"draftmessage",  6, },
-  {"editor",        1, MH_OPT_ARG, "program"},
-  {"noedit",        3, },
-  {"whatnowproc",   2, MH_OPT_ARG, "program"},
-  {"nowhatnowproc", 3, },
-  { 0 }
+  { "build" },
+  { "file",          MH_OPT_ARG, "draftfile" },
+  { "form",          MH_OPT_ARG, "formatfile" },
+  { "draftfolder",   MH_OPT_ARG, "folder" },
+  { "nodraftfolder" },
+  { "draftmessage" },
+  { "editor",        MH_OPT_ARG, "program" },
+  { "noedit" },
+  { "whatnowproc",   MH_OPT_ARG, "program" },
+  { "nowhatnowproc" },
+  { NULL }
 };
 
 struct mh_whatnow_env wh_env = { 0 };
diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c
index 216544d..10c0d65 100644
--- a/mh/fmtcheck.c
+++ b/mh/fmtcheck.c
@@ -21,7 +21,6 @@
 
 static char doc[] = N_("GNU MH fmtcheck")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "";
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -34,14 +33,14 @@ static struct argp_option options[] = {
   { "debug",  ARG_DEBUG, NULL,     0,
     N_("enable parser debugging output"),},
 
-  { 0 }
+  { NULL }
 };
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"form",    4,  MH_OPT_ARG, "formatfile"},
-  {"format",  5,  MH_OPT_ARG, "string"},
-  { 0 }
+  { "form",    MH_OPT_ARG, "formatfile" },
+  { "format",  MH_OPT_ARG, "string" },
+  { NULL }
 };
 
 char *format_str;
@@ -97,7 +96,7 @@ main (int argc, char **argv)
   MU_APP_INIT_NLS ();
 
   mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
+  mh_argp_parse (&argc, &argv, 0, options, mh_option, NULL, doc,
 		 opt_handler, NULL, NULL);
 
   if (format_str && mh_format_parse (format_str, &format))
diff --git a/mh/folder.c b/mh/folder.c
index 2b8f04e..57a9179 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -34,7 +34,7 @@
 
 static char doc[] = N_("GNU MH folder")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[action] [msg]");
+static char args_doc[] = N_("[ACTION] [MSG]");
 
 static struct argp_option options[] = {
   {N_("Actions are:"), 0, 0, OPTION_DOC, NULL, 0 },
@@ -83,18 +83,18 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"print",   2, 0, NULL },
-  {"list",    1, 0, NULL },
-  {"push",    2, 0, NULL },
-  {"pop",     2, 0, NULL },
-  {"all",     1, 0, NULL },
-  {"pack",    2, 0, NULL },
-  {"create",  1, MH_OPT_BOOL, NULL},
-  {"fast",    1, MH_OPT_BOOL, NULL},
-  {"header",  1, MH_OPT_BOOL, NULL},
-  {"recurse", 1, MH_OPT_BOOL, NULL},
-  {"total",   1, MH_OPT_BOOL, NULL},
-  {NULL},
+  { "print" },
+  { "list" },
+  { "push" },
+  { "pop" },
+  { "all" },
+  { "pack" },
+  { "create",  MH_OPT_BOOL },
+  { "fast",    MH_OPT_BOOL },
+  { "header",  MH_OPT_BOOL },
+  { "recurse", MH_OPT_BOOL },
+  { "total",   MH_OPT_BOOL },
+  { NULL }
 };
 
 typedef int (*folder_action) ();
diff --git a/mh/forw.c b/mh/forw.c
index 06a9de5..639706b 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -22,7 +22,7 @@
 static char doc[] = N_("GNU MH forw")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "[msgs]";
+static char args_doc[] = N_("[MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -72,21 +72,21 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"annotate",      1, MH_OPT_BOOL },
-  {"build",         1, },
-  {"form",          4, MH_OPT_ARG, "formatfile"},
-  {"format",        5,  MH_OPT_ARG, "string"},
-  {"draftfolder",   6, MH_OPT_ARG, "folder"},
-  {"nodraftfolder", 3 },
-  {"draftmessage",  6, },
-  {"editor",        1, MH_OPT_ARG, "program"},
-  {"noedit",        3, },
-  {"filter",        2, MH_OPT_ARG, "program"},
-  {"inplace",       1, MH_OPT_BOOL },
-  {"whatnowproc",   2, MH_OPT_ARG, "program"},
-  {"nowhatnowproc", 3 },
-  {"mime",          2, MH_OPT_BOOL, NULL},
-  {NULL}
+  { "annotate",      MH_OPT_BOOL },
+  { "build" },
+  { "form",          MH_OPT_ARG, "formatfile"},
+  { "format",        MH_OPT_ARG, "string"},
+  { "draftfolder",   MH_OPT_ARG, "folder"},
+  { "nodraftfolder" },
+  { "draftmessage" },
+  { "editor",        MH_OPT_ARG, "program"},
+  { "noedit" },
+  { "filter",        MH_OPT_ARG, "program"},
+  { "inplace",       MH_OPT_BOOL },
+  { "whatnowproc",   MH_OPT_ARG, "program"},
+  { "nowhatnowproc" },
+  { "mime",          MH_OPT_BOOL },
+  { NULL }
 };
 
 enum encap_type {
diff --git a/mh/inc.c b/mh/inc.c
index d2fb0a3..dde43fe 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -21,7 +21,7 @@
 
 static char doc[] = N_("GNU MH inc")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+folder]");
+static char args_doc[] = N_("[+FOLDER]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -52,16 +52,16 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"audit",     5, MH_OPT_ARG, "audit-file" },
-  {"noaudit",   3, 0, },
-  {"changecur", 1, MH_OPT_BOOL},
-  {"file",      2, MH_OPT_ARG, "input-file"},
-  {"form",      4, MH_OPT_ARG, "format-file"},
-  {"format",    5, MH_OPT_ARG, "string"},
-  {"truncate",  2, MH_OPT_BOOL, },
-  {"width",     1, MH_OPT_ARG, "number"},
-  {"quiet",     1, 0, },
-  { 0 }
+  { "audit",     MH_OPT_ARG, "audit-file" },
+  { "noaudit" },
+  { "changecur", MH_OPT_BOOL },
+  { "file",      MH_OPT_ARG, "input-file" },
+  { "form",      MH_OPT_ARG, "format-file" },
+  { "format",    MH_OPT_ARG, "string" },
+  { "truncate",  MH_OPT_BOOL },
+  { "width",     MH_OPT_ARG, "number" },
+  { "quiet" },
+  { NULL }
 };
 
 static char *format_str = mh_list_format;
diff --git a/mh/install-mh.c b/mh/install-mh.c
index 5b48244..8d33319 100644
--- a/mh/install-mh.c
+++ b/mh/install-mh.c
@@ -19,7 +19,6 @@
 
 static char doc[] = N_("GNU MH install-mh")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "";
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -29,8 +28,8 @@ static struct argp_option options[] = {
 };
 
 struct mh_option mh_option[] = {
-  {"auto",     1, 0, },
-  {"compat",     1, 0, },
+  { "auto" },
+  { "compat" },
   { NULL }
 };
 
@@ -65,7 +64,7 @@ main (int argc, char **argv)
 
   mh_argp_init ();
   mh_auto_install = 0;
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
+  mh_argp_parse (&argc, &argv, 0, options, mh_option, NULL, doc,
 		 opt_handler, NULL, NULL);
 
   name = getenv ("MH");
diff --git a/mh/mark.c b/mh/mark.c
index ec2e46e..03588bf 100644
--- a/mh/mark.c
+++ b/mh/mark.c
@@ -19,7 +19,7 @@
 
 static char doc[] = N_("GNU MH mark")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "[msgs...]";
+static char args_doc[] = N_("[MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -43,12 +43,12 @@ static struct argp_option options[] = {
 };
 
 struct mh_option mh_option[] = {
-  {"sequence", 1, },
-  {"add", 1, }, 
-  {"delete", 1, },
-  {"list", 1, },
-  {"public", 1, MH_OPT_BOOL },
-  {"zero", 1, MH_OPT_BOOL },
+  { "sequence" },
+  { "add" }, 
+  { "delete" },
+  { "list" },
+  { "public", MH_OPT_BOOL },
+  { "zero", MH_OPT_BOOL },
   { NULL }
 };
 
diff --git a/mh/mh_argp.c b/mh/mh_argp.c
index dff019b..b1b8d4b 100644
--- a/mh/mh_argp.c
+++ b/mh/mh_argp.c
@@ -180,7 +180,7 @@ struct argp mu_debug_argp = {
 };
 
 struct argp_child mh_argp_children[] = {
-  { &mu_debug_argp, 0, N_("Global debugging settings"), 0 },
+  { &mu_debug_argp, 0, N_("Global debugging settings"), -2 },
   { NULL }
 };
 
@@ -201,7 +201,8 @@ mh_argp_parse (int *pargc, char **pargv[],
 
   mu_set_program_name ((*pargv)[0]);
   mh_init ();
-  
+
+  mh_option_init (mh_option);
   memset (&argp, 0, sizeof (argp));
   argp.options = option;
   argp.parser = parse_opt;
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index a90d943..2bed55c 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -153,6 +153,52 @@ mh_help (struct mh_option *mh_opt, const char *doc)
             mu_program_name);
 }
 
+
+static int
+optcmp (const void *a, const void *b)
+{
+  struct mh_option const *opta = a, *optb = b;
+  return strcmp (opta->opt, optb->opt);
+}
+
+void
+mh_option_init (struct mh_option *opt)
+{
+  size_t count, i;
+
+  /* Count number of elements and initialize minimum abbreviation
+     lengths to 1. */
+  for (count = 0; opt[count].opt; count++)
+    opt[count].match_len = 1;
+  /* Sort them alphabetically */
+  qsort (opt, count, sizeof (opt[0]), optcmp);
+  /* Determine minimum abbreviations */
+  for (i = 0; i < count; i++)
+    {
+      const char *sample = opt[i].opt;
+      size_t sample_len = strlen (sample);
+      size_t minlen = opt[i].match_len;
+      size_t j;
+      
+      for (j = i + 1; j < count; j++)
+	{
+	  size_t len = strlen (opt[j].opt);
+	  if (len >= minlen && memcmp (opt[j].opt, sample, minlen) == 0)
+	    do
+	      {
+		minlen++;
+		opt[j].match_len = minlen;
+		if (minlen == sample_len)
+		  break;
+	      }
+	    while (len >= minlen && memcmp (opt[j].opt, sample, minlen) == 0);
+	  else
+	    break;
+	}
+      opt[i].match_len = minlen;
+    }
+}
+
 void
 mh_opt_notimpl (const char *name)
 {
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index b66026c..7312250 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -25,9 +25,9 @@
 struct mh_option
 {
   char *opt;
-  int match_len;
   int flags;
   char *arg;
+  size_t match_len;
 };
 
 struct mh_argp_data
@@ -183,6 +183,8 @@ enum mh_arg {
 
 extern void (*mh_help_hook) (void);
 
+void mh_option_init (struct mh_option *opt);
+
 void mh_argp_init (void);
 void mh_argv_preproc (int argc, char **argv, struct mh_argp_data *data);
 int mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc);
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 7b2098f..9913a98 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -808,13 +808,12 @@ mh_install (char *name, int automode)
   else if ((st.st_mode & S_IFREG) || (st.st_mode & S_IFLNK)) 
     {
       mu_error(_("You already have an MH profile, use an editor to modify it"));
-      exit (0);
+      exit (1);
     }
   else
     {
-      mu_error(_("You already have file %s which is not a regular file or a symbolic link.\n"
-		 "Please remove it and try again"),
-	       name);
+      mu_error (_("You already have file %s which is not a regular file or a symbolic link."), name);
+      mu_error (_("Please remove it and try again"));
       exit (1);
     }
 }
diff --git a/mh/mhl.c b/mh/mhl.c
index 9b5abcb..1d6635f 100644
--- a/mh/mhl.c
+++ b/mh/mhl.c
@@ -23,7 +23,7 @@
 
 static char doc[] = N_("GNU MH mhl")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[files]");
+static char args_doc[] = N_("[FILE [FILE...]]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -50,13 +50,13 @@ static struct argp_option options[] = {
    
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  { "bell",       1,  MH_OPT_BOOL },
-  { "clear",      1,  MH_OPT_BOOL },
-  { "form",       1,  MH_OPT_ARG, "formatfile"},
-  { "width",      1,  MH_OPT_ARG, "number"},
-  { "length",     1,  MH_OPT_ARG, "number"},
-  { "moreproc",   1,  MH_OPT_ARG, "program"},
-  { "nomoreproc", 3, },
+  { "bell",       MH_OPT_BOOL },
+  { "clear",      MH_OPT_BOOL },
+  { "form",       MH_OPT_ARG, "formatfile"},
+  { "width",      MH_OPT_ARG, "number"},
+  { "length",     MH_OPT_ARG, "number"},
+  { "moreproc",   MH_OPT_ARG, "program"},
+  { "nomoreproc" },
   { NULL }
 };
 
diff --git a/mh/mhn.c b/mh/mhn.c
index 238761d..d66ef9b 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -27,82 +27,88 @@
 static char doc[] = N_("GNU MH mhn")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "[msgs]";
+static char args_doc[] = N_("[MSGLIST]");
 
 static struct argp_option options[] = {
   {"folder",       ARG_FOLDER,       N_("FOLDER"), 0,
    N_("specify folder to operate upon"), 0},
   {"file",         ARG_FILE,         N_("FILE"),   0,
    N_("specify file to operate upon"), 0},
-  
-  {N_("MIME editing options"),   0,  NULL, OPTION_DOC,  NULL, 5},
+
+#define GRID 10
+  {N_("MIME editing options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
   {"compose",      ARG_COMPOSE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("compose the MIME message (default)"), 6},
-  {"nocompose",    ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN, "", 6},
-  
-  {N_("Listing options"),   0,  NULL, OPTION_DOC,  NULL, 0},
+   N_("compose the MIME message (default)"), GRID+1},
+  {"nocompose",    ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN, "", GRID+1},
+#undef GRID
+#define GRID 20  
+  {N_("Listing options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
   {"list",         ARG_LIST,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("list the table of contents"), 11 },
-  {"nolist",       ARG_NOLIST,       NULL, OPTION_HIDDEN, "", 11 },
+   N_("list the table of contents"), GRID+1 },
+  {"nolist",       ARG_NOLIST,       NULL, OPTION_HIDDEN, "", GRID+1 },
   {"headers",      ARG_HEADER,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print the banner above the listing"), 12},
-  {"noheaders",    ARG_NOHEADERS,    NULL, OPTION_HIDDEN, "", 12 },
+   N_("print the banner above the listing"), GRID+1 },
+  {"noheaders",    ARG_NOHEADERS,    NULL, OPTION_HIDDEN, "", GRID+1 },
   {"realsize",     ARG_REALSIZE,     N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("list the decoded sizes"), 12},
-  {"norealsize",   ARG_NOREALSIZE,   NULL, OPTION_HIDDEN, "", 12 },
-
-  {N_("Display options"),   0,  NULL, OPTION_DOC,  NULL, 20},
+   N_("list the decoded sizes"), GRID+1 },
+  {"norealsize",   ARG_NOREALSIZE,   NULL, OPTION_HIDDEN, "", GRID+1 },
+#undef GRID
+#define GRID 40
+  {N_("Display options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
   {"show",         ARG_SHOW,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("display the contents of the messages"), 21},
-  {"noshow",       ARG_NOSHOW,       NULL, OPTION_HIDDEN, "", 21 },
+   N_("display the contents of the messages"), GRID+1},
+  {"noshow",       ARG_NOSHOW,       NULL, OPTION_HIDDEN, "", GRID+1 },
   {"serialonly",   ARG_SERIALONLY,   N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* display messages serially"), 22},
-  {"noserialonly", ARG_NOSERIALONLY, NULL, OPTION_HIDDEN, "", 22 },
+   N_("* display messages serially"), GRID+1},
+  {"noserialonly", ARG_NOSERIALONLY, NULL, OPTION_HIDDEN, "", GRID+1 },
   {"form",         ARG_FORM,         N_("FILE"), 0,
-   N_("read mhl format from FILE"), 22},
+   N_("read mhl format from FILE"), GRID+1},
   {"pause",        ARG_PAUSE,        N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("pause prior to displaying content"), 22},
-  {"nopause",      ARG_NOPAUSE,      NULL, OPTION_HIDDEN, "", 22 },
-   
-  {N_("Saving options"),   0,  NULL, OPTION_DOC,  NULL, 30},
+   N_("pause prior to displaying content"), GRID+1},
+  {"nopause",      ARG_NOPAUSE,      NULL, OPTION_HIDDEN, "", GRID+1 },
+#undef GRID
+#define GRID 50
+  {N_("Saving options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
   {"store",        ARG_STORE,        N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("store the contents of the messages on disk"), 31},
-  {"nostore",      ARG_NOSTORE,      NULL, OPTION_HIDDEN, "", 31 },
+   N_("write extracted message parts to disk"), GRID+1},
+  {"nostore",      ARG_NOSTORE,      NULL, OPTION_HIDDEN, "", GRID+1 },
   {"auto",         ARG_AUTO,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("use filenames from the content headers"), 31},
-  {"noauto",       ARG_NOAUTO,       NULL, OPTION_HIDDEN, "", 31 },
+   N_("use filenames from the content headers"), GRID+1},
+  {"noauto",       ARG_NOAUTO,       NULL, OPTION_HIDDEN, "", GRID+1 },
   {"charset",      ARG_CHARSET,      N_("NAME"), 0,
-   N_("use this charset to represent attachment file names"), 31},
-  
-  {N_("Other options"),    0,  NULL, OPTION_DOC,  NULL, 40},
+   N_("use this charset to represent attachment file names"), GRID+1},
+#undef GRID
+#define GRID 60
+  {N_("Other options"),    0,  NULL, OPTION_DOC,  NULL, GRID},
   {"part",         ARG_PART,         N_("PART"), 0,
-   N_("limit the scope of the operation to the given part"), 41},
+   N_("limit the scope of the operation to the given part"), GRID+1},
   {"type",         ARG_TYPE,         N_("CONTENT"), 0,
-   N_("operate on message part with given multipart content"), 41 },
+   N_("operate on message part with given multipart content"), GRID+1 },
   {"verbose",      ARG_VERBOSE,     N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print additional information"), 41 },
-  {"noverbose",    ARG_NOVERBOSE,   NULL, OPTION_HIDDEN, "", 41 },
+   N_("print additional information"), GRID+1 },
+  {"noverbose",    ARG_NOVERBOSE,   NULL, OPTION_HIDDEN, "", GRID+1 },
   {"quiet",        ARG_QUIET, 0, 0,
-   N_("be quiet")},
+   N_("be quiet"), GRID+1},
+#undef GRID
   {NULL}
 };
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"file",          2, 0, "filename"},
-  {"list",          1, MH_OPT_BOOL, NULL},
-  {"headers",       1, MH_OPT_BOOL, NULL},
-  {"realsize",      1, MH_OPT_BOOL, NULL},
-  {"show",          2, MH_OPT_BOOL, NULL},
-  {"serialonly",    2, MH_OPT_BOOL, NULL},
-  {"form",          2, 0, "formfile"},
-  {"pause",         3, MH_OPT_BOOL, NULL},
-  {"store",         1, MH_OPT_BOOL, NULL},
-  {"auto",          1, MH_OPT_BOOL, NULL},
-  {"part",          3, 0, "part"},
-  {"type",          1, 0, "type"},
-  {"verbose",       1, MH_OPT_BOOL, NULL},
-  {NULL}
+  { "file",          MH_OPT_ARG, "filename" },
+  { "list",          MH_OPT_BOOL },
+  { "headers",       MH_OPT_BOOL },
+  { "realsize",      MH_OPT_BOOL },
+  { "show",          MH_OPT_BOOL },
+  { "serialonly",    MH_OPT_BOOL },
+  { "form",          MH_OPT_ARG, "formfile" },
+  { "pause",         MH_OPT_BOOL },
+  { "store",         MH_OPT_BOOL },
+  { "auto",          MH_OPT_BOOL },
+  { "part",          MH_OPT_ARG, "part" },
+  { "type",          MH_OPT_ARG, "type" },
+  { "verbose",       MH_OPT_BOOL },
+  { NULL }
 };
 
 typedef struct _msg_part *msg_part_t;
diff --git a/mh/mhparam.c b/mh/mhparam.c
index 9149c1c..1ca2aad 100644
--- a/mh/mhparam.c
+++ b/mh/mhparam.c
@@ -21,7 +21,7 @@
 
 static char doc[] = N_("GNU MH mhparam")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[components]");
+static char args_doc[] = N_("[COMPONENT [COMPONENT...]]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -34,9 +34,9 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  { "all", 1, 0 },
-  { "component", 1, MH_OPT_BOOL},
-  { 0 }
+  { "all" },
+  { "component", MH_OPT_BOOL },
+  { NULL }
 };
 
 static int display_all;
diff --git a/mh/mhpath.c b/mh/mhpath.c
index 5051418..f3b8256 100644
--- a/mh/mhpath.c
+++ b/mh/mhpath.c
@@ -21,7 +21,7 @@
 
 static char doc[] = N_("GNU MH mhpath")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+folder] [msgs]");
+static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -32,7 +32,7 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  { 0 }
+  { NULL }
 };
 
 static error_t
diff --git a/mh/pick.c b/mh/pick.c
index 91d202b..0bbf3ba 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -37,93 +37,106 @@ letter or followed by a colon, e.g.:\n\
   --user-agent: Mailutils\n\
 \n\
 Use -help to obtain a list of traditional MH options.");
-static char args_doc[] = N_("[messages]");
+static char args_doc[] = N_("[MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon"), 0},
-
-  {N_("Specifying search patterns:"), 0,  NULL, OPTION_DOC,  NULL, 0},
-  {"component", ARG_COMPONENT, N_("FIELD"), 0,
-   N_("search the named header field"), 1},
-  {"pattern", ARG_PATTERN, N_("STRING"), 0,
-   N_("set pattern to look for"), 1},
-  {"search",  0, NULL, OPTION_ALIAS, NULL, 1},
-  {"cflags",  ARG_CFLAGS,  N_("STRING"), 0,
-   N_("flags controlling the type of regular expressions. STRING must consist of one or more of the following letters: B=basic, E=extended, I=ignore case, C=case sensitive. Default is \"EI\". The flags remain in effect until the next occurrence of --cflags option. The option must occur right before --pattern or --component option (or its alias).") },
-  {"cc",      ARG_CC,      N_("STRING"), 0,
-   N_("same as --component cc --pattern STRING"), 1},
-  {"date",    ARG_DATE,    N_("STRING"), 0,
-   N_("same as --component date --pattern STRING"), 1},
-  {"from",    ARG_FROM,    N_("STRING"), 0,
-   N_("same as --component from --pattern STRING"), 1},
-  {"subject", ARG_SUBJECT, N_("STRING"), 0,
-   N_("same as --component subject --pattern STRING"), 1},
-  {"to",      ARG_TO,      N_("STRING"), 0,
-   N_("same as --component to --pattern STRING"), 1},
-
-  {N_("Date constraint operations:"), 0,  NULL, OPTION_DOC, NULL, 1},
-  {"datefield",ARG_DATEFIELD, N_("STRING"), 0,
-   N_("search in the named date header field (default is `Date:')"), 2},
-  {"after",    ARG_AFTER,     N_("DATE"), 0,
-   N_("match messages after the given date"), 2},
-  {"before",   ARG_BEFORE,    N_("DATE"), 0,
-   N_("match messages before the given date"), 2},
-
-  {N_("Logical operations and grouping:"), 0, NULL, OPTION_DOC, NULL, 2},
-  {"and",     ARG_AND,    NULL, 0,
-   N_("logical AND (default)"), 3 },
-  {"or",      ARG_OR,     NULL, 0,
-   N_("logical OR"), 3 },
-  {"not",     ARG_NOT,    NULL, 0,
-   N_("logical NOT"), 3},
-  {"lbrace",  ARG_LBRACE, NULL, 0,
-   N_("open group"), 3},
-  {"(",       0, NULL, OPTION_ALIAS, NULL, 3},
-  {"rbrace",  ARG_RBRACE, NULL, 0,
-   N_("close group"), 3},
-  {")",       0, NULL, OPTION_ALIAS, NULL, 3},
-
-  {N_("Operations over the selected messages:"), 0, NULL, OPTION_DOC, NULL, 3},
-  {"list",   ARG_LIST,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("list the numbers of the selected messages (default)"), 4},
-  {"nolist", ARG_NOLIST,     NULL, OPTION_HIDDEN, "", 4 },
-  {"sequence", ARG_SEQUENCE,  N_("NAME"), 0,
-   N_("add matching messages to the given sequence"), 4},
-  {"public", ARG_PUBLIC, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("create public sequence"), 4},
-  {"nopublic", ARG_NOPUBLIC, NULL, OPTION_HIDDEN, "", 4 },
-  {"zero",     ARG_ZERO,     N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("empty the sequence before adding messages"), 4},
-  {"nozero", ARG_NOZERO, NULL, OPTION_HIDDEN, "", 4 },
-  {NULL},
+#define GRID 10
+  { "folder",  ARG_FOLDER, N_("FOLDER"), 0,
+    N_("specify folder to operate upon"), GRID },
+#undef GRID
+
+#define GRID 20
+  { N_("Search patterns"), 0,  NULL, OPTION_DOC,  NULL, GRID },
+  { "component", ARG_COMPONENT, N_("FIELD"), 0,
+    N_("search the named header field"), GRID+1},
+  { "pattern", ARG_PATTERN, N_("STRING"), 0,
+    N_("set pattern to look for"), GRID+1 },
+  { "search",  0, NULL, OPTION_ALIAS, NULL, GRID+1 },
+  { "cflags",  ARG_CFLAGS,  N_("STRING"), 0,
+    N_("flags controlling the type of regular expressions. STRING must consist of one or more of the following letters: B=basic, E=extended, I=ignore case, C=case sensitive. Default is \"EI\". The flags remain in effect until the next occurrence of --cflags option. The option must occur right before --pattern or --component option (or its alias)."), GRID+1 },
+  { "cc",      ARG_CC,      N_("STRING"), 0,
+    N_("same as --component cc --pattern STRING"), GRID+1 },
+  { "date",    ARG_DATE,    N_("STRING"), 0,
+    N_("same as --component date --pattern STRING"), GRID+1 },
+  { "from",    ARG_FROM,    N_("STRING"), 0,
+    N_("same as --component from --pattern STRING"), GRID+1 },
+  { "subject", ARG_SUBJECT, N_("STRING"), 0,
+    N_("same as --component subject --pattern STRING"), GRID+1 },
+  { "to",      ARG_TO,      N_("STRING"), 0,
+    N_("same as --component to --pattern STRING"), GRID+1 },
+#undef GRID
+
+#define GRID 30  
+  { N_("Date constraint operations"), 0,  NULL, OPTION_DOC, NULL, GRID },
+  { "datefield",ARG_DATEFIELD, N_("STRING"), 0,
+    N_("search in the named date header field (default is `Date:')"), GRID+1 },
+  { "after",    ARG_AFTER,     N_("DATE"), 0,
+    N_("match messages after the given date"), GRID+1 },
+  { "before",   ARG_BEFORE,    N_("DATE"), 0,
+    N_("match messages before the given date"), GRID+1 },
+#undef GRID
+
+#define GRID 40
+  { N_("Logical operations and grouping"), 0, NULL, OPTION_DOC, NULL, GRID },
+  { "and",     ARG_AND,    NULL, 0,
+    N_("logical AND (default)"), GRID+1 },
+  { "or",      ARG_OR,     NULL, 0,
+    N_("logical OR"), GRID+1 },
+  { "not",     ARG_NOT,    NULL, 0,
+    N_("logical NOT"), GRID+1 },
+  { "lbrace",  ARG_LBRACE, NULL, 0,
+    N_("open group"), GRID+1 },
+  { "(",       0, NULL, OPTION_ALIAS, NULL, GRID+1 },
+  { "rbrace",  ARG_RBRACE, NULL, 0,
+    N_("close group"), GRID+1},
+  { ")",       0, NULL, OPTION_ALIAS, NULL, GRID+1 },
+#undef GRID
+
+#define GRID 50
+  { N_("Operations over the selected messages"), 0, NULL, OPTION_DOC, NULL,
+    GRID },
+  { "list",   ARG_LIST,       N_("BOOL"), OPTION_ARG_OPTIONAL,
+    N_("list the numbers of the selected messages (default)"), GRID+1 },
+  { "nolist", ARG_NOLIST,     NULL, OPTION_HIDDEN, "", GRID+1 },
+  { "sequence", ARG_SEQUENCE,  N_("NAME"), 0,
+    N_("add matching messages to the given sequence"), GRID+1 },
+  { "public", ARG_PUBLIC, N_("BOOL"), OPTION_ARG_OPTIONAL,
+    N_("create public sequence"), GRID+1 },
+  { "nopublic", ARG_NOPUBLIC, NULL, OPTION_HIDDEN, "", GRID+1 },
+  { "zero",     ARG_ZERO,     N_("BOOL"), OPTION_ARG_OPTIONAL,
+    N_("empty the sequence before adding messages"), GRID+1 },
+  { "nozero", ARG_NOZERO, NULL, OPTION_HIDDEN, "", GRID+1 },
+#undef GRID
+
+  { NULL }
+  
 };
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"component", 1,  0, "field" },
-  {"pattern",   1,  0, "pattern" },
-  {"search",    1,  0, "pattern" },
-  {"cc",        1,  0, "pattern" },
-  {"date",      1,  0, "pattern" },
-  {"from",      1,  0, "pattern" },
-  {"subject",   1,  0, "pattern" },
-  {"to",        1,  0, "pattern" },
-  {"datefield", 1,  0, "field" },
-  {"after",     1,  0, "date" },
-  {"before",    1,  0, "date"},
-  {"and",       1,  0, NULL },
-  {"or",        1,  0, NULL }, 
-  {"not",       1,  0, NULL },
-  {"lbrace",    1,  0, NULL },
-  {"rbrace",    1,  0, NULL },
-
-  {"list",      1,  MH_OPT_BOOL, },
-  {"sequence",  1,  0, NULL },
-  {"public",    1,  MH_OPT_BOOL },
-  {"zero",      1,  MH_OPT_BOOL },
-  {NULL}
+  { "component", MH_OPT_ARG, "field" },
+  { "pattern",   MH_OPT_ARG, "pattern" },
+  { "search",    MH_OPT_ARG, "pattern" },
+  { "cc",        MH_OPT_ARG, "pattern" },
+  { "date",      MH_OPT_ARG, "pattern" },
+  { "from",      MH_OPT_ARG, "pattern" },
+  { "subject",   MH_OPT_ARG, "pattern" },
+  { "to",        MH_OPT_ARG, "pattern" },
+  { "datefield", MH_OPT_ARG, "field" },
+  { "after",     MH_OPT_ARG, "date" },
+  { "before",    MH_OPT_ARG, "date" },
+  { "and" },
+  { "or" }, 
+  { "not" },
+  { "lbrace" },
+  { "rbrace" },
+
+  { "list",      MH_OPT_BOOL },
+  { "sequence",  MH_OPT_ARG, "name" },
+  { "public",    MH_OPT_BOOL },
+  { "zero",      MH_OPT_BOOL },
+  { NULL }
 };
 
 static int list = 1;
diff --git a/mh/refile.c b/mh/refile.c
index ab66730..74d47c7 100644
--- a/mh/refile.c
+++ b/mh/refile.c
@@ -27,7 +27,7 @@
 static char doc[] = N_("GNU MH refile")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("messages folder [folder...]");
+static char args_doc[] = N_("MSGLIST FOLDER [FOLDER...]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -49,12 +49,12 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"file",     2, 0, "input-file"},
-  {"draft",    1, 0, NULL },
-  {"link",     1, MH_OPT_BOOL, NULL },
-  {"preserve", 1, MH_OPT_BOOL, NULL },
-  {"src",      1, 0, "+folder" },
-  { 0 }
+  { "file",     MH_OPT_ARG, "input-file"},
+  { "draft" },
+  { "link",     MH_OPT_BOOL },
+  { "preserve", MH_OPT_BOOL },
+  { "src",      MH_OPT_ARG, "folder" },
+  { NULL }
 };
 
 int link_flag = 0;
diff --git a/mh/repl.c b/mh/repl.c
index 920c4d6..6a9d496 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -25,7 +25,7 @@
 static char doc[] = N_("GNU MH repl")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+folder] [msg]");
+static char args_doc[] = N_("[+FOLDER] [MESSAGE]");
 
 
 /* GNU options */
@@ -70,26 +70,26 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"annotate",    1, MH_OPT_BOOL },
-  {"build",       1, },
-  {"cc",          1, MH_OPT_ARG, "all/to/cc/me"},
-  {"nocc",        3, MH_OPT_ARG, "all/to/cc/me"},
-  {"form",        4, MH_OPT_ARG, "formatfile"},
-  {"width",       1, MH_OPT_ARG, "number"},
-  {"draftfolder", 6, MH_OPT_ARG, "folder"},
-  {"nodraftfolder", 3 },
-  {"draftmessage", 6, },
-  {"editor",      1, MH_OPT_ARG, "program"},
-  {"noedit",      3, },
-  {"fcc",         1, MH_OPT_ARG, "folder"},
-  {"filter",      2, MH_OPT_ARG, "program"},
-  {"format",      2, MH_OPT_BOOL },
-  {"group",       1, MH_OPT_BOOL },
-  {"inplace",     1, MH_OPT_BOOL },
-  {"query",       1, MH_OPT_BOOL },
-  {"whatnowproc", 2, MH_OPT_ARG, "program"},
-  {"nowhatnowproc", 3 },
-  { 0 }
+  { "annotate",    MH_OPT_BOOL },
+  { "build" },
+  { "cc",          MH_OPT_ARG, "all/to/cc/me"},
+  { "nocc",        MH_OPT_ARG, "all/to/cc/me"},
+  { "form",        MH_OPT_ARG, "formatfile"},
+  { "width",       MH_OPT_ARG, "number"},
+  { "draftfolder", MH_OPT_ARG, "folder"},
+  { "nodraftfolder" },
+  { "draftmessage" },
+  { "editor", MH_OPT_ARG, "program"},
+  { "noedit" },
+  { "fcc",         MH_OPT_ARG, "folder"},
+  { "filter",      MH_OPT_ARG, "program"},
+  { "format",      MH_OPT_BOOL },
+  { "group",       MH_OPT_BOOL },
+  { "inplace",     MH_OPT_BOOL },
+  { "query",       MH_OPT_BOOL },
+  { "whatnowproc", MH_OPT_ARG, "program"},
+  { "nowhatnowproc" },
+  { NULL }
 };
 
 static char default_format_str[] =
diff --git a/mh/rmf.c b/mh/rmf.c
index 8a2c60a..bf07fe4 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -30,7 +30,7 @@
 
 static char doc[] = N_("GNU MH rmf")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+folder]");
+static char args_doc[] = N_("[+FOLDER]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -47,7 +47,7 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"interactive", 1, MH_OPT_BOOL, NULL},
+  { "interactive", MH_OPT_BOOL },
   { 0 }
 };
 
diff --git a/mh/rmm.c b/mh/rmm.c
index a9bbfc8..96cb028 100644
--- a/mh/rmm.c
+++ b/mh/rmm.c
@@ -21,7 +21,7 @@
 
 static char doc[] = N_("GNU MH rmm")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+folder] [msgs]");
+static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -32,7 +32,7 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  { 0 }
+  { NULL }
 };
 
 static error_t
diff --git a/mh/scan.c b/mh/scan.c
index 3bc3816..0fe0ee4 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -28,7 +28,7 @@
 
 static char doc[] = N_("GNU MH scan")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+folder] [msgs]");
+static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -56,14 +56,14 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"clear",   1,  MH_OPT_BOOL},
-  {"form",    4,  MH_OPT_ARG, "formatfile"},
-  {"format",  5,  MH_OPT_ARG, "string"},
-  {"header",  3,  MH_OPT_BOOL},
-  {"width",   1,  MH_OPT_ARG, "number"},
-  {"reverse", 1,  MH_OPT_BOOL},
-  {"file",    4,  MH_OPT_ARG, "file"},
-  { 0 }
+  { "clear",   MH_OPT_BOOL },
+  { "form",    MH_OPT_ARG, "formatfile" },
+  { "format",  MH_OPT_ARG, "string" },
+  { "header",  MH_OPT_BOOL },
+  { "width",   MH_OPT_ARG, "number" },
+  { "reverse", MH_OPT_BOOL },
+  { "file",    MH_OPT_ARG, "file" },
+  { NULL }
 };
 
 static int clear;
diff --git a/mh/send.c b/mh/send.c
index faece4e..d717bb9 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -26,7 +26,7 @@
 static char doc[] = N_("GNU MH send")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
 Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("file [file...]");
+static char args_doc[] = N_("FILE [FILE...]");
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -79,25 +79,25 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"alias",         1, 0, "aliasfile" },
-  {"draft",         5, 0, NULL },
-  {"draftfolder",   6, 0, "folder" },
-  {"draftmessage",  6, 0, "message"},
-  {"nodraftfolder", 3, 0, NULL },
-  {"filter",        2, 0, "filterfile"},
-  {"nofilter",      3, 0, NULL },
-  {"format",        4, MH_OPT_BOOL, NULL},
-  {"forward",       4, MH_OPT_BOOL, NULL},
-  {"mime",          2, MH_OPT_BOOL, NULL},
-  {"msgid",         2, MH_OPT_BOOL, NULL},
-  {"push",          2, MH_OPT_BOOL, NULL},
-  {"preserve",      2, MH_OPT_BOOL, NULL},
-  {"keep",          1, MH_OPT_BOOL, NULL},
-  {"split",         1, 0, "seconds"},
-  {"verbose",       1, MH_OPT_BOOL, NULL},
-  {"watch",         2, MH_OPT_BOOL, NULL},
-  {"width",         2, 0, NULL },
-  { 0 }
+  { "alias",         MH_OPT_ARG, "aliasfile" },
+  { "draft" },
+  { "draftfolder",   MH_OPT_ARG, "folder" },
+  { "draftmessage",  MH_OPT_ARG, "message" },
+  { "nodraftfolder" },
+  { "filter",        MH_OPT_ARG, "filterfile" },
+  { "nofilter" },
+  { "format",        MH_OPT_BOOL },
+  { "forward",       MH_OPT_BOOL },
+  { "mime",          MH_OPT_BOOL },
+  { "msgid",         MH_OPT_BOOL },
+  { "push",          MH_OPT_BOOL },
+  { "preserve",      MH_OPT_BOOL },
+  { "keep",          MH_OPT_BOOL },
+  { "split",         MH_OPT_ARG, "seconds" },
+  { "verbose",       MH_OPT_BOOL },
+  { "watch",         MH_OPT_BOOL },
+  { "width" },
+  { NULL }
 };
 
 static int use_draft;            /* Use the prepared draft */
diff --git a/mh/sortm.c b/mh/sortm.c
index 1e5bacc..45ad51b 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -24,7 +24,7 @@
 
 static char doc[] = N_("GNU MH sortm")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[msgs]");
+static char args_doc[] = N_("[MSGLIST]");
 
 #define ARG_QUICKSORT 1024
 #define ARG_SHELL     1025
@@ -78,13 +78,13 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"datefield",     1, 0, "field" },
-  {"nodatefield",   3, 0, 0 },
-  {"textfield",     1, 0, "field" },
-  {"notextfield",   3, 0, 0 },
-  {"limit",         1, 0, "days" },
-  {"nolimit",       3, 0, 0 },
-  {"verbose",       1, MH_OPT_BOOL, NULL},
+  { "datefield",     MH_OPT_ARG, "field" },
+  { "nodatefield" },
+  { "textfield",     MH_OPT_ARG, "field" },
+  { "notextfield" },
+  { "limit",         MH_OPT_ARG, "days" },
+  { "nolimit" },
+  { "verbose",       MH_OPT_BOOL },
   { NULL },
 };
 
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 2006a35..7429b7a 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -42,10 +42,12 @@ TESTSUITE_AT = \
  anno.at\
  folder.at\
  inc.at\
+ install-mh.at\
  mark.at\
  mhl.at\
  mhparam.at\
  mhpath.at\
+ pick.at\
  scan.at\
  refile.at\
  rmf.at\
diff --git a/mh/tests/install-mh.at b/mh/tests/install-mh.at
new file mode 100644
index 0000000..05abaae
--- /dev/null
+++ b/mh/tests/install-mh.at
@@ -0,0 +1,63 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([install-mh -auto])
+AT_KEYWORDS([install-mh install-mh00])
+
+AT_CHECK([
+mkdir home
+dir=`cd home; pwd`
+HOME=$dir MH=$dir/mh_profile install-mh -auto || exit $?
+find home
+HOME=$dir MH=$dir/mh_profile install-mh -auto 2>errout
+echo $?
+cat errout
+],
+[0],
+[I'm going to create the standard MH path for you.
+home
+home/Mail
+home/Mail/context
+home/Mail/inbox
+home/mh_profile
+1
+install-mh: You already have an MH profile, use an editor to modify it
+])
+
+AT_CLEANUP
+
+# --------------------------------------------------
+AT_SETUP([install-mh with invalid profile])
+AT_KEYWORDS([install-mh install-mh01])
+
+AT_CHECK([
+mkdir home
+dir=`cd home; pwd`
+mkdir $dir/mh_profile
+HOME=$dir MH=$dir/mh_profile install-mh -auto 2>errout
+code=$?
+cat errout | sed 's|[[^ ][^ ]*]/mh_profile|mh_profile|' >&2
+exit $code
+],
+[1],
+[],
+[install-mh: You already have file mh_profile which is not a regular file or a symbolic link.
+install-mh: Please remove it and try again
+])
+
+AT_CLEANUP
+
+# End of install-mh.at
diff --git a/mh/tests/pick.at b/mh/tests/pick.at
new file mode 100644
index 0000000..7658e3f
--- /dev/null
+++ b/mh/tests/pick.at
@@ -0,0 +1,313 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef[MH_KEYWORDS],[pick])
+
+MH_CHECK([pick -from],[pick00 pick-from],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -from dormouse
+],
+[0],
+[17
+31
+49
+61
+65
+67
+69
+77
+79
+81
+83
+88
+89
+91
+92
+])
+
+MH_CHECK([pick -from -sequence],[pick01 pick-from-sequence],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -from dormouse -sequence dormouse || exit $?
+sed -n '/^dormouse:/{s/  */ /g;s/ $//;p}' Mail/inbox/.mh_sequences
+],
+[0],
+[dormouse: 17 31 49 61 65 67 69 77 79 81 83 88 89 91 92
+])
+
+MH_CHECK([pick -search],[pick02 pick-search],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -search 'Why not'
+],
+[0],
+[91
+])
+
+MH_CHECK([pick -search regex],[pick03 pick-search-regex],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -search 'I.*think'
+],
+[0],
+[36
+86
+93
+])
+
+MH_CHECK([pick -subject -from],[pick04 pick-subject-from],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -subject Story -from Dormouse
+],
+[0],
+[61
+65
+67
+69
+77
+79
+81
+83
+88
+89
+91
+92
+])
+
+MH_CHECK([pick -subject -and -from],[pick05 pick-subject-and-from],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -subject Story -and -from Dormouse
+],
+[0],
+[61
+65
+67
+69
+77
+79
+81
+83
+88
+89
+91
+92
+])
+
+MH_CHECK([pick -subject -or -from],[pick06 pick-subject-or-from],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -subject Story -or -from Dormouse
+],
+[0],
+[17
+31
+49
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+76
+77
+78
+79
+80
+81
+82
+83
+85
+86
+87
+88
+89
+90
+91
+92
+93
+])
+
+MH_CHECK([pick -- default precedence],[pick07 pick-subject-and-from-or-from],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -subject Story -and -from Dormouse -or -from Alice
+],
+[0],
+[2
+4
+6
+8
+10
+12
+14
+20
+25
+27
+29
+33
+36
+38
+40
+43
+45
+47
+51
+53
+55
+57
+59
+61
+63
+65
+66
+67
+68
+69
+70
+72
+74
+76
+77
+78
+79
+80
+81
+82
+83
+85
+87
+88
+89
+90
+91
+92
+93
+95
+])
+
+MH_CHECK([pick -- explicit precedence (1)],[pick08 pick-expl-1],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -lbrace -subject Story -and -from Dormouse -rbrace -or -from Alice
+],
+[0],
+[2
+4
+6
+8
+10
+12
+14
+20
+25
+27
+29
+33
+36
+38
+40
+43
+45
+47
+51
+53
+55
+57
+59
+61
+63
+65
+66
+67
+68
+69
+70
+72
+74
+76
+77
+78
+79
+80
+81
+82
+83
+85
+87
+88
+89
+90
+91
+92
+93
+95
+])
+
+MH_CHECK([pick -- explicit precedence (2)],[pick09 pick-expl-2],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+echo "cur: 1" > Mail/inbox/.mh_sequences
+pick -subject Story -and -lbrace -from Dormouse -or -from Alice -rbrace
+],
+[0],
+[59
+61
+63
+65
+66
+67
+68
+69
+70
+76
+77
+78
+79
+80
+81
+82
+83
+85
+87
+88
+89
+90
+91
+92
+93
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of pick.at
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index 86bc7ba..bf19a5b 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -41,6 +41,7 @@ AT_CLEANUP
 
 AT_INIT
 
+m4_include([install-mh.at])
 m4_include([folder.at])
 m4_include([inc.at])
 m4_include([scan.at])
@@ -52,3 +53,4 @@ m4_include([refile.at])
 m4_include([mhpath.at])
 m4_include([mhl.at])
 m4_include([anno.at])
+m4_include([pick.at])
diff --git a/mh/whatnow.c b/mh/whatnow.c
index decf947..aa47a8c 100644
--- a/mh/whatnow.c
+++ b/mh/whatnow.c
@@ -38,13 +38,13 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"draftfolder", 6, MH_OPT_ARG, "folder"},
-  {"nodraftfolder", 3, },
-  {"draftmessage", 6, },
-  {"editor", 1, MH_OPT_ARG, "program"},
-  {"noedit", 3, },
-  {"prompt", 1 },
-  { 0 }
+  { "draftfolder",  MH_OPT_ARG, "folder" },
+  { "nodraftfolder" },
+  { "draftmessage" },
+  { "editor",       MH_OPT_ARG, "program" },
+  { "noedit" },
+  { "prompt" },
+  { NULL }
 };
 
 struct mh_whatnow_env wh_env = { 0 };
diff --git a/mh/whom.c b/mh/whom.c
index b943e97..5fb719e 100644
--- a/mh/whom.c
+++ b/mh/whom.c
@@ -19,7 +19,7 @@
 
 static char doc[] = N_("GNU MH whom")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = "[file]";
+static char args_doc[] = "[FILE]";
 
 /* GNU options */
 static struct argp_option options[] = {
@@ -42,12 +42,12 @@ static struct argp_option options[] = {
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
-  {"alias",         1, 0, "aliasfile" },
-  {"draft",         5, 0, NULL },
-  {"draftfolder",   6, 0, "folder" },
-  {"draftmessage",  6, 0, "message"},
-  {"nodraftfolder", 3, 0, NULL },
-  {"check",         1, MH_OPT_BOOL, NULL},
+  { "alias",         MH_OPT_ARG, "aliasfile" },
+  { "draft" },
+  { "draftfolder",   MH_OPT_ARG, "folder" },
+  { "draftmessage",  MH_OPT_ARG, "message" },
+  { "nodraftfolder" },
+  { "check",         MH_OPT_BOOL },
   {NULL}
 };
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Nov 15 13:27:09 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PI3ll-0004Z3-1v
	for mharc-commit-mailutils@gnu.org; Mon, 15 Nov 2010 13:27:09 -0500
Received: from [140.186.70.92] (port=34473 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PI3lf-0004UX-NP
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 13:27:07 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI3lV-00014q-Vr
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 13:27:03 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:58332
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI3lV-00014m-U0
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 13:26:53 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI3lV-0005cf-IE
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 18:26:53 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PI3lO-0006gE-EV
	for commit-mailutils@gnu.org; Mon, 15 Nov 2010 18:26:53 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: c2a942772fc73a7b6f48766982f12fbc3dee4f71
X-Git-Newrev: feee0bbfdb8e2136d612a74ff7d748c5f6c616ea
Message-Id: <E1PI3lO-0006gE-EV@vcs-noshell.in.savannah.gnu.org>
Date: Mon, 15 Nov 2010 18:26:47 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-193-gfeee0bb
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 15 Nov 2010 18:27:07 -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=feee0bbfdb8e2136d612a74ff7d748c5f6c616ea

The branch, master has been updated
       via  feee0bbfdb8e2136d612a74ff7d748c5f6c616ea (commit)
      from  c2a942772fc73a7b6f48766982f12fbc3dee4f71 (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 feee0bbfdb8e2136d612a74ff7d748c5f6c616ea
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 15 20:20:05 2010 +0200

    mh: fix testsuite, add new tests.
    
    * mh/ali.c (ali_print_name_list): Print -list output.
    * mh/tests/ali.at: New test case.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add ali.at
    * mh/tests/testsuite.at: Include ali.at.
    * mh/tests/anno.at: Fix MH_KEYWORDS definition.
    * mh/tests/folder.at: Likewise.
    * mh/tests/inc.at: Likewise.
    * mh/tests/mark.at: Likewise.
    * mh/tests/mhl.at: Likewise.
    * mh/tests/mhparam.at: Likewise.
    * mh/tests/mhpath.at: Likewise.
    * mh/tests/refile.at: Likewise.
    * mh/tests/rmf.at: Likewise.
    
    * mh/tests/pick.at: Fix MH_KEYWORDS definition. Add more tests.

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

Summary of changes:
 mh/ali.c              |   10 +---
 mh/tests/Makefile.am  |    1 +
 mh/tests/ali.at       |  126 +++++++++++++++++++++++++++++++++++++++++++++++++
 mh/tests/anno.at      |    2 +-
 mh/tests/folder.at    |    2 +-
 mh/tests/inc.at       |    2 +-
 mh/tests/mark.at      |    2 +-
 mh/tests/mhl.at       |    2 +-
 mh/tests/mhparam.at   |    2 +-
 mh/tests/mhpath.at    |    2 +-
 mh/tests/pick.at      |   40 ++++++++++++++--
 mh/tests/refile.at    |    2 +-
 mh/tests/rmf.at       |    2 +-
 mh/tests/rmm.at       |    2 +-
 mh/tests/scan.at      |    2 +-
 mh/tests/testsuite.at |    3 +-
 16 files changed, 179 insertions(+), 23 deletions(-)
 create mode 100644 mh/tests/ali.at

diff --git a/mh/ali.c b/mh/ali.c
index 9785574..93134dd 100644
--- a/mh/ali.c
+++ b/mh/ali.c
@@ -117,15 +117,11 @@ ali_print_name_list (mu_list_t list, int off)
   
   if (list_mode)
     {
-      mu_iterator_first (itr);
-      mu_iterator_current (itr, (void **)&item);
-      printf ("%s\n", item);
-      for (mu_iterator_next (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr))
+      for (mu_iterator_first (itr);
+	   !mu_iterator_is_done (itr); mu_iterator_next (itr))
 	{
-	  int len;
 	  mu_iterator_current (itr, (void **)&item);
-	  len = off + strlen (item);
-	  printf ("%*.*s\n", len, len, item);
+	  printf ("%s\n", item);
 	}
     }
   else
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 7429b7a..beb7689 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -39,6 +39,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
 ## ------------ ##
 
 TESTSUITE_AT = \
+ ali.at\
  anno.at\
  folder.at\
  inc.at\
diff --git a/mh/tests/ali.at b/mh/tests/ali.at
new file mode 100644
index 0000000..a75a23d
--- /dev/null
+++ b/mh/tests/ali.at
@@ -0,0 +1,126 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([MH_KEYWORDS],[ali])
+
+MH_CHECK([ali: simple aliases],[ali00],[
+AT_DATA([mh_aliases],[
+devel: gray, polak
+admin: gray, jeff
+])
+ali -a ./mh_aliases devel
+],
+[0],
+[gray, polak
+])
+
+MH_CHECK([ali: recursive aliases],[ali01],[
+AT_DATA([mh_aliases],[
+devel: gray, polak, admin
+admin: gray, jeff
+])
+ali -a ./mh_aliases devel
+],
+[0],
+[gray, polak, gray, jeff
+])
+
+MH_CHECK([ali: file inlcusion],[ali02 ali-include],[
+AT_DATA([Mail/mh_aliases2],[
+admin: gray, jeff
+])
+AT_DATA([mh_aliases],[
+devel: gray, polak, admin
+<mh_aliases2
+])
+ali -a ./mh_aliases devel
+],
+[0],
+[gray, polak, gray, jeff
+])
+
+MH_CHECK([ali: recursive inlcusion],[ali03 ali-include-recursive],[
+AT_DATA([Mail/mh_aliases2],[
+<mh_aliases
+])
+AT_DATA([Mail/mh_aliases],[
+devel: gray, polak, admin
+<mh_aliases2
+])
+ali -a ./Mail/mh_aliases devel 2>errout
+code=$?
+dir=`cd Mail;pwd`
+sed "s|$dir/||g" errout >&2
+exit $code
+],
+[0],
+[gray, polak, admin
+],
+[ali: mh_aliases2:2: recursive inclusion
+ali: mh_aliases2:2: `mh_aliases' already included at top level
+])
+
+MH_CHECK([ali: group name],[ali04 ali-group-name],[
+grep ^root: /etc/group >/dev/null || AT_SKIP_TEST
+AT_DATA([mh_aliases],[
+korzen: =root
+])
+awk -F : '$1=="root" { print $4 }' /etc/group | tr -d ' ' > expout
+ali -a ./mh_aliases korzen | tr -d ' '
+],
+[0],
+[expout])
+
+MH_CHECK([ali: group id],[ali05 ali-group-id ali-gid],[
+awk -F : '$4==0 { print $1 }' /etc/passwd > expout
+test -s expout || AT_SKIP_TEST
+name=`awk -F : '$3==0 { print $1 }' /etc/group`
+test -z "$name" && AT_SKIP_TEST
+
+AT_DATA([mh_aliases],[
+korzen: +root
+])
+# FIXME: Do I need to sort the output?
+ali -list -a ./mh_aliases korzen
+],
+[0],
+[expout])
+
+MH_CHECK([ali: everybody],[ali06 ali-everybody],[
+awk -F : '$3>200 { print $1 }' /etc/passwd > expout
+test -s expout || AT_SKIP_TEST
+AT_DATA([mh_aliases],[
+everybody: *
+])
+ali -list -a ./mh_aliases everybody
+],
+[0],
+[expout])
+
+MH_CHECK([ali: simple aliases],[ali00],[
+AT_DATA([mh_aliases],[
+devel: gray, polak
+admin: gray, jeff
+])
+ali -a ./mh_aliases devel
+],
+[0],
+[gray, polak
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of ali.at
+
diff --git a/mh/tests/anno.at b/mh/tests/anno.at
index 376d176..f935647 100644
--- a/mh/tests/anno.at
+++ b/mh/tests/anno.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[anno])
+m4_pushdef([MH_KEYWORDS],[anno])
 
 MH_CHECK([anno],[anno00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/folder.at b/mh/tests/folder.at
index c7d1d70..e7d0204 100644
--- a/mh/tests/folder.at
+++ b/mh/tests/folder.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[folder])
+m4_pushdef([MH_KEYWORDS],[folder])
 
 MH_CHECK([folder],[folder00 folder-print],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/inc.at b/mh/tests/inc.at
index 46b90a4..64bcedb 100644
--- a/mh/tests/inc.at
+++ b/mh/tests/inc.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[inc])
+m4_pushdef([MH_KEYWORDS],[inc])
 
 MH_CHECK([inc -notruncate],[inc00 inc-notruncate],[
 MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
diff --git a/mh/tests/mark.at b/mh/tests/mark.at
index 65af674..623ed3a 100644
--- a/mh/tests/mark.at
+++ b/mh/tests/mark.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[mark])
+m4_pushdef([MH_KEYWORDS],[mark])
 
 MH_CHECK([mark -add],[mark00 mark-add],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/mhl.at b/mh/tests/mhl.at
index e8f17e6..c9c99da 100644
--- a/mh/tests/mhl.at
+++ b/mh/tests/mhl.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[mhl])
+m4_pushdef([MH_KEYWORDS],[mhl])
 
 MH_CHECK([mhl],[mhl00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
diff --git a/mh/tests/mhparam.at b/mh/tests/mhparam.at
index 5e03fb2..7d602d5 100644
--- a/mh/tests/mhparam.at
+++ b/mh/tests/mhparam.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[mhparam])
+m4_pushdef([MH_KEYWORDS],[mhparam])
 
 MH_CHECK([mhparam -all],[mhparam00 mhparam-all],[
 cat >>$MH <<EOT
diff --git a/mh/tests/mhpath.at b/mh/tests/mhpath.at
index 45cef81..ba08c38 100644
--- a/mh/tests/mhpath.at
+++ b/mh/tests/mhpath.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[mhpath])
+m4_pushdef([MH_KEYWORDS],[mhpath])
 
 MH_CHECK([mhpath],[mhpath00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/pick.at b/mh/tests/pick.at
index 7658e3f..d82a3b2 100644
--- a/mh/tests/pick.at
+++ b/mh/tests/pick.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[pick])
+m4_pushdef([MH_KEYWORDS],[pick])
 
 MH_CHECK([pick -from],[pick00 pick-from],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
@@ -157,7 +157,7 @@ pick -subject Story -or -from Dormouse
 93
 ])
 
-MH_CHECK([pick -- default precedence],[pick07 pick-subject-and-from-or-from],[
+MH_CHECK([pick: default precedence],[pick07 pick-subject-and-from-or-from],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
 echo "Current-Folder: inbox" > Mail/context
 echo "cur: 1" > Mail/inbox/.mh_sequences
@@ -216,7 +216,7 @@ pick -subject Story -and -from Dormouse -or -from Alice
 95
 ])
 
-MH_CHECK([pick -- explicit precedence (1)],[pick08 pick-expl-1],[
+MH_CHECK([pick: explicit precedence (1)],[pick08 pick-expl-1],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
 echo "Current-Folder: inbox" > Mail/context
 echo "cur: 1" > Mail/inbox/.mh_sequences
@@ -275,7 +275,7 @@ pick -lbrace -subject Story -and -from Dormouse -rbrace -or -from Alice
 95
 ])
 
-MH_CHECK([pick -- explicit precedence (2)],[pick09 pick-expl-2],[
+MH_CHECK([pick: explicit precedence (2)],[pick09 pick-expl-2],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
 echo "Current-Folder: inbox" > Mail/context
 echo "cur: 1" > Mail/inbox/.mh_sequences
@@ -309,5 +309,37 @@ pick -subject Story -and -lbrace -from Dormouse -or -from Alice -rbrace
 93
 ])
 
+MH_CHECK([pick -before],[pick10 pick-before],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+echo "Current-Folder: inbox" > Mail/context
+pick -before 'Mon, 29 Jul 2002 21:00:03 +0000'
+],
+[0],
+[1
+2
+])
+
+MH_CHECK([pick --Component pattern],[pick11 pick-component],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+pick --X-Envelope-Sender hare
+],
+[0],
+[1
+3
+5
+7
+9
+11
+13
+16
+22
+24
+35
+42
+58
+62
+71
+])
+
 m4_popdef[MH_KEYWORDS])
 # End of pick.at
diff --git a/mh/tests/refile.at b/mh/tests/refile.at
index 2fee41f..deafe10 100644
--- a/mh/tests/refile.at
+++ b/mh/tests/refile.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[refile])
+m4_pushdef([MH_KEYWORDS],[refile])
 
 MH_CHECK([refile],[refile00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/rmf.at b/mh/tests/rmf.at
index 7b0b37a..9f93647 100644
--- a/mh/tests/rmf.at
+++ b/mh/tests/rmf.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[rmm])
+m4_pushdef([MH_KEYWORDS],[rmm])
 
 MH_CHECK([rmf +folder],[rmf00 rmf+folder],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/rmm.at b/mh/tests/rmm.at
index 52ece5b..850fd7a 100644
--- a/mh/tests/rmm.at
+++ b/mh/tests/rmm.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[rmm])
+m4_pushdef([MH_KEYWORDS],[rmm])
 
 MH_CHECK([rmm msg],[rmm00 rmm-msg],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/scan.at b/mh/tests/scan.at
index 1b11828..9436742 100644
--- a/mh/tests/scan.at
+++ b/mh/tests/scan.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef[MH_KEYWORDS],[scan])
+m4_pushdef([MH_KEYWORDS],[scan])
 
 MH_CHECK([scan],[scan00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index bf19a5b..a9ae3b4 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -33,7 +33,7 @@ dnl          [STDOUT = `'], [STDERR = `']
 dnl
 m4_define([MH_CHECK],[
 AT_SETUP($1)
-AT_KEYWORDS(MH_KEYWORDS[ $2])
+AT_KEYWORDS([MH_KEYWORDS $2])
 MH_SETUP
 AT_CHECK([$3],[$4],[$5],[$6])
 AT_CLEANUP
@@ -42,6 +42,7 @@ AT_CLEANUP
 AT_INIT
 
 m4_include([install-mh.at])
+m4_include([ali.at])
 m4_include([folder.at])
 m4_include([inc.at])
 m4_include([scan.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 16 03:53:00 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PIHHg-0006Pr-OV
	for mharc-commit-mailutils@gnu.org; Tue, 16 Nov 2010 03:53:00 -0500
Received: from [140.186.70.92] (port=53653 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PIHHd-0006Pi-Gd
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 03:52:59 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHHb-00059l-5i
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 03:52:57 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:52080
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHHb-00059h-2N
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 03:52:55 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHHa-0008DD-M6
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 08:52:54 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHHQ-0007Gu-NF
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 08:52:54 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: feee0bbfdb8e2136d612a74ff7d748c5f6c616ea
X-Git-Newrev: a43d959feceeba5008169a7e8127b8385f64b0e9
Message-Id: <E1PIHHQ-0007Gu-NF@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 16 Nov 2010 08:52:46 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-195-ga43d959
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Nov 2010 08:52:59 -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=a43d959feceeba5008169a7e8127b8385f64b0e9

The branch, master has been updated
       via  a43d959feceeba5008169a7e8127b8385f64b0e9 (commit)
       via  cf431d85b28662f883e1960f164579df8b01436e (commit)
      from  feee0bbfdb8e2136d612a74ff7d748c5f6c616ea (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 a43d959feceeba5008169a7e8127b8385f64b0e9
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 16 10:46:47 2010 +0200

    mh: fix burst, provide test cases.
    
    * mh/burst.c (burst_stream): New struct.
    (finish_stream): Change signature.
    Keep track of current part number and flags.
    (flush_stream): Rewrite.
    (burst_digest): Remove extra buffering code.  Rely on the
    stream buffering instead.
    Fixed length-based EB detection.
    Return 0 if the message was bursted successfully, 1 if it is
    not in digest format.
    (burst_or_copy): Revert the condition on burst_digest.
    
    * tests/burst.at: New test.
    * tests/Makefile.am (TESTSUITE_AT): Add burst.at
    * tests/testsuite.at: Include burst.at

commit cf431d85b28662f883e1960f164579df8b01436e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 15 21:20:50 2010 +0200

    message_stream: Bugfix
    
    * libmailutils/stream/message_stream.c (copy_trimmed_value): Fix
    memory allocation.

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

Summary of changes:
 libmailutils/stream/message_stream.c      |    2 +-
 mh/burst.c                                |  220 ++++++++++++++----------
 mh/tests/Makefile.am                      |    1 +
 readmsg/tests/all.at => mh/tests/burst.at |  261 +++++++++++++++-------------
 mh/tests/testsuite.at                     |    1 +
 5 files changed, 272 insertions(+), 213 deletions(-)
 copy readmsg/tests/all.at => mh/tests/burst.at (51%)

diff --git a/libmailutils/stream/message_stream.c b/libmailutils/stream/message_stream.c
index dfa8b70..189eb0f 100644
--- a/libmailutils/stream/message_stream.c
+++ b/libmailutils/stream/message_stream.c
@@ -138,7 +138,7 @@ copy_trimmed_value (const char *str)
   
   str = mu_str_skip_class (str, MU_CTYPE_SPACE);
   len = strlen (str) - 1;
-  p = malloc (len);
+  p = malloc (len + 1);
   memcpy (p, str, len);
   p[len] = 0;
   return p;
diff --git a/mh/burst.c b/mh/burst.c
index 5751513..d26fef4 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -134,7 +134,7 @@ struct burst_map
 struct burst_map map;        /* Currently built map */
 struct burst_map *burst_map; /* Finished burst map */
 size_t burst_count;          /* Number of items in burst_map */
-mu_mailbox_t tmpbox;         /* Temporaty mailbox */			 
+mu_mailbox_t tmpbox;         /* Temporary mailbox */
 struct obstack stk;          /* Stack for building burst_map, etc. */
 
 static int burst_or_copy (mu_message_t msg, int recursive, int copy);
@@ -217,33 +217,70 @@ token_num(int c)
     }
 }
 
+#define F_FIRST  0x01  /* First part of the message (no EB seen so far) */
+#define F_ENCAPS 0x02  /* Within encapsulated part */
+
+struct burst_stream
+{
+  mu_stream_t stream;  /* Output stream */
+  int flags;           /* See F_ flags above */
+  size_t msgno;        /* Number of the current message */
+  size_t partno;       /* Number of the part within the message */
+};
+
 static void
-finish_stream (mu_stream_t *pstr)
+finish_stream (struct burst_stream *bs)
 {
-  mu_message_t msg;
-  mu_stream_seek (*pstr, 0, SEEK_SET, NULL);
-  msg = mh_stream_to_message (*pstr);
-  if (!map.first)
-    mu_mailbox_uidnext (tmpbox, &map.first);
-  burst_or_copy (msg, recursive, 1);
-  mu_stream_close (*pstr);
-  mu_stream_destroy (pstr);
+  if (bs->stream)
+    {
+      mu_message_t msg;
+      
+      mu_stream_seek (bs->stream, 0, SEEK_SET, NULL);
+      msg = mh_stream_to_message (bs->stream);
+      if (!map.first)
+	mu_mailbox_uidnext (tmpbox, &map.first);
+      burst_or_copy (msg, recursive, 1);
+      mu_message_destroy (&msg, mu_message_get_owner (msg));
+      mu_stream_unref (bs->stream);
+      bs->stream = 0;
+      
+      bs->partno++;
+      bs->flags &= ~F_FIRST;
+    }
 }  
 
 static void
-flush_stream (mu_stream_t *pstr, char *buf, size_t size)
+flush_stream (struct burst_stream *bs, char *buf, size_t size)
 {
   int rc;
 
   if (size == 0)
     return;
-  if ((rc = mu_temp_file_stream_create (pstr, NULL))) 
+  if (!bs->stream)
     {
-      mu_error (_("Cannot open temporary file: %s"),
-		mu_strerror (rc));
-      exit (1);
+      if ((rc = mu_temp_file_stream_create (&bs->stream, NULL))) 
+	{
+	  mu_error (_("Cannot open temporary file: %s"),
+		    mu_strerror (rc));
+	  exit (1);
+	}
+      mu_stream_printf (bs->stream, "X-Burst-Part: %lu %lu %02x\n",
+			(unsigned long) bs->msgno,
+			(unsigned long) bs->partno, bs->flags);
+      if (!bs->flags)
+	mu_stream_write (bs->stream, "\n", 1, NULL);
+
+      if (verbose && !inplace)
+	{
+	  size_t nextuid;
+	  mu_mailbox_uidnext (tmpbox, &nextuid);
+	  printf (_("message %lu of digest %lu becomes message %lu\n"),
+		  (unsigned long) bs->partno,
+		  (unsigned long) bs->msgno,
+		  (unsigned long) nextuid);
+	}
     }
-  rc = mu_stream_write (*pstr, buf, size, NULL);
+  rc = mu_stream_write (bs->stream, buf, size, NULL);
   if (rc)
     {
       mu_error (_("error writing temporary stream: %s"),
@@ -252,95 +289,100 @@ flush_stream (mu_stream_t *pstr, char *buf, size_t size)
     }
 }
 
+/* Burst an RFC 934 digest.  Return 0 if OK, 1 if the message is not
+   a valid digest.
+   FIXME: On errors, cleanup and return -1
+*/
 int
 burst_digest (mu_message_t msg)
 {
-  mu_stream_t is, os = NULL;
-  char *buf;
-  size_t bufsize;
+  mu_stream_t is;
+  char c;
   size_t n;
+  size_t count;
   int state = S1;
-  size_t count = 0;
   int eb_length = 0;
+  struct burst_stream bs;
+  int result;
+  
+  bs.stream = NULL;
+  bs.flags = F_FIRST;
+  bs.partno = 1;
+  mh_message_number (msg, &bs.msgno);
   
-  mu_message_size (msg, &bufsize);
-
-  for (; bufsize > 1; bufsize >>= 1)
-    if ((buf = malloc (bufsize)))
-      break;
-
-  if (!buf)
-    {
-      mu_error (_("cannot burst message: %s"), mu_strerror (ENOMEM));
-      exit (1);
-    }
-
   mu_message_get_streamref (msg, &is);
-  while (mu_stream_read (is, buf, bufsize, &n) == 0
-	 && n > 0)
+  while (mu_stream_read (is, &c, 1, &n) == 0
+	 && n == 1)
     {
-      size_t start, i;
-	
-      for (i = start = 0; i < n; i++)
+      int newstate = transtab[state - 1][token_num (c)];
+      int silent = 0;
+      
+      if (newstate < 0)
 	{
-	  int newstate = transtab[state-1][token_num(buf[i])];
-	  
-	  if (newstate < 0)
-	    {
-	      newstate = -newstate;
-	      flush_stream (&os, buf + start, i - start);
-	      start = i + 1;
-	    }
+	  newstate = -newstate;
+	  silent = 1;
+	}
 
-	  if (state == S1)
+      if (state == S1)
+	{
+	  /* GNU extension: check if we have seen enough dashes to
+	     constitute a valid encapsulation boundary. */
+	  if (newstate == S3)
 	    {
-	      /* GNU extension: check if we have seen enough dashes to
-		 constitute a valid encapsulation boundary. */
-	      if (newstate == S3)
+	      eb_length++;
+	      if (eb_length < eb_min_length)
+		continue; /* Ignore state change */
+	      if (eb_min_length > 1)
 		{
-		  eb_length++;
-		  if (eb_length < eb_min_length)
-		    continue; /* Ignore state change */
+		  newstate = S4;
+		  finish_stream (&bs);
+		  bs.flags ^= F_ENCAPS;
 		}
-	      else if (eb_length)
-		while (eb_length--)
-		  flush_stream (&os, "-", 1);
-	      eb_length = 0;
-	    }
-	  else if (state == S5 && newstate == S2)
-	    {
-	      /* As the automaton traverses from state S5 to S2, the
-		 bursting agent should consider a new message started
-		 and output the first character. */
-	      os = NULL;
-	      count++;
 	    }
-	  else if (state == S3 && newstate == S4)
-	    {
-	      /* As the automaton traverses from state S3 to S4, the
-		 bursting agent should consider the current message ended. */
-	      finish_stream (&os);
-	    }
-	  
-	  state = newstate;
+	  else
+	    for (; eb_length; eb_length--, count++)
+	      flush_stream (&bs, "-", 1);
+	  eb_length = 0;
+	}
+      else if (state == S5 && newstate == S2)
+	{
+	  /* As the automaton traverses from state S5 to S2, the
+	     bursting agent should consider a new message started
+	     and output the first character. */
+	  finish_stream (&bs);
+	}
+      else if (state == S3 && newstate == S4)
+	{
+	  /* As the automaton traverses from state S3 to S4, the
+	     bursting agent should consider the current message ended. */
+	  finish_stream (&bs);
+	  bs.flags ^= F_ENCAPS;
+	}
+      state = newstate;
+      if (!silent)
+	{
+	  flush_stream (&bs, &c, 1);
+	  count++;
 	}
-
-      flush_stream (&os, buf + start, i - start);
     }
   mu_stream_destroy (&is);
-  
-  free (buf);
-  if (os)
+
+  if (bs.flags == F_FIRST)
+    {
+      mu_stream_destroy (&bs.stream);
+      result = 1;
+    }
+  else if (bs.stream)
     {
-      if (count)
-	finish_stream (&os);
+      mu_off_t size = 0;
+      mu_stream_size (bs.stream, &size);
+      if (size)
+	finish_stream (&bs);
       else
-	{
-	  mu_stream_close (os);
-	  mu_stream_destroy (&os);
-	}
+	mu_stream_destroy (&bs.stream);
+      result = 0;
     }
-  return count > 0;
+  return result;
 }
 
 
@@ -358,7 +400,7 @@ burst_or_copy (mu_message_t msg, int recursive, int copy)
 	    map.mime = 1;
 	  return burst_mime (msg);
 	}
-      else if (burst_digest (msg))
+      else if (burst_digest (msg) == 0)
 	return 0;
     }
 
@@ -380,9 +422,6 @@ burst_or_copy (mu_message_t msg, int recursive, int copy)
 	      
 	      mu_message_get_body (msg, &body);
 	      mu_body_get_streamref (body, &str);
-	      /* FIXME: Check if str is actually destroyed.
-		 See mailbox/message_stream.c
-	      */
 	      msg = mh_stream_to_message (str);
 	    }
 	  free (value);
@@ -404,7 +443,7 @@ burst_or_copy (mu_message_t msg, int recursive, int copy)
       map.count++;
       return 0;
     }      
-   
+	      
   return 1;
 }
 
@@ -490,7 +529,6 @@ msg_copy (size_t num, const char *file)
 
   mu_mailbox_get_message (tmpbox, num, &msg);
   mu_message_get_streamref (msg, &istream);
-  /* FIXME: Implement RFC 934 FSA? */
   rc = mu_stream_copy (ostream, istream, 0, NULL);
   if (rc)
     {
@@ -499,7 +537,7 @@ msg_copy (size_t num, const char *file)
     }
   
   mu_stream_destroy (&istream);
-  
+
   mu_stream_close (ostream);
   mu_stream_destroy (&ostream);
 
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index beb7689..3adf295 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -41,6 +41,7 @@ $(srcdir)/package.m4: $(top_srcdir)/configure.ac
 TESTSUITE_AT = \
  ali.at\
  anno.at\
+ burst.at\
  folder.at\
  inc.at\
  install-mh.at\
diff --git a/readmsg/tests/all.at b/mh/tests/burst.at
similarity index 51%
copy from readmsg/tests/all.at
copy to mh/tests/burst.at
index 8db52a6..2a2e4c3 100644
--- a/readmsg/tests/all.at
+++ b/mh/tests/burst.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,69 +14,124 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-READMSGTEST([readmsg *],[readmsg00],
-['*'],
+m4_pushdef([MH_KEYWORDS],[burst])
+
+MH_CHECK([burst digest],[burst00 burst-digest],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[
+From: Sergey Poznyakoff <gray@example.net>
+To: root@example.com
+Subject: digest
+
+Initial text.
+
+------- Forwarded message
+From: Puszcza hackers
+To: Sergey Poznyakoff <gray@gnu.org>
+Subject: Hello
+
+Greetings
+- ---------
+How are you?
+------- End of Forwarded message
+
+Regards,
+Sergey
+])
+
+burst +inbox 1 || exit $?
+grep -v ^X-Envelope-Date Mail/inbox/2
+grep -v ^X-Envelope-Date Mail/inbox/3
+grep -v ^X-Envelope-Date Mail/inbox/4
+],
 [0],
-[Date: Fri, 28 Dec 2001 22:18:08 +0200
-From: Foo Bar <foobar@nonexistent.net>
-To: Bar <bar@dontmailme.org>
-Subject: Jabberwocky
-
-`Twas brillig, and the slithy toves
-Did gyre and gimble in the wabe;
-All mimsy were the borogoves,
-And the mome raths outgrabe.
-
-`Beware the Jabberwock, my son!
-The jaws that bite, the claws that catch!
-Beware the Jujub bird, and shun
-The frumious Bandersnatch!'
-
-He took his vorpal sword in hand:
-Long time the manxome foe he sought --
-So rested he by the Tumtum gree,
-And stood awhile in thought.
-
-And as in uffish thought he stood,
-The Jabberwock, with eyes of flame,
-Came whiffling through the tulgey wook,
-And burbled as it came!
-
-One, two!  One, two!  And through and through
-The vorpal blade went snicker-snack!
-He left it dead, and with its head
-He went galumphing back.
-
-`And has thou slain the Jabberwock?
-Come to my arms, my beamish boy!
-O frabjous day!  Calloh!  Callay!
-He chortled in his joy.
-
-`Twas brillig, and the slithy toves
-Did gyre and gimble in the wabe;
-All mimsy were the borogoves,
-And the mome raths outgrabe.
-
-
-Date: Fri, 28 Dec 2001 23:28:08 +0200
-From: Bar <bar@dontmailme.org>
-To: Foo Bar <foobar@nonexistent.net>
-Subject: Re: Jabberwocky
-
-It seems very pretty, but it's *rather* hard to understand!'
-Somehow it seems to fill my head with ideas -- only I don't
-exactly know what they are!  However, SOMEBODY killed SOMETHING:
-that's clear, at any rate...
-
-To: Foo Bar <foobar@nonexistent.net>
-Subject: Simple MIME
-Date: Sat, 13 Jul 2002 00:43:18 +0300
+[X-Burst-Part: 1 1 01
+From: Sergey Poznyakoff <gray@example.net>
+To: root@example.com
+Subject: digest
+X-Envelope-Sender: gray@example.net
+
+Initial text.
+
+X-Burst-Part: 1 2 02
+From: Puszcza hackers
+To: Sergey Poznyakoff <gray@gnu.org>
+Subject: Hello
+X-Envelope-Sender: GNU-Mailutils
+
+Greetings
+---------
+How are you?
+X-Burst-Part: 1 3 00
+X-Envelope-Sender: GNU-MH
+
+Regards,
+Sergey
+])
+
+MH_CHECK([burst digest /w EB length limit],[burst01 burst-digest-eb-length],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[
 From: Sergey Poznyakoff <gray@example.net>
+To: root@example.com
+Subject: digest
+
+Initial text.
+
+------- Forwarded message
+From: Puszcza hackers
+To: Sergey Poznyakoff <gray@gnu.org>
+Subject: Hello
 
-------- =_aaaaaaaaaa0
-Content-Type: text/plain; name="msg.1"; charset="us-ascii"
+Greetings
+-----
+How are you?
+------- End of Forwarded message
+
+Regards,
+Sergey
+])
+
+burst +inbox --length=7 1 || exit $?
+grep -v ^X-Envelope-Date Mail/inbox/2
+grep -v ^X-Envelope-Date Mail/inbox/3
+grep -v ^X-Envelope-Date Mail/inbox/4
+],
+[0],
+[X-Burst-Part: 1 1 01
+From: Sergey Poznyakoff <gray@example.net>
+To: root@example.com
+Subject: digest
+X-Envelope-Sender: gray@example.net
+
+Initial text.
+
+X-Burst-Part: 1 2 02
+From: Puszcza hackers
+To: Sergey Poznyakoff <gray@gnu.org>
+Subject: Hello
+X-Envelope-Sender: GNU-Mailutils
+
+Greetings
+-----
+How are you?
+X-Burst-Part: 1 3 00
+X-Envelope-Sender: GNU-MH
+
+Regards,
+Sergey
+])
+
+MH_CHECK([burst mime],[burst02 burst-mime],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+burst +inbox 3 || exit $?
+grep -v ^X-Envelope-Date: Mail/inbox/6
+],
+[0],
+[Content-Type: text/plain; name="msg.1"; charset="us-ascii"
 Content-ID: <5082.1026510189.1@example.net>
 Content-Description: How doth
+X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 How doth the little crocodile
 Improve his shining tail,
@@ -87,31 +142,21 @@ On every golden scale!
 How neatly spread his claws,
 And welcome little fishes in
 With gently smiling jaws!
+])
 
-------- =_aaaaaaaaaa0
-Content-Type: application/octet-stream; name="msg.21"
-Content-ID: <5082.1026510189.2@example.net>
-Content-Description: Father William Part I
-Content-Transfer-Encoding: base64
-
-YFlvdSBhcmUgb2xkLCBGYXRoZXIgV2lsbGlhbSwnIHRoZSB5b3VuZyBtYW4gc2FpZCwKYEFuZCB5
-b3VyIGhhaXIgaGFzIGJlY29tZSB2ZXJ5IHdoaXRlOwpBbmQgeWV0IHlvdSBpbmNlc3NhbnRseSBz
-dGFuZCBvbiB5b3VyIGhlYWQtLQpEbyB5b3UgdGhpbmssIGF0IHlvdXIgYWdlLCBpdCBpcyByaWdo
-dD8nCgpgSW4gbXkgeW91dGgsJyBGYXRoZXIgV2lsbGlhbSByZXBsaWVkIHRvIGhpcyBzb24sCmBJ
-IGZlYXJlZCBpdCBtaWdodCBpbmp1cmUgdGhlIGJyYWluOwpCdXQsIG5vdyB0aGF0IEknbSBwZXJm
-ZWN0bHkgc3VyZSBJIGhhdmUgbm9uZSwKV2h5LCBJIGRvIGl0IGFnYWluIGFuZCBhZ2Fpbi4nCgo=
-
-------- =_aaaaaaaaaa0--
-
-To: Foo Bar <foobar@nonexistent.net>
-Subject: Nested MIME
-Date: Sat, 13 Jul 2002 00:50:58 +0300
-From: Sergey Poznyakoff <gray@example.net>
-
-------- =_aaaaaaaaaa0
-Content-Type: text/plain; name="msg.21"; charset="us-ascii"
+MH_CHECK([burst mime recursive],[burst03 burst-mime-recursive],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+burst +inbox --recursive 4 || exit $?
+grep -v ^X-Envelope-Date: Mail/inbox/6
+grep -v ^X-Envelope-Date: Mail/inbox/7
+grep -v ^X-Envelope-Date: Mail/inbox/8
+grep -v ^X-Envelope-Date: Mail/inbox/9
+],
+[0],
+[Content-Type: text/plain; name="msg.21"; charset="us-ascii"
 Content-ID: <5122.1026510654.2@example.net>
 Content-Description: Father William Part I
+X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 `You are old, Father William,' the young man said,
 `And your hair has become very white;
@@ -123,16 +168,11 @@ Do you think, at your age, it is right?'
 But, now that I'm perfectly sure I have none,
 Why, I do it again and again.'
 
-
-------- =_aaaaaaaaaa0
-Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa1"
-Content-ID: <5122.1026510654.3@example.net>
-
-------- =_aaaaaaaaaa1
 Content-Type: application/octet-stream; name="msg.22"
 Content-ID: <5122.1026510654.4@example.net>
 Content-Description: Father William Part II
 Content-Transfer-Encoding: base64
+X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBhcyBJIG1lbnRpb25lZCBiZWZvcmUsCkFu
 ZCBoYXZlIGdyb3duIG1vc3QgdW5jb21tb25seSBmYXQ7CllldCB5b3UgdHVybmVkIGEgYmFjay1z
@@ -141,16 +181,11 @@ YXQ/JwoKYEluIG15IHlvdXRoLCcgc2FpZCB0aGUgc2FnZSwgYXMgaGUgc2hvb2sgaGlzIGdyZXkg
 bG9ja3MsCmBJIGtlcHQgYWxsIG15IGxpbWJzIHZlcnkgc3VwcGxlCkJ5IHRoZSB1c2Ugb2YgdGhp
 cyBvaW50bWVudC0tb25lIHNoaWxsaW5nIHRoZSBib3gtLQpBbGxvdyBtZSB0byBzZWxsIHlvdSBh
 IGNvdXBsZT8nCg==
-
-------- =_aaaaaaaaaa1
-Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa2"
-Content-ID: <5122.1026510654.5@example.net>
-
-------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.23"
 Content-ID: <5122.1026510654.6@example.net>
 Content-Description: Father William Part III
 Content-Transfer-Encoding: base64
+X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBhbmQgeW91ciBqYXdzIGFyZSB0b28gd2Vh
 awpGb3IgYW55dGhpbmcgdG91Z2hlciB0aGFuIHN1ZXQ7CllldCB5b3UgZmluaXNoZWQgdGhlIGdv
@@ -159,12 +194,11 @@ ZSB0byBkbyBpdD8nCgpgSW4gbXkgeW91dGgsJyBzYWlkIGhpcyBmYXRoZXIsIGBJIHRvb2sgdG8g
 dGhlIGxhdywKQW5kIGFyZ3VlZCBlYWNoIGNhc2Ugd2l0aCBteSB3aWZlOwpBbmQgdGhlIG11c2N1
 bGFyIHN0cmVuZ3RoLCB3aGljaCBpdCBnYXZlIHRvIG15IGphdywKSGFzIGxhc3RlZCB0aGUgcmVz
 dCBvZiBteSBsaWZlLicK
-
-------- =_aaaaaaaaaa2
 Content-Type: application/octet-stream; name="msg.24"
 Content-ID: <5122.1026510654.7@example.net>
 Content-Description: Father William Part IV
 Content-Transfer-Encoding: base64
+X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBvbmUgd291bGQgaGFyZGx5IHN1cHBvc2UK
 VGhhdCB5b3VyIGV5ZSB3YXMgYXMgc3RlYWR5IGFzIGV2ZXI7CllldCB5b3UgYmFsYW5jZWQgYW4g
@@ -173,32 +207,17 @@ ZXZlcj8nCgpgSSBoYXZlIGFuc3dlcmVkIHRocmVlIHF1ZXN0aW9ucywgYW5kIHRoYXQgaXMgZW5v
 dWdoLCcKU2FpZCBoaXMgZmF0aGVyOyBgZG9uJ3QgZ2l2ZSB5b3Vyc2VsZiBhaXJzIQpEbyB5b3Ug
 dGhpbmsgSSBjYW4gbGlzdGVuIGFsbCBkYXkgdG8gc3VjaCBzdHVmZj8KQmUgb2ZmLCBvciBJJ2xs
 IGtpY2sgeW91IGRvd24gc3RhaXJzIScK
+])
 
-------- =_aaaaaaaaaa2--
-
-------- =_aaaaaaaaaa1--
-
-------- =_aaaaaaaaaa0--
-
-To: Foo Bar <foobar@nonexistent.net>
-Subject: Empty MIME Parts
-Date: Sat, 13 Jul 2002 00:43:18 +0300
-From: Sergey Poznyakoff <gray@example.net>
-
-------- =_aaaaaaaaaa0
-Content-Type: text/plain; name="empty"; charset="us-ascii"
-Content-ID: <5082.1026510189.1@example.net>
-Content-Description: Empty part
-
-
-------- =_aaaaaaaaaa0
-Content-Type: text/plain; name="single.line"; charset="us-ascii"
-Content-ID: <5082.1026510189.2@example.net>
-Content-Description: Single line part
-
-
-
-------- =_aaaaaaaaaa0--
+MH_CHECK([burst non-digest],[burst04 burst-non-digest],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+burst +inbox 1 || exit $?
+],
+[0],
+[],
+[burst: message 1 not in digest format
+])
 
+m4_popdef[MH_KEYWORDS])
+# End of burst.at
 
-])
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index a9ae3b4..10b8d52 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -55,3 +55,4 @@ m4_include([mhpath.at])
 m4_include([mhl.at])
 m4_include([anno.at])
 m4_include([pick.at])
+m4_include([burst.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 16 04:07:55 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PIHW7-0004GD-Jc
	for mharc-commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:07:55 -0500
Received: from [140.186.70.92] (port=55452 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PIHW5-0004Fm-Ag
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:07:54 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHW4-0007o3-1O
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:07:53 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:41611
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHW3-0007nw-UC
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:07:51 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHW3-0008Pd-O8
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 09:07:51 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHW1-0008FH-EK
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 09:07:51 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: a43d959feceeba5008169a7e8127b8385f64b0e9
X-Git-Newrev: 52c4656f527c90e0123a4559ce7d5dcd5f1b03d5
Message-Id: <E1PIHW1-0008FH-EK@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 16 Nov 2010 09:07:51 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-196-g52c4656
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Nov 2010 09:07:54 -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=52c4656f527c90e0123a4559ce7d5dcd5f1b03d5

The branch, master has been updated
       via  52c4656f527c90e0123a4559ce7d5dcd5f1b03d5 (commit)
      from  a43d959feceeba5008169a7e8127b8385f64b0e9 (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 52c4656f527c90e0123a4559ce7d5dcd5f1b03d5
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 16 11:07:09 2010 +0200

    mh: rmm now saves state before returning
    
    * mh/rmm.c (main): Call mh_global_save_state.

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

Summary of changes:
 mh/rmm.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/mh/rmm.c b/mh/rmm.c
index 96cb028..6e2f65e 100644
--- a/mh/rmm.c
+++ b/mh/rmm.c
@@ -82,6 +82,7 @@ main (int argc, char **argv)
   mu_mailbox_expunge (mbox);
   mu_mailbox_close (mbox);
   mu_mailbox_destroy (&mbox);
+  mh_global_save_state ();
   return status;
 }
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 16 04:17:12 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PIHf6-0006vf-Hu
	for mharc-commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:17:12 -0500
Received: from [140.186.70.92] (port=43587 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PIHf4-0006vH-H4
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:17:11 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHf3-0000wI-Fv
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:17:10 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:46002
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHf3-0000wE-EI
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 04:17:09 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHf3-00006S-HZ
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 09:17:09 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIHf3-0006VP-9b
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 09:17:09 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 52c4656f527c90e0123a4559ce7d5dcd5f1b03d5
X-Git-Newrev: 3d266601df7be584da838bca1f276c4ed92f3c65
Message-Id: <E1PIHf3-0006VP-9b@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 16 Nov 2010 09:17:09 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-197-g3d26660
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Nov 2010 09:17:11 -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=3d266601df7be584da838bca1f276c4ed92f3c65

The branch, master has been updated
       via  3d266601df7be584da838bca1f276c4ed92f3c65 (commit)
      from  52c4656f527c90e0123a4559ce7d5dcd5f1b03d5 (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 3d266601df7be584da838bca1f276c4ed92f3c65
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 16 11:15:39 2010 +0200

    mh: minor fix in traditional option handler
    
    * mh/mh_getopt.c (mh_option_init): Enforce the compited minlen
    on each option which begins on the same letter as the sample.

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

Summary of changes:
 mh/mh_getopt.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 2bed55c..748db10 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -192,6 +192,8 @@ mh_option_init (struct mh_option *opt)
 		  break;
 	      }
 	    while (len >= minlen && memcmp (opt[j].opt, sample, minlen) == 0);
+	  else if (opt[j].opt[0] == sample[0])
+	    opt[j].match_len = minlen;
 	  else
 	    break;
 	}


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 16 07:56:31 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PIL5L-0000WP-Ba
	for mharc-commit-mailutils@gnu.org; Tue, 16 Nov 2010 07:56:31 -0500
Received: from [140.186.70.92] (port=45548 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PIL5G-0000W2-J2
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 07:56:29 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIL5E-00061V-EQ
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 07:56:26 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:53829
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIL5E-00061M-CW
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 07:56:24 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIL5D-0003FQ-NX
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 12:56:23 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIL56-00032J-EA
	for commit-mailutils@gnu.org; Tue, 16 Nov 2010 12:56:23 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 3d266601df7be584da838bca1f276c4ed92f3c65
X-Git-Newrev: 90450be6f2f902b26c3b63c901b729503a056ec3
Message-Id: <E1PIL56-00032J-EA@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 16 Nov 2010 12:56:17 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-199-g90450be
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 16 Nov 2010 12:56:29 -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=90450be6f2f902b26c3b63c901b729503a056ec3

The branch, master has been updated
       via  90450be6f2f902b26c3b63c901b729503a056ec3 (commit)
       via  08562ac4ef9b4d07d6ac0ff56af04f83dc4a1075 (commit)
      from  3d266601df7be584da838bca1f276c4ed92f3c65 (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 90450be6f2f902b26c3b63c901b729503a056ec3
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 16 13:20:49 2010 +0200

    mh: Optimize for speed.
    
    * mh/burst.c (transtab): Revamp as a proper translation table.
    It is indexed by the current state offset by 1 and the last read
    caracter.
    (token_num): Remove.
    (finish_stream, flush_stream): Inline functions.
    (burst_digest): Change transtab indexing.

commit 08562ac4ef9b4d07d6ac0ff56af04f83dc4a1075
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 16 12:38:36 2010 +0200

    mh: further fixes in burst testsuite.
    
    * mh/burst.c: Minor changes.
    * mh/tests/burst.at: Remove host-specific information.

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

Summary of changes:
 mh/burst.c        |  211 +++++++++++++++++++++++++++++++++++++++++++----------
 mh/burstfsa.c     |  105 ++++++++++++++++++++++++++
 mh/tests/burst.at |   15 +---
 3 files changed, 282 insertions(+), 49 deletions(-)
 create mode 100644 mh/burstfsa.c

diff --git a/mh/burst.c b/mh/burst.c
index d26fef4..03b7eb7 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -192,31 +192,169 @@ burst_mime (mu_message_t msg)
 #define S5 5
 
 /* Negative state means no write */
-int transtab[][4] = {
-/*          DEF    '\n'   ' '   '-' */
-/* S1 */ {  S2,    S1,    S2,   -S3 },
-/* S2 */ {  S2,    S1,    S2,    S2 },
-/* S3 */ { -S4,   -S4,   -S2,   -S4 }, 
-/* S4 */ { -S4,   -S5,   -S4,   -S4 },
-/* S5 */ {  S2,   -S5,    S2,    S2 }
+int transtab[5][256] = {
+/* S1 */ {  S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S1,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2, -S3,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2 },
+/* S2 */ {  S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S1,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2 },
+/* S3 */ { -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S2, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4 },
+/* S4 */ { -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S5, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4, 
+           -S4, -S4, -S4, -S4, -S4, -S4, -S4, -S4 },
+/* S5 */ {  S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2, -S5,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2, 
+            S2,  S2,  S2,  S2,  S2,  S2,  S2,  S2 }
 };
 
-static int
-token_num(int c)
-{
-  switch (c)
-    {
-    case '\n':
-      return 1;
-    case ' ':
-      return 2;
-    case '-':
-      return 3;
-    default:
-      return 0;
-    }
-}
-
 #define F_FIRST  0x01  /* First part of the message (no EB seen so far) */
 #define F_ENCAPS 0x02  /* Within encapsulated part */
 
@@ -228,7 +366,7 @@ struct burst_stream
   size_t partno;       /* Number of the part within the message */
 };
 
-static void
+static inline void
 finish_stream (struct burst_stream *bs)
 {
   if (bs->stream)
@@ -249,7 +387,7 @@ finish_stream (struct burst_stream *bs)
     }
 }  
 
-static void
+static inline void
 flush_stream (struct burst_stream *bs, char *buf, size_t size)
 {
   int rc;
@@ -291,15 +429,14 @@ flush_stream (struct burst_stream *bs, char *buf, size_t size)
 
 /* Burst an RFC 934 digest.  Return 0 if OK, 1 if the message is not
    a valid digest.
-   FIXME: On errors, cleanup and return -1
+   FIXME: On errors, cleanup and return -1.
 */
 int
 burst_digest (mu_message_t msg)
 {
   mu_stream_t is;
-  char c;
+  unsigned char c;
   size_t n;
-  size_t count;
   int state = S1;
   int eb_length = 0;
   struct burst_stream bs;
@@ -311,10 +448,9 @@ burst_digest (mu_message_t msg)
   mh_message_number (msg, &bs.msgno);
   
   mu_message_get_streamref (msg, &is);
-  while (mu_stream_read (is, &c, 1, &n) == 0
-	 && n == 1)
+  while (mu_stream_read (is, &c, 1, &n) == 0 && n == 1)
     {
-      int newstate = transtab[state - 1][token_num (c)];
+      int newstate = transtab[state - 1][c];
       int silent = 0;
       
       if (newstate < 0)
@@ -340,7 +476,7 @@ burst_digest (mu_message_t msg)
 		}
 	    }
 	  else
-	    for (; eb_length; eb_length--, count++)
+	    for (; eb_length; eb_length--)
 	      flush_stream (&bs, "-", 1);
 	  eb_length = 0;
 	}
@@ -360,10 +496,7 @@ burst_digest (mu_message_t msg)
 	}
       state = newstate;
       if (!silent)
-	{
-	  flush_stream (&bs, &c, 1);
-	  count++;
-	}
+	flush_stream (&bs, (char*)&c, 1);
     }
   mu_stream_destroy (&is);
 
@@ -639,9 +772,9 @@ main (int argc, char **argv)
       mh_msgset_uids (mbox, &ms);
 	
       mu_mailbox_get_url (mbox, &dst_url);
-      dir = mu_url_to_string (dst_url);
-      VERBOSE ((_("changing to `%s'"), dir + 3));
-      if (chdir (dir+3))
+      mu_url_sget_path (dst_url, &dir);
+      VERBOSE ((_("changing to `%s'"), dir));
+      if (chdir (dir))
 	{
 	  mu_error (_("cannot change to `%s': %s"), dir, mu_strerror (errno));
 	  exit (1);
diff --git a/mh/burstfsa.c b/mh/burstfsa.c
new file mode 100644
index 0000000..f43d25b
--- /dev/null
+++ b/mh/burstfsa.c
@@ -0,0 +1,105 @@
+/* Generate FSA states for RFC 934 bursting agent.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdio.h>
+
+/* Bursting FSA states accoring to RFC 934:
+   
+      S1 ::   "-" S3
+            | CRLF {CRLF} S1
+            | c {c} S2
+
+      S2 ::   CRLF {CRLF} S1
+            | c {c} S2
+
+      S3 ::   " " S2
+            | c S4     ;; the bursting agent should consider the current
+	               ;; message ended.  
+
+      S4 ::   CRLF S5
+            | c S4
+
+      S5 ::   CRLF S5
+            | c {c} S2 ;; The bursting agent should consider a new
+	               ;; message started
+*/
+
+static int
+token_num (int c)
+{
+  switch (c)
+    {
+    case '\n':
+      return 1;
+    case ' ':
+      return 2;
+    case '-':
+      return 3;
+    default:
+      return 0;
+    }
+}
+
+#define S1 1
+#define S2 2
+#define S3 3
+#define S4 4
+#define S5 5
+
+/* Negative state means no write */
+int transtab[][4] = {
+/*          DEF    '\n'   ' '   '-' */
+/* S1 */ {  S2,    S1,    S2,   -S3 },
+/* S2 */ {  S2,    S1,    S2,    S2 },
+/* S3 */ { -S4,   -S4,   -S2,   -S4 }, 
+/* S4 */ { -S4,   -S5,   -S4,   -S4 },
+/* S5 */ {  S2,   -S5,    S2,    S2 }
+};
+
+int
+main()
+{
+  int i, state;
+
+  for (state = S1; state <= S5; state++)
+    {
+      printf ("/* S%d */ { ", state);
+      for (i = 0; i < 256; i++)
+	{
+	  int newstate = transtab[state - 1][token_num (i)];
+
+	  if (i > 0)
+	    {
+	      putchar (',');
+	      if (i % 8 == 0)
+		printf ("\n           ");
+	    }
+	  putchar (' ');
+	  if (newstate < 0)
+	    {
+	      putchar ('-');
+	      newstate = -newstate;
+	    }
+	  else
+	    putchar (' ');
+	  printf ("S%d", newstate);
+	}
+      printf (" },\n");
+    }
+  return 0;
+}
+  
+    
diff --git a/mh/tests/burst.at b/mh/tests/burst.at
index 2a2e4c3..b8f906c 100644
--- a/mh/tests/burst.at
+++ b/mh/tests/burst.at
@@ -125,13 +125,12 @@ Sergey
 MH_CHECK([burst mime],[burst02 burst-mime],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 burst +inbox 3 || exit $?
-grep -v ^X-Envelope-Date: Mail/inbox/6
+grep -v ^X-Envelope- Mail/inbox/6
 ],
 [0],
 [Content-Type: text/plain; name="msg.1"; charset="us-ascii"
 Content-ID: <5082.1026510189.1@example.net>
 Content-Description: How doth
-X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 How doth the little crocodile
 Improve his shining tail,
@@ -147,16 +146,15 @@ With gently smiling jaws!
 MH_CHECK([burst mime recursive],[burst03 burst-mime-recursive],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 burst +inbox --recursive 4 || exit $?
-grep -v ^X-Envelope-Date: Mail/inbox/6
-grep -v ^X-Envelope-Date: Mail/inbox/7
-grep -v ^X-Envelope-Date: Mail/inbox/8
-grep -v ^X-Envelope-Date: Mail/inbox/9
+grep -v ^X-Envelope- Mail/inbox/6
+grep -v ^X-Envelope- Mail/inbox/7
+grep -v ^X-Envelope- Mail/inbox/8
+grep -v ^X-Envelope- Mail/inbox/9
 ],
 [0],
 [Content-Type: text/plain; name="msg.21"; charset="us-ascii"
 Content-ID: <5122.1026510654.2@example.net>
 Content-Description: Father William Part I
-X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 `You are old, Father William,' the young man said,
 `And your hair has become very white;
@@ -172,7 +170,6 @@ Content-Type: application/octet-stream; name="msg.22"
 Content-ID: <5122.1026510654.4@example.net>
 Content-Description: Father William Part II
 Content-Transfer-Encoding: base64
-X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBhcyBJIG1lbnRpb25lZCBiZWZvcmUsCkFu
 ZCBoYXZlIGdyb3duIG1vc3QgdW5jb21tb25seSBmYXQ7CllldCB5b3UgdHVybmVkIGEgYmFjay1z
@@ -185,7 +182,6 @@ Content-Type: application/octet-stream; name="msg.23"
 Content-ID: <5122.1026510654.6@example.net>
 Content-Description: Father William Part III
 Content-Transfer-Encoding: base64
-X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBhbmQgeW91ciBqYXdzIGFyZSB0b28gd2Vh
 awpGb3IgYW55dGhpbmcgdG91Z2hlciB0aGFuIHN1ZXQ7CllldCB5b3UgZmluaXNoZWQgdGhlIGdv
@@ -198,7 +194,6 @@ Content-Type: application/octet-stream; name="msg.24"
 Content-ID: <5122.1026510654.7@example.net>
 Content-Description: Father William Part IV
 Content-Transfer-Encoding: base64
-X-Envelope-Sender: gray@Trurl.gnu.org.ua
 
 YFlvdSBhcmUgb2xkLCcgc2FpZCB0aGUgeW91dGgsIGBvbmUgd291bGQgaGFyZGx5IHN1cHBvc2UK
 VGhhdCB5b3VyIGV5ZSB3YXMgYXMgc3RlYWR5IGFzIGV2ZXI7CllldCB5b3UgYmFsYW5jZWQgYW4g


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 17 08:06:06 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PIhiA-0000WI-MZ
	for mharc-commit-mailutils@gnu.org; Wed, 17 Nov 2010 08:06:06 -0500
Received: from [140.186.70.92] (port=52351 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PIhi7-0000Ud-5K
	for commit-mailutils@gnu.org; Wed, 17 Nov 2010 08:06:04 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIhi4-0002GX-Sh
	for commit-mailutils@gnu.org; Wed, 17 Nov 2010 08:06:02 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:34256
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIhi4-0002GR-PS
	for commit-mailutils@gnu.org; Wed, 17 Nov 2010 08:06:00 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIhi4-000621-K7
	for commit-mailutils@gnu.org; Wed, 17 Nov 2010 13:06:00 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PIhhw-0003nC-Ce
	for commit-mailutils@gnu.org; Wed, 17 Nov 2010 13:06:00 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 90450be6f2f902b26c3b63c901b729503a056ec3
X-Git-Newrev: 110d13ec5187a06c59a53deb0f76b2e944c334ef
Message-Id: <E1PIhhw-0003nC-Ce@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 17 Nov 2010 13:05:52 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-200-g110d13e
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 17 Nov 2010 13:06:05 -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=110d13ec5187a06c59a53deb0f76b2e944c334ef

The branch, master has been updated
       via  110d13ec5187a06c59a53deb0f76b2e944c334ef (commit)
      from  90450be6f2f902b26c3b63c901b729503a056ec3 (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 110d13ec5187a06c59a53deb0f76b2e944c334ef
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 17 12:47:30 2010 +0200

    Implement "inline-comment" filter.
    
    * include/mailutils/filter.h (mu_filter_xcode_t): Change signature.
    (mu_filter_create_args): New proto.
    (mu_inline_comment_filter): New extern.
    
    * libmailutils/filter/inline-comment.c: New file.
    * libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Add inline-comment.c.
    * libmailutils/filter/crlfdot.c (alloc_state): Update declaration.
    * libmailutils/filter/crlfflt.c: Likewise.
    * libmailutils/filter/dot.c: Likewise.
    * libmailutils/filter/fromflt.c (_from_alloc_state): Likewise.
    * libmailutils/filter/filter.c (mu_filter_create_args): New function.
    (mu_filter_create): Rewrite via mu_filter_create_args.
    
    mh: inline comments are allowed for use in components and forwcomp files.
    
    * mh/compcommon.c (mh_comp_draft): Fix erroneous conditional.
    * mh/components: Add comments.
    * mh/mh_init.c (mh_file_copy): Rewrite using new API.
    
    mu filter: new option to list supported filters.
    
    * mu/filter.c (filter_options): New option --list (-L).
    (filter_parse_opt): Handle the -L option.
    (filter_printer, list_filters): New functions.
    (main): Print a list of filters if --list was given.

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

Summary of changes:
 include/mailutils/filter.h           |   16 +++-
 libmailutils/filter/Makefile.am      |    1 +
 libmailutils/filter/crlfdot.c        |    3 +-
 libmailutils/filter/crlfflt.c        |    3 +-
 libmailutils/filter/dot.c            |    3 +-
 libmailutils/filter/filter.c         |   29 ++++++-
 libmailutils/filter/fromflt.c        |    3 +-
 libmailutils/filter/inline-comment.c |  152 ++++++++++++++++++++++++++++++++++
 mh/compcommon.c                      |    2 +-
 mh/components                        |    2 +
 mh/mh_init.c                         |   56 ++++--------
 mu/filter.c                          |   45 +++++++++-
 12 files changed, 260 insertions(+), 55 deletions(-)
 create mode 100644 libmailutils/filter/inline-comment.c

diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index 3ee19be..aff0031 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -64,11 +64,16 @@ enum mu_filter_result
 
 #define MU_FILTER_MAX_AGAIN 5
 
-typedef int (*mu_filter_new_data_t) (void **, int, void *);
-typedef enum mu_filter_result (*mu_filter_xcode_t) (void *data,
-						    enum mu_filter_command cmd,
-						    struct mu_filter_io *iobuf);
-
+typedef int (*mu_filter_new_data_t) (void **, int, int argc,
+				     const char **argv);
+typedef enum mu_filter_result
+       (*mu_filter_xcode_t) (void *data, enum mu_filter_command cmd,
+			     struct mu_filter_io *iobuf);
+
+int mu_filter_create_args (mu_stream_t *pstream, mu_stream_t stream,
+			   const char *name, int argc, const char **argv,
+			   int mode, int flags);
+  
 int mu_filter_stream_create (mu_stream_t *pflt,
 			     mu_stream_t str,
 			     int mode, 
@@ -103,6 +108,7 @@ extern mu_filter_record_t mu_bit7_filter;
 extern mu_filter_record_t mu_rfc_2047_Q_filter;
 extern mu_filter_record_t mu_rfc_2047_B_filter;
 extern mu_filter_record_t mu_from_filter;
+extern mu_filter_record_t mu_inline_comment_filter;
 
 enum mu_iconv_fallback_mode
   {
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index 3d459c6..e870a09 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -27,6 +27,7 @@ libfilter_la_SOURCES =\
  filter.c\
  filter_iconv.c\
  fromflt.c\
+ inline-comment.c\
  linelenflt.c\
  qpflt.c
 
diff --git a/libmailutils/filter/crlfdot.c b/libmailutils/filter/crlfdot.c
index 35043a6..a0295c7 100644
--- a/libmailutils/filter/crlfdot.c
+++ b/libmailutils/filter/crlfdot.c
@@ -316,7 +316,8 @@ _crlfdot_encoder (void *xd,
 }
 
 static int
-alloc_state (void **pret, int mode MU_ARG_UNUSED, void *data MU_ARG_UNUSED)
+alloc_state (void **pret, int mode MU_ARG_UNUSED,
+	     int argc MU_ARG_UNUSED, const char **argv MU_ARG_UNUSED)
 {
   *pret = malloc (sizeof (int));
   if (!*pret)
diff --git a/libmailutils/filter/crlfflt.c b/libmailutils/filter/crlfflt.c
index 9dc147c..ea5b8ce 100644
--- a/libmailutils/filter/crlfflt.c
+++ b/libmailutils/filter/crlfflt.c
@@ -140,7 +140,8 @@ _crlf_decoder (void *xd MU_ARG_UNUSED,
 }
 
 static int
-alloc_state (void **pret, int mode, void *data MU_ARG_UNUSED)
+alloc_state (void **pret, int mode,
+	     int argc MU_ARG_UNUSED, const char **argv MU_ARG_UNUSED)
 {
   switch (mode)
     {
diff --git a/libmailutils/filter/dot.c b/libmailutils/filter/dot.c
index 872f6ba..b962161 100644
--- a/libmailutils/filter/dot.c
+++ b/libmailutils/filter/dot.c
@@ -248,7 +248,8 @@ _dot_encoder (void *xd,
 }
 
 static int
-alloc_state (void **pret, int mode MU_ARG_UNUSED, void *data MU_ARG_UNUSED)
+alloc_state (void **pret, int mode MU_ARG_UNUSED,
+	     int argc MU_ARG_UNUSED, const char **argv MU_ARG_UNUSED)
 {
   *pret = malloc (sizeof (int));
   if (!*pret)
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index 6ab3c92..7525cf1 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -78,6 +78,7 @@ mu_filter_get_list (mu_list_t *plist)
       mu_list_append (filter_list, mu_rfc_2047_Q_filter);
       mu_list_append (filter_list, mu_rfc_2047_B_filter);
       mu_list_append (filter_list, mu_from_filter);
+      mu_list_append (filter_list, mu_inline_comment_filter);
       /* FIXME: add the default encodings?  */
     }
   *plist = filter_list;
@@ -129,7 +130,7 @@ filter_create_wr (mu_stream_t *pstream, mu_stream_t stream,
 {
   int status;
   mu_stream_t fltstream, instream = NULL, tmpstr;
-
+  
   flags &= ~MU_STREAM_AUTOCLOSE;
 
   if (max_line_length)
@@ -157,13 +158,15 @@ filter_create_wr (mu_stream_t *pstream, mu_stream_t stream,
 }
 
 int
-mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
-		  int mode, int flags)
+mu_filter_create_args (mu_stream_t *pstream, mu_stream_t stream,
+		       const char *name, int argc, const char **argv,
+		       int mode, int flags)
 {
   int status;
   mu_filter_record_t frec;
   mu_list_t list;
   void *xdata = NULL;
+  mu_filter_xcode_t xcode;
   
   if ((flags & MU_STREAM_RDWR) == MU_STREAM_RDWR)
     return EINVAL;
@@ -173,9 +176,13 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
   if (status)
     return status;
 
+  xcode = mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder;
+  if (!xcode)
+    return MU_ERR_EMPTY_VFN;
+  
   if (frec->newdata)
     {
-      status = frec->newdata (&xdata, mode, NULL);
+      status = frec->newdata (&xdata, mode, argc, argv);
       if (status)
 	return status;
     }
@@ -184,10 +191,22 @@ mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
                    (pstream, stream,
 		    mode == MU_FILTER_ENCODE ? frec->max_line_length : 0,
 		    mode,
-		    mode == MU_FILTER_ENCODE ? frec->encoder : frec->decoder,
+		    xcode,
 		    xdata,
 		    flags);
   if (status)
     free (xdata);
   return status;
 }
+
+int
+mu_filter_create (mu_stream_t *pstream, mu_stream_t stream, const char *name,
+		  int mode, int flags)
+{
+  const char *argv[2];
+  argv[0] = name;
+  argv[1] = NULL;
+  return mu_filter_create_args (pstream, stream, name, 1, argv, mode,
+				flags);
+}
+
diff --git a/libmailutils/filter/fromflt.c b/libmailutils/filter/fromflt.c
index ebf4326..902fe3c 100644
--- a/libmailutils/filter/fromflt.c
+++ b/libmailutils/filter/fromflt.c
@@ -262,7 +262,8 @@ _from_encoder (void *xd,
 }
 
 static int
-_from_alloc_state (void **pret, int mode, void *data MU_ARG_UNUSED)
+_from_alloc_state (void **pret, int mode,
+		   int argc MU_ARG_UNUSED, const char **argv MU_ARG_UNUSED)
 {
   *pret = malloc (sizeof (int));
   if (!*pret)
diff --git a/libmailutils/filter/inline-comment.c b/libmailutils/filter/inline-comment.c
new file mode 100644
index 0000000..ec6d238
--- /dev/null
+++ b/libmailutils/filter/inline-comment.c
@@ -0,0 +1,152 @@
+/* Simple inline comment filter for GNU Mailutils.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* This filter removes all inline comments from the input.
+   An inline comment begins with a comment starter character at the beginning
+   of a line and ends with the newline character.
+
+   Default comment starter is semicolon.  Another comment starter can
+   be given as the first argument to the filter creation routine.
+
+   Limitations:
+    1. Comment starter must be a single character.  This should be
+       fixed in future.
+    2. Comment starter must appear at the beginning of a line.  This is
+       hard (if not downright impossible) to fix, because the filter
+       has no information about lexical structure of the input stream.
+*/       
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+
+enum ilcmt_state
+  {
+    ilcmt_initial,
+    ilcmt_newline,
+    ilcmt_copy,
+    ilcmt_comment
+  };
+
+struct ilcmt_data
+{
+  enum ilcmt_state state;
+  int cstart;
+};
+
+static int
+new_ilcmt_state (struct ilcmt_data *pd, int c)
+{
+  switch (pd->state)
+    {
+    case ilcmt_initial:
+    case ilcmt_newline:
+      if (c == pd->cstart)
+	{
+	  pd->state = ilcmt_comment;
+	  return 0;
+	}
+      else
+	pd->state = ilcmt_copy;
+      break;
+      
+    case ilcmt_copy:
+      if (c == '\n')
+	pd->state = ilcmt_newline;
+      break;
+
+    case ilcmt_comment:
+      if (c == '\n')
+	pd->state = ilcmt_newline;
+      return 0;
+    }
+  return 1;
+}
+
+static enum mu_filter_result
+_ilcmt_decoder (void *xd, enum mu_filter_command cmd,
+		struct mu_filter_io *iobuf)
+{
+  struct ilcmt_data *pd = xd;
+  size_t i, j;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      pd->state = ilcmt_initial;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; i < isize && j < osize; i++)
+    {
+      unsigned char c = *iptr++;
+      if (new_ilcmt_state (pd, c))
+	optr[j++] = c;
+    }
+
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return mu_filter_ok;
+}
+
+static int
+alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
+{
+  struct ilcmt_data *pd = malloc (sizeof (*pd));
+  
+  if (!pd)
+    return ENOMEM;
+
+  if (argc == 2)
+    pd->cstart = argv[1][0];
+  else
+    pd->cstart = ';';
+  *pret = pd;
+  
+  return 0;
+}
+
+static struct _mu_filter_record _inline_comment_filter = {
+  "INLINE-COMMENT",
+  0,
+  alloc_state,
+  NULL,
+  _ilcmt_decoder
+};
+
+mu_filter_record_t mu_inline_comment_filter = &_inline_comment_filter;
+
+
+
diff --git a/mh/compcommon.c b/mh/compcommon.c
index 312faf3..f277f59 100644
--- a/mh/compcommon.c
+++ b/mh/compcommon.c
@@ -34,7 +34,7 @@ mh_comp_draft (const char *formfile, const char *defformfile,
   if (formfile)
     {
       s = mh_expand_name (MHLIBDIR, formfile, 0);
-      if (mh_file_copy (s, draftfile) == 0)
+      if (mh_file_copy (s, draftfile))
 	exit (1);
     }
   else
diff --git a/mh/components b/mh/components
index 2669f04..512352e 100644
--- a/mh/components
+++ b/mh/components
@@ -1,3 +1,5 @@
+;; Default components file for GNU MH.
+;; Lines beginning with ; are ignored.  Rest of lines is copied verbatim.
 To:
 cc:
 Subject:
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 9913a98..9f37b86 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -583,34 +583,19 @@ mh_spawnp (const char *prog, const char *file)
   return rc;
 }
 
+/* Copy data from FROM to TO, creating the latter if necessary.
+   FIXME: How about formats?
+*/
 int
 mh_file_copy (const char *from, const char *to)
 {
-  char *buffer;
-  size_t bufsize, rdsize;
-  struct stat st;
-  mu_stream_t in;
-  mu_stream_t out;
+  mu_stream_t in, out, flt;
   int rc;
   
-  if (stat (from, &st))
-    {
-      mu_error ("mh_copy: %s", mu_strerror (errno));
-      return -1;
-    }
-
-  for (bufsize = st.st_size; bufsize > 0 && (buffer = malloc (bufsize)) == 0;
-       bufsize /= 2)
-    ;
-
-  if (!bufsize)
-    mh_err_memory (1);
-
   if ((rc = mu_file_stream_create (&in, from, MU_STREAM_READ)))
     {
       mu_error (_("cannot open input file `%s': %s"),
 		from, mu_strerror (rc));
-      free (buffer);
       return 1;
     }
 
@@ -618,31 +603,28 @@ mh_file_copy (const char *from, const char *to)
     {
       mu_error (_("cannot open output file `%s': %s"),
 		to, mu_strerror (rc));
-      free (buffer);
-      mu_stream_close (in);
       mu_stream_destroy (&in);
       return 1;
     }
 
-  while (st.st_size > 0
-	 && (rc = mu_stream_read (in, buffer, bufsize, &rdsize)) == 0
-	 && rdsize > 0)
+  rc = mu_filter_create (&flt, in, "INLINE-COMMENT", MU_FILTER_DECODE,
+			 MU_STREAM_READ);
+  mu_stream_unref (in);
+  if (rc)
     {
-      if ((rc = mu_stream_write (out, buffer, rdsize, NULL)) != 0)
-	{
-	  mu_error (_("write error on `%s': %s"),
-		    to, mu_strerror (rc));
-	  break;
-	}
-      st.st_size -= rdsize;
+      mu_error (_("cannot open filter stream: %s"), mu_strerror (rc));
+      mu_stream_destroy (&out);
+      return 1;
     }
-
-  free (buffer);
-
-  mu_stream_close (in);
-  mu_stream_close (out);
-  mu_stream_destroy (&in);
+  
+  rc = mu_stream_copy (out, flt, 0, NULL);
+      
+  mu_stream_destroy (&flt);
   mu_stream_destroy (&out);
+
+  if (rc)
+    mu_error (_("error copying file `%s' to `%s': %s"),
+	      from, to, mu_strerror (rc));
   
   return rc;
 }
diff --git a/mu/filter.c b/mu/filter.c
index 2facaee..b050403 100644
--- a/mu/filter.c
+++ b/mu/filter.c
@@ -25,13 +25,14 @@
 
 static char filter_doc[] = N_("mu filter - apply a filter to the input");
 char filter_docstring[] = N_("apply a filter to the input");
-static char filter_args_doc[] = N_("NAME");
+static char filter_args_doc[] = N_("NAME [ARGS]");
 
 static struct argp_option filter_options[] = {
   { "encode", 'e', NULL, 0, N_("encode the input (default)") },
   { "decode", 'd', NULL, 0, N_("decode the input") },
   { "line-length", 'l', N_("NUMBER"), 0, N_("limit output line length") },
   { "newline", 'n', NULL, 0, N_("print additional newline") },
+  { "list", 'L', NULL, 0, N_("list supported filters") },
   { NULL }
 };
 
@@ -39,6 +40,7 @@ static int filter_mode = MU_FILTER_ENCODE;
 static int newline_option = 0;
 static size_t line_length;
 static int line_length_option = 0;
+static int list_option;
 
 static error_t
 filter_parse_opt (int key, char *arg, struct argp_state *state)
@@ -65,6 +67,10 @@ filter_parse_opt (int key, char *arg, struct argp_state *state)
 	argp_error (state, N_("not a number"));
       line_length_option = 1;
       break;
+
+    case 'L':
+      list_option = 1;
+      break;
       
     default:
       return ARGP_ERR_UNKNOWN;
@@ -98,6 +104,28 @@ reset_line_length (const char *name, size_t length)
   /* don't bail out, leave that to mu_filter_create */
 }
 
+static int
+filter_printer (void *item, void *data)
+{
+  mu_filter_record_t rec = item;
+  printf ("%s\n", rec->name);
+  return 0;
+}
+
+static int
+list_filters ()
+{
+  mu_list_t list;
+  int rc = mu_filter_get_list (&list);
+
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_get_list", NULL, rc);
+      return 1;
+    }
+  return mu_list_do (list, filter_printer, NULL);
+}
+
 int
 mutool_filter (int argc, char **argv)
 {
@@ -111,7 +139,17 @@ mutool_filter (int argc, char **argv)
   argc -= index;
   argv += index;
 
-  if (argc != 1)
+  if (list_option)
+    {
+      if (argc)
+	{
+	  mu_error (_("excess arguments"));
+	  return 1;
+	}
+      return list_filters ();
+    }
+  
+  if (argc == 0)
     {
       mu_error (_("what filter do you want?"));
       return 1;
@@ -136,7 +174,8 @@ mutool_filter (int argc, char **argv)
   if (line_length_option)
     reset_line_length (fltname, line_length);
 
-  rc = mu_filter_create (&flt, in, fltname, filter_mode, MU_STREAM_READ);
+  rc = mu_filter_create_args (&flt, in, fltname, argc, (const char **)argv,
+			      filter_mode, MU_STREAM_READ);
   if (rc)
     {
       mu_error (_("cannot open filter stream: %s"), mu_strerror (rc));


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 18 03:41:16 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PJ03Q-0002kX-EY
	for mharc-commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:41:16 -0500
Received: from [140.186.70.92] (port=52385 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PJ03M-0002jo-9d
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:41:14 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ03K-0002Wl-32
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:41:12 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:44743
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ03J-0002Wg-Vp
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:41:10 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ03J-0004Ln-Da
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 08:41:09 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ03A-0007rm-8G
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 08:41:09 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 110d13ec5187a06c59a53deb0f76b2e944c334ef
X-Git-Newrev: 820568fbf17c86fd4e68fff5e056c1c6deb1a319
Message-Id: <E1PJ03A-0007rm-8G@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 18 Nov 2010 08:41:01 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-201-g820568f
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Nov 2010 08:41:14 -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=820568fbf17c86fd4e68fff5e056c1c6deb1a319

The branch, master has been updated
       via  820568fbf17c86fd4e68fff5e056c1c6deb1a319 (commit)
      from  110d13ec5187a06c59a53deb0f76b2e944c334ef (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 820568fbf17c86fd4e68fff5e056c1c6deb1a319
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 18 10:36:46 2010 +0200

    mh: implement prompter
    
    * configure.ac (MU_COND_READLINE): New cond.
    * mh/prompter.c: New file.
    * mh/prompter-rl.c: New file.
    * mh/prompter-tty.c: New file.
    * mh/prompter.h: New file.
    * mh/TODO: Update.
    * mh/Makefile.am: Build prompter.
    
    * doc/texinfo/mu-mh.texi: Document prompter
    * po/POTFILES.in: Update.

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

Summary of changes:
 configure.ac                          |    6 +-
 doc/texinfo/mu-mh.texi                |   63 +++++--
 mh/Makefile.am                        |   16 ++
 mh/TODO                               |    2 +
 testsuite/mbdel.c => mh/prompter-rl.c |   80 +++++----
 mh/prompter-tty.c                     |  197 +++++++++++++++++++++
 mh/prompter.c                         |  313 +++++++++++++++++++++++++++++++++
 mail/list.c => mh/prompter.h          |   23 +--
 po/POTFILES.in                        |    2 +
 9 files changed, 635 insertions(+), 67 deletions(-)
 copy testsuite/mbdel.c => mh/prompter-rl.c (53%)
 create mode 100644 mh/prompter-tty.c
 create mode 100644 mh/prompter.c
 copy mail/list.c => mh/prompter.h (67%)

diff --git a/configure.ac b/configure.ac
index 67ddf6b..7c9df0a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -909,7 +909,7 @@ AC_SUBST(CURSES_LIBS)
 dnl Check for GNU Readline
 AC_SUBST(READLINE_LIBS)
 
-if test x"$usereadline" = x"yes"; then
+if test "$usereadline" = "yes"; then
 
 	dnl FIXME This should only link in the curses libraries if it's
 	dnl really needed!
@@ -919,7 +919,7 @@ if test x"$usereadline" = x"yes"; then
 	AC_CHECK_LIB(readline, readline, mu_have_readline=yes)
 	LIBS=$saved_LIBS
 
-	if test x"$mu_have_readline" = x"yes"; then
+	if test "$mu_have_readline" = "yes"; then
 		AC_CHECK_HEADERS(readline/readline.h,
 			AC_DEFINE(WITH_READLINE,1,[Enable use of readline]))
 			READLINE_LIBS="-lreadline $CURSES_LIBS"
@@ -933,6 +933,8 @@ if test x"$usereadline" = x"yes"; then
 
 fi
 
+AM_CONDITIONAL([MU_COND_READLINE], [test "$usereadline" = "yes"])
+
 AH_BOTTOM([
 /* Newer versions of readline have rl_completion_matches */
 #ifndef HAVE_RL_COMPLETION_MATCHES
diff --git a/doc/texinfo/mu-mh.texi b/doc/texinfo/mu-mh.texi
index b04a34c..99ebaeb 100644
--- a/doc/texinfo/mu-mh.texi
+++ b/doc/texinfo/mu-mh.texi
@@ -311,25 +311,6 @@ behaviour is disabled when @option{--quiet} option was given.
 
 The @option{--all} mode does not display commented out entries.
 
-@item repl
-
-Understands @option{--use} option. Disposition shell provides
-@code{use} command. 
-
-@item rmm
-
-@enumerate 1
-@item
-Different behaviour if one of the messages in the list does not exist:
-
-Mailutils @command{rmm} does not delete any messages. Standard
-@command{rmm} in this case deletes all messages preceding the
-non-existent one. 
-
-@item
-The @code{rmmproc} profile component is not used.
-@end enumerate
-
 @item pick
 
 The command line syntax @option{--@var{component} @var{string}}) is
@@ -388,6 +369,31 @@ pick --before '1 year ago'
 etc...
 @end smallexample
 
+@item prompter
+@enumerate
+@item
+Prompter attempts to use GNU Readline library, if it is installed.
+Consequently, arguments to @option{-erase} and @option{-kill} option
+must follow GNU style key sequence notation (@pxref{Readline Init File
+Syntax, keyseq,,readline,GNU Readline Library}).
+
+If @command{prompter} is built without @command{readline}, it accepts
+the following character notations:
+
+@table @asis
+@item \@var{nnnn}
+Here, @var{n} stands for a single octal digit.
+
+@item ^@var{chr}
+This notation is translated to the ASCII code @samp{@var{chr} + 0100}.
+@end table
+
+@item
+Component continuation lines are not required to begin with a
+whitespace.  If leading whitespace is not present, @command{prompter}
+will add it automatically.
+@end enumerate
+
 @item refile
 
 @enumerate
@@ -405,6 +411,25 @@ compatibility only.
 Message specs and folder names may be interspersed.
 @end enumerate
 
+@item repl
+
+Understands @option{--use} option. Disposition shell provides
+@code{use} command. 
+
+@item rmm
+
+@enumerate 1
+@item
+Different behaviour if one of the messages in the list does not exist:
+
+Mailutils @command{rmm} does not delete any messages. Standard
+@command{rmm} in this case deletes all messages preceding the
+non-existent one. 
+
+@item
+The @code{rmmproc} profile component is not used.
+@end enumerate
+
 @item sortm
 
 New option @option{--numfield} specifies numeric comparison for the
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 2c52f55..08218b2 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -34,6 +34,7 @@ bin_PROGRAMS = \
  mhparam\
  mhpath\
  pick\
+ prompter\
  refile\
  repl\
  rmf\
@@ -44,6 +45,21 @@ bin_PROGRAMS = \
  whatnow\
  whom
 
+prompter_LDADD = $(mh_LIBS)
+
+if MU_COND_READLINE
+  PROMPTER_FUN=prompter-rl.c
+  prompter_LDADD += @READLINE_LIBS@
+else
+  PROMPTER_FUN=prompter-tty.c
+  prompter_LDADD += @CURSES_LIBS@
+endif
+
+prompter_SOURCES = \
+ prompter.c\
+ prompter.h\
+ $(PROMPTER_FUN)
+
 noinst_LIBRARIES = libmh.a
 
 libmh_a_SOURCES= \
diff --git a/mh/TODO b/mh/TODO
index 8dfe2c6..ba6b410 100644
--- a/mh/TODO
+++ b/mh/TODO
@@ -40,6 +40,7 @@ State	Nice	Utility		Comments
 +	10	mhpath
 +	10	whatnow		
 +	20	sortm
++       20      prompter
 
 Utilities In Alphabetical Order
 ===============================
@@ -55,6 +56,7 @@ mhl
 mhn
 mhpath
 pick
+prompter
 refile
 repl
 rmf
diff --git a/testsuite/mbdel.c b/mh/prompter-rl.c
similarity index 53%
copy from testsuite/mbdel.c
copy to mh/prompter-rl.c
index e1c7339..731c9cb 100644
--- a/testsuite/mbdel.c
+++ b/mh/prompter-rl.c
@@ -14,41 +14,55 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <mailutils/mailutils.h>
-
-int
-main (int argc, char **argv)
+/* MH prompter - readline support */
+
+#include <mh.h>
+#include "prompter.h"
+#include <readline/readline.h>
+
+void
+prompter_init ()
 {
-  int rc;
-  mu_mailbox_t mbox;
-  
-  if (argc != 2)
-    {
-      fprintf (stderr, "usage: %s URL\n", argv[0]);
-      return 1;
-    }
+}
+
+void
+prompter_done ()
+{
+}
+
+void
+prompter_set_erase (const char *keyseq)
+{
+  rl_bind_keyseq (keyseq, rl_delete);
+}
 
-  mu_register_all_mbox_formats ();
-  
-  MU_ASSERT (mu_mailbox_create (&mbox, argv[1]));
-  rc = mu_mailbox_remove (mbox);
-  if (rc)
+void
+prompter_set_kill (const char *keyseq)
+{
+  rl_bind_keyseq (keyseq, rl_kill_full_line);
+}
+
+char *
+prompter_get_value (const char *name)
+{
+  char *prompt = NULL;
+  char *val;
+
+  if (name)
     {
-      if (rc == ENOTEMPTY)
-	{
-	  printf ("mailbox removed, but has subfolders\n");
-	  rc = 0;
-	}
-      else
-	fprintf (stderr, "%s\n", mu_strerror (rc));
+      prompt = xmalloc (strlen (name) + 3);
+      strcpy (prompt, name);
+      strcat (prompt, ": ");
     }
-  mu_mailbox_destroy (&mbox);
-  
-  return rc != 0;
+  val = readline (prompt);
+  free (prompt);
+  return val;
 }
+
+char *
+prompter_get_line ()
+{
+  return doteof_filter (readline (NULL));
+}
+
+
diff --git a/mh/prompter-tty.c b/mh/prompter-tty.c
new file mode 100644
index 0000000..92c3f3f
--- /dev/null
+++ b/mh/prompter-tty.c
@@ -0,0 +1,197 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* MH prompter - traditional tty/termios support */
+
+#include <mh.h>
+#include "prompter.h"
+#include "muaux.h"
+#if HAVE_TERMIOS_H
+# include <termios.h>
+#endif
+
+mu_stream_t strin;
+#if HAVE_TCGETATTR
+struct termios tios;
+#endif
+
+static int
+decode_key (const char *keyseq)
+{
+  if (keyseq[0] == '^' && keyseq[1])
+    {
+      if (keyseq[2])
+	{
+	  mu_error (_("invalid keysequence (%s near %d)"),
+		    keyseq, 2);
+	  exit (1);
+	}
+      return keyseq[1] + 0100;
+    }
+  else if (keyseq[0] == '\\')
+    {
+      int i;
+      int c = 0;
+      for (i = 1; i <= 3; i++)
+	{
+	  int n;
+	  switch (keyseq[i])
+	    {
+	    case '0':
+	      n = 0;
+	      break;
+	    case '1':
+	      n = 1;
+	      break;
+	    case '2':
+	      n = 2;
+	      break;
+	    case '3':
+	      n = 3;
+	      break;
+	    case '4':
+	      n = 4;
+	      break;
+	    case '5':
+	      n = 5;
+	      break;
+	    case '6':
+	      n = 6;
+	      break;
+	    case '7':
+	      n = 7;
+	      break;
+	    default:
+	      mu_error (_("invalid keysequence (%s near %d)"),
+			keyseq, i);
+	      exit (1);
+	    }
+	  c = (c << 3) + n;
+	}
+      if (keyseq[i])
+	{
+	  mu_error (_("invalid keysequence (%s near %d)"),
+		    keyseq, i);
+	  exit (1);
+	}
+      return c;
+    }
+  else if (keyseq[1])
+    {
+      mu_error (_("invalid keysequence (%s near %d)"),
+		keyseq, 2);
+      exit (1);
+    }
+
+  return keyseq[0];
+}
+
+static RETSIGTYPE
+sighan (int signo)
+{
+  prompter_done ();
+  exit (0);
+}
+
+void
+prompter_init ()
+{
+  int rc;
+  if ((rc = mu_stdio_stream_create (&strin, MU_STDIN_FD, MU_STREAM_READ)))
+    {
+      mu_error (_("cannot open stdout: %s"), mu_strerror (rc));
+      exit (1);
+    }
+#if HAVE_TCGETATTR
+  rc = tcgetattr (MU_STDOUT_FD, &tios);
+  if (rc)
+    {
+      mu_error (_("tcgetattr failed: %s"), mu_strerror (rc));
+      exit (1);
+    }
+  else
+    {
+      static int sigtab[] = { SIGPIPE, SIGABRT, SIGINT, SIGQUIT, SIGTERM };
+      mu_set_signals (sighan, sigtab, MU_ARRAY_SIZE (sigtab));
+    }
+#endif
+}
+
+void
+prompter_done ()
+{
+#if HAVE_TCGETATTR
+  int rc = tcsetattr (MU_STDOUT_FD, TCSANOW, &tios);
+  if (rc)
+    mu_error (_("tcsetattr failed: %s"), mu_strerror (rc));
+#endif
+}
+
+void
+prompter_set_erase (const char *keyseq)
+{
+#if HAVE_TCGETATTR
+  int rc;
+  struct termios t = tios;
+  
+  t.c_lflag |= ICANON;
+  t.c_cc[VERASE] = decode_key (keyseq);
+  rc = tcsetattr (MU_STDOUT_FD, TCSANOW, &t);
+  if (rc)
+    mu_error (_("tcsetattr failed: %s"), mu_strerror (rc));
+#endif
+}
+
+void
+prompter_set_kill (const char *keyseq)
+{
+#if HAVE_TCGETATTR
+  int rc;
+  struct termios t = tios;
+  
+  t.c_lflag |= ICANON;
+  t.c_cc[VKILL] = decode_key (keyseq);
+  rc = tcsetattr (MU_STDOUT_FD, TCSANOW, &t);
+  if (rc)
+    mu_error (_("tcsetattr failed: %s"), mu_strerror (rc));
+#endif
+}
+
+char *
+prompter_get_value (const char *name)
+{
+  size_t size = 0, n;
+  char *buf = NULL;
+  
+  mu_stream_printf (strout, "%s: ", name);
+  mu_stream_flush (strout);
+  if (mu_stream_getline (strin, &buf, &size, &n) || n == 0)
+    return NULL;
+  mu_rtrim_cset (buf, "\n");
+  return buf;
+}
+
+char *
+prompter_get_line ()
+{
+  size_t size = 0, n;
+  char *buf = NULL;
+  
+  if (mu_stream_getline (strin, &buf, &size, &n) || n == 0)
+    return NULL;
+  mu_rtrim_cset (buf, "\n");
+  return doteof_filter (buf);
+}
diff --git a/mh/prompter.c b/mh/prompter.c
new file mode 100644
index 0000000..1131c4e
--- /dev/null
+++ b/mh/prompter.c
@@ -0,0 +1,313 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* MH prompter command */
+
+#include <mh.h>
+#include "prompter.h"
+
+static char doc[] = N_("GNU MH prompter")"\v"
+N_("Use -help to obtain the list of traditional MH options.");
+static char args_doc[] = N_("FILE");
+
+enum {
+  ARG_ERASE=256,
+  ARG_KILL,
+  ARG_PREPEND,
+  ARG_NOPREPEND,
+  ARG_RAPID,
+  ARG_NORAPID,
+  ARG_DOTEOF,
+  ARG_NODOTEOF
+};
+
+static struct argp_option options[] = {
+  { "erase",         ARG_ERASE,         N_("CHAR"), 0,
+    N_("set erase character") },
+  { "kill",          ARG_KILL,          N_("CHAR"), 0,
+    N_("set kill character") },
+  { "prepend",       ARG_PREPEND,       N_("BOOL"), 0,
+    N_("prepend user input to the message body") },
+  { "noprepend",     ARG_NOPREPEND,     NULL, OPTION_HIDDEN,
+    NULL },
+  { "rapid",         ARG_RAPID,         N_("BOOL"), 0,
+    N_("do not display message body") },
+  { "norapid",       ARG_NORAPID,       NULL, OPTION_HIDDEN,
+    NULL },
+  { "doteof",        ARG_DOTEOF,        N_("BOOL"), 0,
+    N_("a period on a line marks end-of-file") },
+  { "nodoteof",      ARG_NODOTEOF,      NULL, OPTION_HIDDEN,
+    NULL },
+  { NULL }
+};
+
+struct mh_option mh_option[] = {
+  { "erase", MH_OPT_ARG, "chr" },
+  { "kill",  MH_OPT_ARG, "chr" },
+  { "prepend", MH_OPT_BOOL },
+  { "rapid", MH_OPT_BOOL },
+  { "doteof", MH_OPT_BOOL },
+  { NULL }
+};
+
+char *erase_seq;
+char *kill_seq;
+int prepend_option;
+int rapid_option;
+int doteof_option;
+
+static error_t
+opt_handler (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+    {
+    case ARG_ERASE:
+      erase_seq = arg;
+      break;
+      
+    case ARG_KILL:
+      kill_seq = arg;
+      break;
+      
+    case ARG_PREPEND:
+      prepend_option = is_true (arg);
+      break;
+      
+    case ARG_NOPREPEND:
+      prepend_option = 0;
+      break;
+      
+    case ARG_RAPID:
+      rapid_option = is_true (arg);
+      break;
+      
+    case ARG_NORAPID:
+      rapid_option = 0;
+      break;
+      
+    case ARG_DOTEOF:
+      doteof_option = is_true (arg);
+      break;
+      
+    case ARG_NODOTEOF:
+      doteof_option = 0;
+      break;
+
+    default:
+      return ARGP_ERR_UNKNOWN;
+   }
+  return 0;
+}
+
+static int
+is_empty_string (const char *str)
+{
+  if (!str)
+    return 1;
+  return mu_str_skip_class (str, MU_CTYPE_BLANK)[0] == 0;
+}
+
+char *
+doteof_filter (char *val)
+{
+  if (!val)
+    return NULL;
+  if (doteof_option && val[0] == '.')
+    {
+      if (val[1] == 0)
+	{
+	  free (val);
+	  return NULL;
+	}
+      memmove (val, val + 1, strlen (val + 1) + 1);
+    }
+  return val;
+}
+
+mu_stream_t strout;
+
+int
+main (int argc, char **argv)
+{
+  int index;
+  int rc;
+  mu_stream_t in, tmp;
+  mu_message_t msg;
+  mu_header_t hdr;
+  mu_iterator_t itr;
+  const char *file;
+  char *newval;
+  mu_off_t size;
+  mu_body_t body;
+  mu_stream_t bstr;
+  
+  MU_APP_INIT_NLS ();
+  
+  mh_argp_init ();
+  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
+		 opt_handler, NULL, &index);
+
+  if (index == argc)
+    {
+      mu_error (_("file name not given"));
+      exit (1);
+    }
+  file = argv[index];
+
+  prompter_init ();
+  if (erase_seq)
+    prompter_set_erase (erase_seq);
+  if (kill_seq)
+    prompter_set_erase (kill_seq);
+
+  if ((rc = mu_stdio_stream_create (&strout, MU_STDOUT_FD, MU_STREAM_WRITE)))
+    {
+      mu_error (_("cannot open stdout: %s"), mu_strerror (rc));
+      return 1;
+    }
+  
+  if ((rc = mu_file_stream_create (&in, file, MU_STREAM_RDWR)))
+    {
+      mu_error (_("cannot open input file `%s': %s"),
+		file, mu_strerror (rc));
+      return 1;
+    }
+  rc = mu_stream_to_message (in, &msg);
+  if (rc)
+    {
+      mu_error (_("input stream %s is not a message (%s)"),
+		file, mu_strerror (rc));
+      return 1;
+    }
+  
+  if ((rc = mu_temp_file_stream_create (&tmp, NULL))) 
+    {
+      mu_error (_("Cannot open temporary file: %s"),
+		mu_strerror (rc));
+      return 1;
+    }
+
+  /* Copy headers */
+  mu_message_get_header (msg, &hdr);
+  mu_header_get_iterator (hdr, &itr);
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name, *val;
+      
+      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
+      if (!is_empty_string (val))
+	{
+	  mu_stream_printf (tmp, "%s: %s\n", name, val);
+	  mu_stream_printf (strout, "%s: %s\n", name, val);
+	}
+      else
+	{
+	  int cont = 0;
+	  mu_opool_t opool;
+	  const char *prompt = name;
+	  
+	  mu_opool_create (&opool, 1);
+	  do
+	    {
+	      size_t len;
+	      char *p;
+	      p = prompter_get_value (prompt);
+	      if (!p)
+		return 1;
+	      prompt = NULL;
+	      if (cont)
+		{
+		  mu_opool_append_char (opool, '\n');
+		  if (!mu_isspace (p[0]))
+		    mu_opool_append_char (opool, '\t');
+		}
+	      len = strlen (p);
+	      if (len > 0 && p[len-1] == '\\')
+		{
+		  len--;
+		  cont = 1;
+		}
+	      else
+		cont = 0;
+	      mu_opool_append (opool, p, len);
+	      free (p);
+	    }
+	  while (cont);
+
+	  newval = mu_opool_finish (opool, NULL);
+	  if (!is_empty_string (newval))
+	    mu_stream_printf (tmp, "%s: %s\n", name, newval);
+	  mu_opool_destroy (&opool);
+	}
+    }
+  mu_stream_printf (strout, "--------\n");
+  mu_stream_write (tmp, "\n", 1, NULL);
+
+  /* Copy body */
+  
+  if (prepend_option)
+    {
+      mu_stream_printf (strout, "\n--------%s\n\n", _("Enter initial text"));
+      while (newval = prompter_get_line ())
+	{
+	  mu_stream_write (tmp, newval, strlen (newval), NULL);
+	  free (newval);
+	  mu_stream_write (tmp, "\n", 1, NULL);
+	}
+    }
+
+  mu_message_get_body (msg, &body);
+  mu_body_get_streamref (body, &bstr);
+
+  if (!prepend_option && !rapid_option)
+    {
+      mu_stream_copy (strout, bstr, 0, NULL);
+      mu_stream_seek (bstr, 0, MU_SEEK_SET, NULL);
+    }
+
+  mu_stream_copy (tmp, bstr, 0, NULL);
+  mu_stream_unref (bstr);
+
+  if (!prepend_option && !rapid_option)
+    {
+      printf ("\n--------%s\n\n", _("Enter additional text"));
+      while (newval = prompter_get_line ())
+	{
+	  mu_stream_write (tmp, newval, strlen (newval), NULL);
+	  free (newval);
+	  mu_stream_write (tmp, "\n", 1, NULL);
+	}
+    }
+
+  /* Destroy the message */
+  mu_message_destroy (&msg, mu_message_get_owner (msg));
+
+  /* Rewind the streams and copy data back to in. */
+  mu_stream_seek (in, 0, MU_SEEK_SET, NULL);
+  mu_stream_seek (tmp, 0, MU_SEEK_SET, NULL);
+  mu_stream_copy (in, tmp, 0, &size);
+  mu_stream_truncate (in, size);
+
+  mu_stream_destroy (&in);
+  mu_stream_destroy (&tmp);
+  mu_stream_destroy (&strout);
+
+  prompter_done ();
+  
+  return 0;
+}
+
diff --git a/mail/list.c b/mh/prompter.h
similarity index 67%
copy from mail/list.c
copy to mh/prompter.h
index a6eb18f..cdaf838 100644
--- a/mail/list.c
+++ b/mh/prompter.h
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001, 2005, 2007, 2010 Free Software Foundation,
-   Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,16 +14,14 @@
    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 "mail.h"
+void prompter_init (void);
+void prompter_done (void);
+void prompter_set_erase (const char *keyseq);
+void prompter_set_kill (const char *keyseq);
+char *prompter_get_value (const char *name);
+char *prompter_get_line (void);
+char *doteof_filter (char *val);
+
+extern mu_stream_t strout;
 
-/*
- * l[ist]
- * *
- */
 
-int
-mail_list (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
-{
-  mail_command_list ();
-  return 0;
-}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8d2e5e6..001f754 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -179,6 +179,8 @@ mh/mhl.c
 mh/mhn.c
 mh/mhpath.c
 mh/pick.c
+mh/prompter.c
+mh/prompter-tty.c
 mh/refile.c
 mh/repl.c
 mh/rmf.c


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 18 03:48:12 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PJ0A8-0004Hk-L6
	for mharc-commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:48:12 -0500
Received: from [140.186.70.92] (port=53218 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PJ0A6-0004GV-JK
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:48:11 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ0A5-0003WS-7A
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:48:10 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:55521
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ0A5-0003WM-4U
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 03:48:09 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ0A4-0004PM-DD
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 08:48:08 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJ0A4-0008U1-7H
	for commit-mailutils@gnu.org; Thu, 18 Nov 2010 08:48:08 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 820568fbf17c86fd4e68fff5e056c1c6deb1a319
X-Git-Newrev: 1a8279af0d705aa7121805613fcba9963fb1b4ec
Message-Id: <E1PJ0A4-0008U1-7H@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 18 Nov 2010 08:48:08 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-202-g1a8279a
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 18 Nov 2010 08:48:11 -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=1a8279af0d705aa7121805613fcba9963fb1b4ec

The branch, master has been updated
       via  1a8279af0d705aa7121805613fcba9963fb1b4ec (commit)
      from  820568fbf17c86fd4e68fff5e056c1c6deb1a319 (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 1a8279af0d705aa7121805613fcba9963fb1b4ec
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 18 10:47:42 2010 +0200

    Minor fix.
    
    * mh/prompter.c (main): Append terminating \0 to the opool.

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

Summary of changes:
 mh/prompter.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/mh/prompter.c b/mh/prompter.c
index 1131c4e..7de7a43 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -248,6 +248,7 @@ main (int argc, char **argv)
 	    }
 	  while (cont);
 
+	  mu_opool_append_char (opool, 0);
 	  newval = mu_opool_finish (opool, NULL);
 	  if (!is_empty_string (newval))
 	    mu_stream_printf (tmp, "%s: %s\n", name, newval);


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Nov 20 09:52:35 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PJonr-00032n-I6
	for mharc-commit-mailutils@gnu.org; Sat, 20 Nov 2010 09:52:35 -0500
Received: from [140.186.70.92] (port=50279 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PJonj-00032e-ID
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 09:52:34 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJond-0006BP-4T
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 09:52:27 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:52904
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJonc-0006BL-UE
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 09:52:21 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJonc-00009h-OU
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 14:52:20 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJonX-0001EL-5d
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 14:52:20 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 1a8279af0d705aa7121805613fcba9963fb1b4ec
X-Git-Newrev: c08b926f664b27953483a0dffcbe381ddaa154e5
Message-Id: <E1PJonX-0001EL-5d@vcs-noshell.in.savannah.gnu.org>
Date: Sat, 20 Nov 2010 14:52:15 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-205-gc08b926
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 20 Nov 2010 14:52:34 -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=c08b926f664b27953483a0dffcbe381ddaa154e5

The branch, master has been updated
       via  c08b926f664b27953483a0dffcbe381ddaa154e5 (commit)
       via  77d2867d07ba9d1c5b8b0af1ba8b0543cf57f384 (commit)
       via  33a277e9f8e8541fee73f902413afb100e48b95c (commit)
      from  1a8279af0d705aa7121805613fcba9963fb1b4ec (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 c08b926f664b27953483a0dffcbe381ddaa154e5
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Nov 20 16:30:31 2010 +0200

    Re-implement MH sequences via mailbox properties.
    
    * libmailutils/mailbox/header.c (mu_header_clear): New function.
    (mu_header_sget_value_n): Tolerate pval == NULL.
    * libmailutils/property/assocprop.c (_assoc_prop_setval): Bugfix.
    (_assoc_prop_clear): New method.
    (mu_assoc_property_init): Reference the stream.
    (mu_assoc_property_init): Initialize _prop_clear.
    * libmailutils/property/create.c (_mu_property_init): Now extern.
    * libmailutils/property/propset.c (mu_property_set_value): Null value
    means unset.
    * libmailutils/tests/prop.at: Test property clear and invalidate.
    * libmailutils/tests/prop.c: New commands: 0 for property clear and ! for
    invalidate.
    
    * libmailutils/property/mhprop.c: New file.
    * libmailutils/property/propclr.c: New file.
    * libmailutils/property/propinv.c: New file.
    * libmailutils/property/Makefile.am (noinst_LTLIBRARIES): Add new files.
    
    * include/mailutils/header.h (mu_header_clear): New proto.
    * include/mailutils/property.h (mu_property_clear)
    (mu_property_invalidate): New protos.
    (mu_mh_prop): New struct.
    (mu_mh_property_init): New proto.
    * include/mailutils/sys/property.h (_mu_property) <_prop_clear>: New member.
    (_mu_property_init): New proto.
    * include/mailutils/mh.h: New file.
    * include/mailutils/Makefile.am (pkginclude_HEADERS): Add mh.h
    
    * libproto/mh/profile.c: New file.
    * libproto/mh/Makefile.am (libmu_mh_la_SOURCES): Add new files.
    
    * libproto/mh/mbox.c (mh_get_property): New static function.
    (_mailbox_mh_init): Set _get_property.
    
    * mh/mh_global.c (current_message, sequences): Remove.  Use mbox
    properties instead.
    (mh_global_sequences_get)
    (mh_global_sequences_set)
    (mh_global_sequences_iterate)
    (mh_global_sequences_drop): Take mbox as first argument. All callers
    updated.
    * mh/mh_init.c (mh_init2): Remove call to mh_global_sequences_get.
    * mh/mh_msgset.c (msgset_cur): Use mh_mailbox_get_cur.
    * mh/mh_sequence.c (mh_seq_read, write_sequence)
    (delete_sequence, mh_seq_add, mh_seq_delete): Take mbox as first argument.
    All callers updated.
    
    * mh/mh.h: Include mailutils/property.h.
    (current_message): Remove.
    (mh_mailbox_cur_default): New extern.
    (mh_global_sequences_get)
    (mh_global_sequences_set)
    (mh_global_sequences_iterate)
    (mh_global_sequences_drop): Take mbox as first argument. All callers
    updated.
    
    * mh/mh_format.c (builtin_cur): Rewrite using mh_message_number.
    
    * mh/mboxprop.c: New file.
    * mh/Makefile.am (libmh_a_SOURCES): Add new file.
    
    * mh/folder.c: Update calls to sequence management functions.
    * mh/mark.c: Likewise.
    * mh/pick.c: Likewise.
    
    * mh/inc.c (main): Set mh_mailbox_cur_default to 1.
    Invalidate properties if changecur is not set.
    * mh/prompter.c (main): Destroy the iterator.
    * mh/rmf.c: Rewrite using mu_mailbox_remove.
    * mh/scan.c: Always close the mailbox.
    
    * mh/tests/folder.at: Update.
    * mh/tests/inc.at: Update.  Inc now sets cur to 1 if it was not
    originally set.  This is what others MHs do.

commit 77d2867d07ba9d1c5b8b0af1ba8b0543cf57f384
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 18 20:27:18 2010 +0200

    Rewrite property support.
    
    * configure.ac: Add libmailutils/property/Makefile to config files.
    
    * include/mailutils/property.h (mu_property_create)
    (mu_property_destroy): Change signature.
    (mu_property_get_owner): Remove.
    (mu_property_create_init)
    (mu_property_set_init, mu_property_set_init_data)
    (mu_property_ref, mu_property_unref)
    (mu_property_save): New protos.
    (mu_property_get_iterator)
    (mu_assoc_property_init): New protos.
    * include/mailutils/sys/property.h (property_item): Remove definition.
    (MU_PROP_INIT, MU_PROP_FILL, MU_PROP_MODIFIED): New flags.
    (_mu_property): Rewrite from scratch.
    (_mu_property_check): New proto.
    
    * libmailutils/property/Makefile.am: New file.
    * libmailutils/property/assocprop.c: New file.
    * libmailutils/property/create.c: New file.
    * libmailutils/property/propget.c: New file.
    * libmailutils/property/propitr.c: New file.
    * libmailutils/property/propset.c: New file.
    
    * libmailutils/Makefile.am (SUBDIRS): Add property.
    (libmailutils_la_LIBADD): Add property/libproperty.la.
    
    * libmailutils/base/property.c: Remove.
    * libmailutils/base/Makefile.am (libbase_la_SOURCES): Remove property.c
    
    * libmailutils/base/assoc.c (first): Avoid coredumping on empty
    hash table.
    
    * include/mailutils/folder.h (mu_folder_set_property)
    (mu_folder_get_property): New protos.
    * include/mailutils/sys/folder.h (_mu_folder) <property>
    <_get_property>: New members.
    * libmailutils/mailbox/folder.c (mu_folder_destroy): Destroy the
    property.
    (mu_folder_get_property)
    (mu_folder_set_property): New functions.
    
    * include/mailutils/mailbox.h (mu_mailbox_set_property): New proto.
    * libmailutils/mailbox/mailbox.c (mu_mailbox_set_property): New function.
    (mu_mailbox_get_property): Use _get_property method.
    
    * include/mailutils/mailer.h (mu_mailer_set_property): New proto.
    * include/mailutils/sys/mailer.h (_mu_mailer) <_get_property>: New member.
    * libmailutils/mailer/mailer.c (mu_mailer_set_property): New function.
    (mu_mailer_get_property): Use _get_property method.
    
    * include/mailutils/iterator.h (mu_iterator_set_dataptr): New proto.
    * include/mailutils/sys/iterator.h (_mu_iterator) <dataptr>: New method.
    * libmailutils/base/iterator.c (mu_iterator_set_dataptr): New function.
    (mu_iterator_current): Rewrite as a wrapper around mu_iterator_current_kv.
    (mu_iterator_current_kv): Use dataptr method (if defined) to extract the
    data pointer.
    
    * libmailutils/tests/prop.c: New file.
    * libmailutils/tests/prop.at: New file.
    * libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add prop.
    (TESTSUITE_AT): Add prop.at.
    * libmailutils/tests/testsuite.at: Include prop.at.

commit 33a277e9f8e8541fee73f902413afb100e48b95c
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 18 20:05:25 2010 +0200

    mh: Minor fixes.

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

Summary of changes:
 configure.ac                                       |    1 +
 include/mailutils/Makefile.am                      |    1 +
 include/mailutils/folder.h                         |    4 +
 include/mailutils/header.h                         |    1 +
 include/mailutils/iterator.h                       |    2 +
 include/mailutils/mailbox.h                        |    1 +
 include/mailutils/mailer.h                         |    2 +
 mail/version.c => include/mailutils/mh.h           |   52 ++---
 include/mailutils/property.h                       |   51 +++--
 include/mailutils/sys/folder.h                     |    2 +
 include/mailutils/sys/iterator.h                   |    1 +
 include/mailutils/sys/mailer.h                     |    1 +
 include/mailutils/sys/property.h                   |   42 +++-
 libmailutils/Makefile.am                           |    3 +-
 libmailutils/base/Makefile.am                      |    1 -
 libmailutils/base/assoc.c                          |    9 +-
 libmailutils/base/iterator.c                       |   22 ++-
 libmailutils/base/property.c                       |  191 ----------------
 libmailutils/mailbox/folder.c                      |   28 +++
 libmailutils/mailbox/header.c                      |   20 ++-
 libmailutils/mailbox/mailbox.c                     |   22 ++-
 libmailutils/mailer/mailer.c                       |   22 ++-
 libmailutils/{mime => property}/Makefile.am        |   15 +-
 libmailutils/property/assocprop.c                  |  228 ++++++++++++++++++
 libmailutils/property/create.c                     |  166 ++++++++++++++
 libmailutils/property/mhprop.c                     |  241 ++++++++++++++++++++
 libmailutils/{url/urlstr.c => property/propclr.c}  |   23 ++-
 libmailutils/property/propget.c                    |   83 +++++++
 .../{url/get-secret.c => property/propinv.c}       |   36 ++--
 .../radius.h => libmailutils/property/propitr.c    |   29 ++-
 libmailutils/property/propset.c                    |   70 ++++++
 libmailutils/tests/.gitignore                      |    1 +
 libmailutils/tests/Makefile.am                     |    2 +
 libmailutils/tests/prop.at                         |  124 ++++++++++
 libmailutils/tests/prop.c                          |  158 +++++++++++++
 libmailutils/tests/testsuite.at                    |    1 +
 libproto/mh/Makefile.am                            |    3 +-
 libproto/mh/mbox.c                                 |   38 +++-
 libproto/mh/profile.c                              |   60 +++++
 mh/.gitignore                                      |    1 +
 mh/Makefile.am                                     |    1 +
 mh/folder.c                                        |   32 ++-
 mh/inc.c                                           |   18 +-
 mh/mark.c                                          |   36 ++-
 mh/mboxprop.c                                      |   74 ++++++
 mh/mh.h                                            |   30 ++-
 mh/mh_format.c                                     |   13 +-
 mh/mh_format.h                                     |    2 +-
 mh/mh_global.c                                     |  107 ++++++----
 mh/mh_init.c                                       |    1 -
 mh/mh_msgset.c                                     |   28 ++-
 mh/mh_sequence.c                                   |   29 ++-
 mh/pick.c                                          |   17 ++-
 mh/prompter.c                                      |    5 +-
 mh/rmf.c                                           |   84 ++++---
 mh/scan.c                                          |    3 +-
 mh/tests/folder.at                                 |    2 -
 mh/tests/inc.at                                    |   36 +++-
 mu/Makefile.am                                     |    2 +-
 59 files changed, 1816 insertions(+), 462 deletions(-)
 copy mail/version.c => include/mailutils/mh.h (58%)
 delete mode 100644 libmailutils/base/property.c
 copy libmailutils/{mime => property}/Makefile.am (83%)
 create mode 100644 libmailutils/property/assocprop.c
 create mode 100644 libmailutils/property/create.c
 create mode 100644 libmailutils/property/mhprop.c
 copy libmailutils/{url/urlstr.c => property/propclr.c} (70%)
 create mode 100644 libmailutils/property/propget.c
 copy libmailutils/{url/get-secret.c => property/propinv.c} (67%)
 copy include/mailutils/radius.h => libmailutils/property/propitr.c (67%)
 create mode 100644 libmailutils/property/propset.c
 create mode 100644 libmailutils/tests/prop.at
 create mode 100644 libmailutils/tests/prop.c
 create mode 100644 libproto/mh/profile.c
 create mode 100644 mh/mboxprop.c

diff --git a/configure.ac b/configure.ac
index 7c9df0a..10d1e6a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1389,6 +1389,7 @@ AC_CONFIG_FILES([
  libmailutils/mailbox/Makefile
  libmailutils/mailer/Makefile
  libmailutils/mime/Makefile
+ libmailutils/property/Makefile
  libmailutils/server/Makefile
  libmailutils/string/Makefile
  libmailutils/stream/Makefile
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index cd17f85..b52db2c 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -67,6 +67,7 @@ pkginclude_HEADERS = \
  mailutils.h\
  md5.h\
  message.h\
+ mh.h\
  mime.h\
  monitor.h\
  mu_auth.h\
diff --git a/include/mailutils/folder.h b/include/mailutils/folder.h
index 6e5fc7f..742176a 100644
--- a/include/mailutils/folder.h
+++ b/include/mailutils/folder.h
@@ -89,6 +89,10 @@ extern int  mu_folder_set_authority  (mu_folder_t, mu_authority_t);
 extern int  mu_folder_get_url        (mu_folder_t, mu_url_t *);
 extern int  mu_folder_set_url        (mu_folder_t, mu_url_t);
 
+/* Property */
+extern int  mu_folder_set_property   (mu_folder_t, mu_property_t);  
+extern int  mu_folder_get_property   (mu_folder_t, mu_property_t *);
+  
 /* FIXME: not implemented */
 extern int  mu_folder_decrement      (mu_folder_t);
 
diff --git a/include/mailutils/header.h b/include/mailutils/header.h
index c326c5c..2c9d7e0 100644
--- a/include/mailutils/header.h
+++ b/include/mailutils/header.h
@@ -78,6 +78,7 @@ extern "C" {
 extern int mu_header_create (mu_header_t *, const char *, size_t);
 extern void mu_header_destroy (mu_header_t *);
 extern int mu_header_invalidate (mu_header_t);
+extern int mu_header_clear (mu_header_t header);
 
 extern int mu_header_is_modified (mu_header_t);
 extern int mu_header_clear_modified (mu_header_t);
diff --git a/include/mailutils/iterator.h b/include/mailutils/iterator.h
index d67c063..b6e4f5c 100644
--- a/include/mailutils/iterator.h
+++ b/include/mailutils/iterator.h
@@ -72,6 +72,8 @@ extern int mu_iterator_set_itrctl (mu_iterator_t itr,
 				   int (*itrctl) (void *,
 						  enum mu_itrctl_req,
 						  void *));
+extern int mu_iterator_set_dataptr (mu_iterator_t itr,
+				    void *(*dataptr) (void *));
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h
index 298e6e8..b2149ba 100644
--- a/include/mailutils/mailbox.h
+++ b/include/mailutils/mailbox.h
@@ -97,6 +97,7 @@ extern int  mu_mailbox_set_locker      (mu_mailbox_t, mu_locker_t);
 /* Property.  */
 extern int  mu_mailbox_get_flags       (mu_mailbox_t, int *);
 extern int  mu_mailbox_get_property    (mu_mailbox_t, mu_property_t *);
+extern int  mu_mailbox_set_property (mu_mailbox_t, mu_property_t);
 
 /* URL.  */
 extern int  mu_mailbox_get_url         (mu_mailbox_t, mu_url_t *);
diff --git a/include/mailutils/mailer.h b/include/mailutils/mailer.h
index f42f0eb..4d7f6c2 100644
--- a/include/mailutils/mailer.h
+++ b/include/mailutils/mailer.h
@@ -50,6 +50,8 @@ extern int mu_mailer_get_url_default       (const char** url);
 
 /* Accessor functions. */
 extern int mu_mailer_get_property   (mu_mailer_t, mu_property_t *);
+int mu_mailer_set_property (mu_mailer_t, mu_property_t);
+  
 extern int mu_mailer_get_stream     (mu_mailer_t, mu_stream_t *)
                                       __attribute__ ((deprecated));
 extern int mu_mailer_get_streamref  (mu_mailer_t, mu_stream_t *);
diff --git a/mail/version.c b/include/mailutils/mh.h
similarity index 58%
copy from mail/version.c
copy to include/mailutils/mh.h
index 12c907b..d986ee3 100644
--- a/mail/version.c
+++ b/include/mailutils/mh.h
@@ -15,40 +15,24 @@
    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 "mail.h"
+#ifndef _MAILUTILS_MH_H
+#define _MAILUTILS_MH_H
 
-/*
- * ve[rsion]
- */
+extern mu_property_t mu_mh_profile;
+extern mu_property_t mu_mh_context;
+
+#define MU_MH_SEQUENCES_FILE ".mh_sequences"
+#define MU_MH_USER_PROFILE ".mh_profile"
+#define MU_MH_GLOBAL_PROFILE "mh-profile"
+#define MU_MH_CONTEXT_FILE "context"
+
+typedef int (*mu_mhprop_iterator_t) (const char *field, const char *value,
+				     void *data);
+
+const char *mu_mhprop_get_value (mu_property_t prop, const char *name,
+				 const char *defval);
+int mu_mhprop_iterate (mu_property_t prop, mu_mhprop_iterator_t fp,
+		       void *data);
 
-static const char *with_defs[] =
-{
-#ifdef WITH_PTHREAD
-  "PTHREAD",
-#endif
-#ifdef WITH_BDB2
-  "BDB2",
-#endif
-#ifdef WITH_READLINE
-  "READLINE",
 #endif
-  NULL
-};
-
-
-int
-mail_version (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
-{ 
-  fprintf (ofile, "%s", program_version);
-  if (with_defs[0] != NULL)
-    {
-      int i;
-      fprintf (ofile, " (");
-      for (i = 0; with_defs[i]; i++)
-	fprintf (ofile, " %s", with_defs[i]);
-      fprintf (ofile, " )");
-    }
-  fprintf (ofile, "\n");
-
-  return 0;
-}
+
diff --git a/include/mailutils/property.h b/include/mailutils/property.h
index 1fb7334..40cbb8f 100644
--- a/include/mailutils/property.h
+++ b/include/mailutils/property.h
@@ -27,23 +27,46 @@
 extern "C" {
 #endif
 
-extern int  mu_property_create   (mu_property_t *, void *);
-extern void mu_property_destroy (mu_property_t *, void *);
-extern void *mu_property_get_owner (mu_property_t);
-
-extern int  mu_property_set_value (mu_property_t, const char *, const char *, int);
-extern int mu_property_get_value (mu_property_t, const char *, char *, size_t, 
-				  size_t *);
-extern int mu_property_sget_value (mu_property_t prop, const char *key,
-				   const char **buffer);
-extern int mu_property_aget_value (mu_property_t prop, const char *key,
-				   char **buffer);
+int mu_property_create   (mu_property_t *);
+int mu_property_create_init (mu_property_t *pprop,
+			     int (*initfun) (mu_property_t), void *initdata);
+int mu_property_set_init (mu_property_t prop,
+			  int (*initfun) (mu_property_t), void *initdata);
+int mu_property_set_init_data (mu_property_t prop, void *data,
+			       void **old_data);
+void mu_property_destroy (mu_property_t *pprop);
+
+void mu_property_ref (mu_property_t prop);
+void mu_property_unref (mu_property_t prop);
+int mu_property_save (mu_property_t prop);
+int mu_property_set_value (mu_property_t, const char *, const char *, int);
+int mu_property_get_value (mu_property_t, const char *, char *, size_t, 
+			   size_t *);
+int mu_property_sget_value (mu_property_t prop, const char *key,
+			    const char **buffer);
+int mu_property_aget_value (mu_property_t prop, const char *key,
+			    char **buffer);
+int mu_property_clear (mu_property_t prop);
+int mu_property_invalidate (mu_property_t prop);
 
 /* Helper functions.  */
-extern int mu_property_set  (mu_property_t, const char *);
-extern int mu_property_unset (mu_property_t, const char *);
-extern int mu_property_is_set (mu_property_t, const char *);
+int mu_property_set  (mu_property_t, const char *);
+int mu_property_unset (mu_property_t, const char *);
+int mu_property_is_set (mu_property_t, const char *);
+
+int mu_property_get_iterator (mu_property_t, mu_iterator_t *itr);
+  
+/* Implementation init functions */
+int mu_assoc_property_init (mu_property_t);
+
+struct mu_mh_prop
+{
+  char *filename;
+  int ro;
+};
 
+int mu_mh_property_init (mu_property_t);
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/sys/folder.h b/include/mailutils/sys/folder.h
index 53b909d..3cbbdc2 100644
--- a/include/mailutils/sys/folder.h
+++ b/include/mailutils/sys/folder.h
@@ -38,6 +38,7 @@ struct _mu_folder
   mu_authority_t authority;
   mu_observable_t observable;
   mu_debug_t debug;
+  mu_property_t property;
   mu_stream_t stream;
   mu_monitor_t monitor;
   mu_url_t url;
@@ -63,6 +64,7 @@ struct _mu_folder
   int  (*_rename)      (mu_folder_t, const char *, const char *);
   int  (*_subscribe)   (mu_folder_t, const char *);
   int  (*_unsubscribe) (mu_folder_t, const char *);
+  int  (*_get_property)(mu_folder_t, mu_property_t *);
 };
 
 # ifdef __cplusplus
diff --git a/include/mailutils/sys/iterator.h b/include/mailutils/sys/iterator.h
index 2eaf4d5..f40eb3b 100644
--- a/include/mailutils/sys/iterator.h
+++ b/include/mailutils/sys/iterator.h
@@ -39,6 +39,7 @@ struct _mu_iterator
   int (*curitem_p) (void *owner, void *item);
   int (*finished_p) (void *owner);
   int (*itrctl) (void *owner, enum mu_itrctl_req req, void *arg);
+  void *(*dataptr) (void *);
 };
 
 # ifdef __cplusplus
diff --git a/include/mailutils/sys/mailer.h b/include/mailutils/sys/mailer.h
index 4bd2381..02ff6e1 100644
--- a/include/mailutils/sys/mailer.h
+++ b/include/mailutils/sys/mailer.h
@@ -51,6 +51,7 @@ struct _mu_mailer
   int (*_open)         (mu_mailer_t, int flags);
   int (*_close)        (mu_mailer_t);
   int (*_send_message) (mu_mailer_t, mu_message_t, mu_address_t, mu_address_t);
+  int (*_get_property) (mu_mailer_t, mu_property_t *);
 };
 
 int _mu_mailer_mailbox_init (mu_mailbox_t mailbox);
diff --git a/include/mailutils/sys/property.h b/include/mailutils/sys/property.h
index cbc090f..3705ee7 100644
--- a/include/mailutils/sys/property.h
+++ b/include/mailutils/sys/property.h
@@ -31,18 +31,44 @@
 extern "C" {
 # endif
 
-struct property_item
-{
-  char *value;
-};
-
+#define MU_PROP_INIT     0x01
+#define MU_PROP_FILL     0x02
+#define MU_PROP_MODIFIED 0x04
+  
 struct _mu_property
 {
-  mu_assoc_t assoc;
-  void *owner;
-  mu_monitor_t lock;
+  size_t _prop_ref_count;    /* Reference counter */
+  int _prop_flags;           /* Flags describing the state of this object */
+  void *_prop_data;          /* Implementation-specific data */
+  void *_prop_init_data;     /* Initialization data */
+
+  /* Methods */
+
+  /* Delayed initialization.  This function must allocate _prop_data,
+     if needed, and initialize the rest of _prop_* methods. */
+  int (*_prop_init)  (struct _mu_property *);
+  /* Free memory allocated in _prop_data */
+  void (*_prop_done) (struct _mu_property *);
+  /* Fill in the properties from an external storage */
+  int (*_prop_fill)  (struct _mu_property *);
+  /* Write the properties to an external storage */
+  int (*_prop_save)  (struct _mu_property *);
+  /* Get the value of the property named in the 2nd argument.  If 3rd
+     arg is NULL, _prop_getval tests whether the given property is set. */
+  int (*_prop_getval) (struct _mu_property *, const char *, const char **);
+  /* Set the property */
+  int (*_prop_setval) (struct _mu_property *, const char *, const char *, int);
+  /* Unset (delete) the property */
+  int (*_prop_unset) (struct _mu_property *, const char *);
+  /* Return iterator for this property object */
+  int (*_prop_getitr) (struct _mu_property *, mu_iterator_t *);
+  /* Clear all properties. */
+  int (*_prop_clear) (struct _mu_property *);
 };
 
+int _mu_property_init (mu_property_t prop);
+int _mu_property_check (mu_property_t prop);
+  
 # ifdef __cplusplus
 }
 # endif
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index 454962b..34246dc 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -17,7 +17,7 @@
 # <http://www.gnu.org/licenses/>.
 
 SUBDIRS = auth base address cfg diag filter mailbox mailer mime\
- server string stream url . tests 
+ server string stream property url . tests 
 
 lib_LTLIBRARIES = libmailutils.la
 
@@ -34,6 +34,7 @@ libmailutils_la_LIBADD = \
  mailbox/libmailbox.la\
  mailer/libmailer.la\
  mime/libmime.la\
+ property/libproperty.la\
  server/libserver.la\
  string/libstring.la\
  stream/libstream.la\
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index b4f208e..8160e04 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -52,7 +52,6 @@ libbase_la_SOURCES = \
  opool.c\
  parsedate.c\
  permstr.c\
- property.c\
  registrar.c\
  refcount.c\
  rfc2047.c\
diff --git a/libmailutils/base/assoc.c b/libmailutils/base/assoc.c
index b2e3f60..56b293b 100644
--- a/libmailutils/base/assoc.c
+++ b/libmailutils/base/assoc.c
@@ -391,10 +391,11 @@ first (void *owner)
   mu_assoc_t assoc = itr->assoc;
   unsigned hash_max = hash_size[assoc->hash_num];
   unsigned i;
-  
-  for (i = 0; i < hash_max; i++)
-    if ((ASSOC_ELEM (assoc, i))->name)
-      break;
+
+  if (assoc->tab)
+    for (i = 0; i < hash_max; i++)
+      if ((ASSOC_ELEM (assoc, i))->name)
+	break;
   itr->index = i;
   return 0;
 }
diff --git a/libmailutils/base/iterator.c b/libmailutils/base/iterator.c
index 97f7b75..e4d1846 100644
--- a/libmailutils/base/iterator.c
+++ b/libmailutils/base/iterator.c
@@ -103,6 +103,15 @@ mu_iterator_set_itrctl (mu_iterator_t itr,
 }
 
 int
+mu_iterator_set_dataptr (mu_iterator_t itr, void *(*dataptr) (void *))
+{
+  if (!itr)
+    return EINVAL;
+  itr->dataptr = dataptr;
+  return 0;
+}
+
+int
 mu_iterator_set_destroy (mu_iterator_t itr, int (*destroy) (mu_iterator_t, void *))
 {
   if (!itr)
@@ -202,14 +211,23 @@ mu_iterator_skip (mu_iterator_t iterator, ssize_t count)
 int
 mu_iterator_current (mu_iterator_t iterator, void **pitem)
 {
-  return iterator->getitem (iterator->owner, pitem, NULL);
+  return mu_iterator_current_kv (iterator, NULL, pitem);
 }
 
 int
 mu_iterator_current_kv (mu_iterator_t iterator, 
                         const void **pkey, void **pitem)
 {
-  return iterator->getitem (iterator->owner, (void**)pitem, pkey);
+  void *ptr;
+  int rc = iterator->getitem (iterator->owner, &ptr, pkey);
+  if (rc == 0)
+    {
+      if (iterator->dataptr)
+	*pitem = iterator->dataptr (ptr);
+      else
+	*pitem = ptr;
+    }
+  return rc;
 }
 
 int
diff --git a/libmailutils/base/property.c b/libmailutils/base/property.c
deleted file mode 100644
index eec0ddc..0000000
--- a/libmailutils/base/property.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see 
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-
-#include <mailutils/sys/property.h>
-#include <mailutils/errno.h>
-#include <mailutils/assoc.h>
-#include <stdlib.h>
-
-static void
-prop_free_value (void *data)
-{
-  struct property_item *item = data;
-  free (item->value);
-}
-
-int
-mu_property_create (mu_property_t *pp, void *owner)
-{
-  int rc;
-  mu_property_t prop;
-  if (pp == NULL)
-    return MU_ERR_OUT_PTR_NULL;
-  prop = calloc (1, sizeof *prop);
-  if (prop == NULL)
-    return ENOMEM;
-  rc = mu_assoc_create (&prop->assoc, sizeof (struct property_item), 0);
-  if (rc)
-    {
-      free (prop);
-      return rc;
-    }
-  mu_assoc_set_free (prop->assoc, prop_free_value);
-  mu_monitor_create (&prop->lock, 0, prop);
-  prop->owner = owner;
-  *pp = prop;
-  return 0;
-}
-
-void
-mu_property_destroy (mu_property_t *pp, void *owner)
-{
-  if (pp && *pp)
-    {
-      mu_property_t prop = *pp;
-      if (prop->owner == owner)
-	{
-	  /* Destroy the list and is properties.  */
-	  mu_monitor_wrlock (prop->lock);
-	  mu_assoc_destroy (&prop->assoc);
-	  mu_monitor_unlock (prop->lock);
-	  mu_monitor_destroy (&prop->lock, prop);
-	  free (prop);
-	}
-      *pp = NULL;
-    }
-}
-
-void *
-mu_property_get_owner (mu_property_t prop)
-{
-  return (prop == NULL) ? NULL : prop->owner;
-}
-
-int
-mu_property_set_value (mu_property_t prop, const char *key, const char *value,
-		       int overwrite)
-{
-  struct property_item *item;
-  int rc;
-
-  if (!prop)
-    return EINVAL;
-  rc = mu_assoc_ref_install (prop->assoc, key, (void **)&item);
-  if (rc == MU_ERR_NOENT)
-    {
-      item->value = strdup (value);
-    }
-  else if (overwrite)
-    {
-      free (item->value);
-      item->value = strdup (value);
-    }
-  else
-    return 0;
-  
-  if (!item->value)
-    {
-      mu_assoc_remove (prop->assoc, key);
-      return ENOMEM;
-    }
-
-  return 0;
-}
-  
-int
-mu_property_sget_value (mu_property_t prop, const char *key,
-			const char **buffer)
-{
-  struct property_item *item;
-
-  if (!prop)
-    return EINVAL;
-  item = mu_assoc_ref (prop->assoc, key);
-  if (item == NULL)
-    return MU_ERR_NOENT;
-  if (buffer)
-    *buffer = item->value;
-  return 0;
-}
-
-int
-mu_property_aget_value (mu_property_t prop, const char *key,
-			char **buffer)
-{
-  const char *value;
-  int rc = mu_property_sget_value (prop, key, &value);
-  if (rc == 0)
-    {
-      if ((*buffer = strdup (value)) == NULL)
-	return ENOMEM;
-    }
-  return rc;
-}
-
-int
-mu_property_get_value (mu_property_t prop, const char *key, char *buffer,
-		       size_t buflen, size_t *n)
-{
-  size_t len = 0;
-  const char *value;
-  int rc = mu_property_sget_value (prop, key, &value);
-  if (rc == 0)
-    {
-      len = strlen (value) + 1;
-      if (buffer && buflen)
-	{
-	  if (buflen < len)
-	    len = buflen;
-	  len--;
-	  memcpy (buffer, value, len);
-	  buffer[len] = 0;
-	}
-    }
-  if (n)
-    *n = len;
-  return rc;
-}
-
-int
-mu_property_is_set (mu_property_t prop, const char *key)
-{
-  struct property_item *item = mu_assoc_ref (prop->assoc, key);
-  return (item == NULL) ? 0 : 1;
-}
-
-int
-mu_property_set (mu_property_t prop, const char *key)
-{
-  return mu_property_set_value (prop, key, "", 1);
-}
-
-int
-mu_property_unset (mu_property_t prop, const char *key)
-{
-  if (!prop)
-    return EINVAL;
-  return mu_assoc_remove (prop->assoc, key);
-}
-  
diff --git a/libmailutils/mailbox/folder.c b/libmailutils/mailbox/folder.c
index fe91823..071fc22 100644
--- a/libmailutils/mailbox/folder.c
+++ b/libmailutils/mailbox/folder.c
@@ -35,6 +35,7 @@
 #include <mailutils/stream.h>
 #include <mailutils/url.h>
 #include <mailutils/errno.h>
+#include <mailutils/property.h>
 
 #include <mailutils/sys/folder.h>
 
@@ -208,6 +209,8 @@ mu_folder_destroy (mu_folder_t *pfolder)
 	    mu_stream_destroy (&folder->stream);
 	  if (folder->url)
 	    mu_url_destroy (&folder->url);
+	  if (folder->property)
+	    mu_property_destroy (&folder->property);
 	  free (folder);
 	}
       mu_monitor_unlock (monitor);
@@ -217,6 +220,31 @@ mu_folder_destroy (mu_folder_t *pfolder)
     }
 }
 
+int
+mu_folder_get_property (mu_folder_t folder, mu_property_t *prop)
+{
+  if (folder == NULL)
+    return EINVAL;
+  if (prop == NULL)
+    return MU_ERR_OUT_PTR_NULL;
+  
+  if (folder->property == NULL)
+    {
+      int status;
+
+      if (folder->_get_property)
+	status = folder->_get_property (folder, &folder->property);
+      else
+	status = mu_property_create_init (&folder->property,
+					  mu_assoc_property_init, NULL);
+      if (status != 0)
+	return status;
+    }
+  *prop = folder->property;
+  return 0;
+}
+
+
 /* Cover functions.  */
 int
 mu_folder_open (mu_folder_t folder, int flags)
diff --git a/libmailutils/mailbox/header.c b/libmailutils/mailbox/header.c
index 6ce70d1..b3c28c7 100644
--- a/libmailutils/mailbox/header.c
+++ b/libmailutils/mailbox/header.c
@@ -611,7 +611,23 @@ mu_header_insert (mu_header_t header,
   HEADER_SET_MODIFIED (header);
   return 0;
 }
+
+int
+mu_header_clear (mu_header_t header)
+{
+  int status;
   
+  if (header == NULL)
+    return EINVAL;
+
+  status = mu_header_fill (header);
+  if (status)
+    return status;
+  mu_header_invalidate (header);
+  HEADER_SET_MODIFIED (header);
+  return 0;
+}
+
 
 int
 mu_header_sget_value_n (mu_header_t header,
@@ -630,8 +646,8 @@ mu_header_sget_value_n (mu_header_t header,
   ent = mu_hdrent_find (header, name, n);
   if (!ent)
     return MU_ERR_NOENT;
-
-  *pval = MU_HDRENT_VALUE (header, ent);
+  if (pval)
+    *pval = MU_HDRENT_VALUE (header, ent);
   return 0;
 }
 
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index 0677e88..269223c 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -272,7 +272,7 @@ mu_mailbox_destroy (mu_mailbox_t *pmbox)
 	mu_folder_destroy (&mbox->folder);
 
       if (mbox->property)
-	mu_property_destroy (&mbox->property, mbox);
+	mu_property_destroy (&mbox->property);
 
       free (mbox);
       *pmbox = NULL;
@@ -648,6 +648,18 @@ mu_mailbox_get_observable (mu_mailbox_t mbox, mu_observable_t *pobservable)
 }
 
 int
+mu_mailbox_set_property (mu_mailbox_t mbox, mu_property_t property)
+{
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (mbox->property)
+    mu_property_unref (mbox->property);
+  mbox->property = property;
+  mu_property_ref (property);
+  return 0;
+}
+
+int
 mu_mailbox_get_property (mu_mailbox_t mbox, mu_property_t *pproperty)
 {
   if (mbox == NULL)
@@ -657,7 +669,13 @@ mu_mailbox_get_property (mu_mailbox_t mbox, mu_property_t *pproperty)
   
   if (mbox->property == NULL)
     {
-      int status = mu_property_create (&mbox->property, mbox);
+      int status;
+
+      if (mbox->_get_property)
+	status = mbox->_get_property (mbox, &mbox->property);
+      else
+	status = mu_property_create_init (&mbox->property,
+					  mu_assoc_property_init, NULL);
       if (status != 0)
 	return status;
     }
diff --git a/libmailutils/mailer/mailer.c b/libmailutils/mailer/mailer.c
index fec7cab..e60e70b 100644
--- a/libmailutils/mailer/mailer.c
+++ b/libmailutils/mailer/mailer.c
@@ -210,7 +210,7 @@ mu_mailer_destroy (mu_mailer_t * pmailer)
 	mu_debug_destroy (&(mailer->debug), mailer);
 
       if (mailer->property)
-	mu_property_destroy (&(mailer->property), mailer);
+	mu_property_destroy (&mailer->property);
 
       free (mailer);
       *pmailer = NULL;
@@ -706,6 +706,18 @@ mu_mailer_get_observable (mu_mailer_t mailer, mu_observable_t * pobservable)
 }
 
 int
+mu_mailer_set_property (mu_mailer_t mailer, mu_property_t property)
+{
+  if (mailer == NULL)
+    return EINVAL;
+  if (mailer->property)
+    mu_property_unref (mailer->property);
+  mailer->property = property;
+  mu_property_ref (property);
+  return 0;
+}
+
+int
 mu_mailer_get_property (mu_mailer_t mailer, mu_property_t * pproperty)
 {
   if (mailer == NULL)
@@ -714,7 +726,13 @@ mu_mailer_get_property (mu_mailer_t mailer, mu_property_t * pproperty)
     return MU_ERR_OUT_PTR_NULL;
   if (mailer->property == NULL)
     {
-      int status = mu_property_create (&(mailer->property), mailer);
+      int status;
+
+      if (mailer->_get_property)
+	status = mailer->_get_property (mailer, &mailer->property);
+      else
+	status = mu_property_create_init (&mailer->property,
+					  mu_assoc_property_init, NULL);
       if (status != 0)
 	return status;
     }
diff --git a/libmailutils/mime/Makefile.am b/libmailutils/property/Makefile.am
similarity index 83%
copy from libmailutils/mime/Makefile.am
copy to libmailutils/property/Makefile.am
index 70a3ebc..4f2ea03 100644
--- a/libmailutils/mime/Makefile.am
+++ b/libmailutils/property/Makefile.am
@@ -15,11 +15,16 @@
 # Public License along with this library.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-noinst_LTLIBRARIES = libmime.la
+noinst_LTLIBRARIES = libproperty.la
 
-libmime_la_SOURCES = \
- attachment.c\
- mime.c\
- mimehdr.c
+libproperty_la_SOURCES = \
+ assocprop.c\
+ create.c\
+ mhprop.c\
+ propclr.c\
+ propget.c\
+ propitr.c\
+ propinv.c\
+ propset.c
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/property/assocprop.c b/libmailutils/property/assocprop.c
new file mode 100644
index 0000000..6bf7099
--- /dev/null
+++ b/libmailutils/property/assocprop.c
@@ -0,0 +1,228 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <mailutils/sys/property.h>
+#include <mailutils/errno.h>
+#include <mailutils/assoc.h>
+#include <mailutils/stream.h>
+#include <mailutils/iterator.h>
+#include <stdlib.h>
+
+struct property_item
+{
+  char *value;
+};
+
+static void
+_assoc_prop_done (struct _mu_property *prop)
+{
+  mu_assoc_t assoc = prop->_prop_data;
+  mu_stream_t str = prop->_prop_init_data;
+  mu_assoc_destroy (&assoc);
+  mu_stream_destroy (&str);
+}
+
+static int
+_assoc_prop_getval (struct _mu_property *prop,
+		    const char *key, const char **pval)
+{
+  mu_assoc_t assoc = prop->_prop_data;
+  struct property_item *item;
+
+  item = mu_assoc_ref (assoc, key);
+  if (item == NULL)
+    return MU_ERR_NOENT;
+  if (pval)
+    *pval = item->value;
+  return 0;
+
+}
+
+static int
+_assoc_prop_setval (struct _mu_property *prop, const char *key,
+		       const char *val, int overwrite)
+{
+  mu_assoc_t assoc = prop->_prop_data;
+  struct property_item *item;
+  int rc;
+
+  rc = mu_assoc_ref_install (assoc, key, (void **)&item);
+  if (rc == 0)
+    {
+      item->value = strdup (val);
+      if (!item->value)
+	{
+	  mu_assoc_remove (assoc, key);
+	  return ENOMEM;
+	}
+    }
+  else if (rc == MU_ERR_EXISTS && overwrite)
+    {
+      char *newval = strdup (val);
+      if (!newval)
+	return ENOMEM;
+      free (item->value);
+      item->value = newval;
+    }
+  else
+    return rc;
+  return 0;
+}
+
+static int
+_assoc_prop_unset (struct _mu_property *prop, const char *key)
+{
+  mu_assoc_t assoc = prop->_prop_data;
+
+  return mu_assoc_remove (assoc, key);
+}
+
+static int
+_assoc_prop_clear (struct _mu_property *prop)
+{
+  mu_assoc_t assoc = prop->_prop_data;
+  mu_assoc_clear (assoc);
+  return 0;
+}
+
+
+static void *
+_assoc_prop_dataptr (void *in)
+{
+  struct property_item *item = in;
+  return item->value;
+}
+
+static int
+_assoc_prop_getitr (struct _mu_property *prop, mu_iterator_t *pitr)
+{
+  int rc;
+  mu_iterator_t itr;
+  
+  rc = mu_assoc_get_iterator ((mu_assoc_t)prop->_prop_data, &itr);
+  if (rc)
+    return rc;
+  mu_iterator_set_dataptr (itr, _assoc_prop_dataptr);
+  *pitr = itr;
+  return 0;
+}
+
+
+static void
+prop_free_value (void *data)
+{
+  struct property_item *item = data;
+  free (item->value);
+}
+
+
+static int
+_assoc_prop_fill (struct _mu_property *prop)
+{
+  int rc;
+  mu_stream_t str = prop->_prop_init_data;
+  int state = 0;
+  char *buf[2] = { NULL, NULL };
+  size_t size[2] = { 0, 0 }, n;
+  
+  if (!str)
+    return EINVAL;
+  mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
+  while ((rc = mu_stream_getdelim (str, &buf[state], &size[state],
+				   0, &n)) == 0 &&
+	 n > 0)
+    {
+      if (state == 1)
+	_assoc_prop_setval (prop, buf[0], buf[1], 1);
+      state = !state;
+    }
+  free (buf[0]);
+  free (buf[1]);
+  return rc;
+}
+
+static int
+_assoc_prop_save (struct _mu_property *prop)
+{
+  mu_stream_t str = prop->_prop_init_data;
+  mu_iterator_t itr;
+  int rc;
+  mu_off_t off;
+  
+  if (!str)
+    return EINVAL;
+  rc = mu_property_get_iterator (prop, &itr);
+  if (rc)
+    return rc;
+
+  mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name, *val;
+	  
+      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
+      rc = mu_stream_write (str, name, strlen (name) + 1, NULL);
+      if (rc)
+	break;
+      rc = mu_stream_write (str, val, strlen (val) + 1, NULL);
+      if (rc)
+	break;
+    }      
+  mu_iterator_destroy (&itr);
+  rc = mu_stream_seek (str, 0, MU_SEEK_CUR, &off);
+  if (rc == 0)
+    rc = mu_stream_truncate (str, off);
+  return rc;
+}
+
+int
+mu_assoc_property_init (struct _mu_property *prop)
+{
+  mu_assoc_t assoc;
+  int rc;
+  
+  rc = mu_assoc_create (&assoc, sizeof (struct property_item), 0);
+  if (rc)
+    return rc;
+  mu_assoc_set_free (assoc, prop_free_value);
+  prop->_prop_data = assoc;
+
+  prop->_prop_done = _assoc_prop_done;
+  if (prop->_prop_init_data)
+    {
+      prop->_prop_fill = _assoc_prop_fill;
+      prop->_prop_save = _assoc_prop_save;
+    }
+  else
+    {
+      prop->_prop_fill = NULL;
+      prop->_prop_save = NULL;
+    }
+  prop->_prop_getval = _assoc_prop_getval;
+  prop->_prop_setval = _assoc_prop_setval;
+  prop->_prop_unset = _assoc_prop_unset;
+  prop->_prop_getitr = _assoc_prop_getitr;
+  prop->_prop_clear = _assoc_prop_clear;
+  return 0;
+}
+
diff --git a/libmailutils/property/create.c b/libmailutils/property/create.c
new file mode 100644
index 0000000..cee1e7d
--- /dev/null
+++ b/libmailutils/property/create.c
@@ -0,0 +1,166 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/property.h>
+
+int
+mu_property_create (mu_property_t *pprop)
+{
+  mu_property_t prop = calloc (1, sizeof (prop[0]));
+  if (!prop)
+    return ENOMEM;
+  *pprop = prop;
+  return 0;
+}
+
+int
+mu_property_create_init (mu_property_t *pprop,
+			 int (*initfun) (mu_property_t), void *initdata)
+{
+  mu_property_t prop;
+  int rc = mu_property_create (&prop);
+  if (rc == 0)
+    {
+      mu_property_set_init (prop, initfun, initdata);
+      *pprop = prop;
+    }
+  return 0;
+}
+
+int
+mu_property_set_init (mu_property_t prop,
+		      int (*initfun) (mu_property_t), void *initdata)
+{
+  if (!prop)
+    return ENOMEM;
+  if (prop->_prop_flags & MU_PROP_INIT)
+    return MU_ERR_SEQ;
+  prop->_prop_init = initfun;
+  prop->_prop_init_data = initdata;
+  return 0;
+}
+
+int
+mu_property_set_init_data (mu_property_t prop, void *data, void **old_data)
+{
+  if (!prop)
+    return ENOMEM;
+  if (prop->_prop_flags & MU_PROP_INIT)
+    return MU_ERR_SEQ;
+  if (old_data)
+    *old_data = prop->_prop_init_data;
+  prop->_prop_init_data = data;
+  return 0;
+}
+
+void
+mu_property_destroy (mu_property_t *pprop)
+{
+  if (pprop)
+    {
+      mu_property_t prop = *pprop;
+      if (prop && (prop->_prop_ref_count == 0 || --prop->_prop_ref_count == 0))
+	{
+	  mu_property_save (prop);
+	  if (prop->_prop_done)
+	    prop->_prop_done (prop);
+	  free (prop);
+	  *pprop = NULL;
+	}
+    }
+}
+
+void
+mu_property_ref (mu_property_t prop)
+{
+  if (prop)
+    prop->_prop_ref_count++;
+}
+
+void
+mu_property_unref (mu_property_t prop)
+{
+  mu_property_destroy (&prop);
+}
+
+int
+mu_property_save (mu_property_t prop)
+{
+  int rc = 0;
+      
+  if (!prop)
+    return EINVAL;
+  if (prop->_prop_flags & MU_PROP_MODIFIED)
+    {
+      if (prop->_prop_save)
+	rc = prop->_prop_save (prop);
+
+      if (rc == 0)
+	prop->_prop_flags &= ~MU_PROP_MODIFIED;
+    }
+  return rc;
+}
+
+int
+_mu_property_init (mu_property_t prop)
+{
+  int rc = 0;
+  if (!(prop->_prop_flags & MU_PROP_INIT))
+    {
+      if (prop->_prop_init)
+	rc = prop->_prop_init (prop);
+      if (rc == 0)
+	prop->_prop_flags |= MU_PROP_INIT;
+    }
+  return rc;
+}
+
+static int
+_mu_property_fill (mu_property_t prop)
+{
+  int rc = 0;
+  if (!(prop->_prop_flags & MU_PROP_FILL))
+    {
+      if (prop->_prop_fill)
+	rc = prop->_prop_fill (prop);
+      if (rc == 0)
+	prop->_prop_flags |= MU_PROP_FILL;
+    }
+  return rc;
+}
+
+int
+_mu_property_check (mu_property_t prop)
+{
+  int rc;
+  
+  if (!prop)
+    return EINVAL;
+  rc = _mu_property_init (prop);
+  if (rc == 0)
+    rc = _mu_property_fill (prop);
+  return rc;
+}
+
+  
diff --git a/libmailutils/property/mhprop.c b/libmailutils/property/mhprop.c
new file mode 100644
index 0000000..12b16e9
--- /dev/null
+++ b/libmailutils/property/mhprop.c
@@ -0,0 +1,241 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/stream.h>
+#include <mailutils/iterator.h>
+#include <mailutils/header.h>
+#include <mailutils/nls.h>
+#include <mailutils/filter.h>
+#include <mailutils/property.h>
+#include <mailutils/sys/property.h>
+#include <stdlib.h>
+
+static void
+_mh_prop_done (struct _mu_property *prop)
+{
+  struct mu_mh_prop *mhprop = prop->_prop_init_data;
+  mu_header_t header = prop->_prop_data;
+  mu_header_destroy (&header);
+  free (mhprop->filename);
+  free (mhprop);
+}
+
+static int
+_mh_prop_getval (struct _mu_property *prop,
+		 const char *key, const char **pval)
+{
+  mu_header_t header = prop->_prop_data;
+
+  if (!header)
+    return MU_ERR_NOENT;
+  return mu_header_sget_value (header, key, pval);
+}
+
+static int
+_mh_prop_setval (struct _mu_property *prop, const char *key,
+		 const char *val, int overwrite)
+{
+  struct mu_mh_prop *mhprop = prop->_prop_init_data;
+  mu_header_t header = prop->_prop_data;
+  if (!header)
+    {
+      int rc;
+      if ((rc = mu_header_create (&header, NULL, 0)) != 0)
+	{
+	  mu_error (_("cannot create context %s: %s"),
+		    mhprop->filename, mu_strerror (rc));
+	  return 1;
+	}
+      prop->_prop_data = header;
+    }
+  return mu_header_set_value (header, key, val, overwrite);
+}
+
+static int
+_mh_prop_unset (struct _mu_property *prop, const char *key)
+{
+  mu_header_t header = prop->_prop_data;
+  if (!header)
+    return 0;
+  return mu_header_remove (header, key, 1);
+}
+
+static int
+_mh_prop_getitr (struct _mu_property *prop, mu_iterator_t *pitr)
+{
+  mu_header_t header = prop->_prop_data;
+  return mu_header_get_iterator (header, pitr);
+}
+
+static int
+_mh_prop_clear (struct _mu_property *prop)
+{
+  mu_header_t header = prop->_prop_data;
+  return mu_header_clear (header);
+}
+
+    
+static int
+_mh_prop_read_stream (mu_header_t *phdr, mu_stream_t stream)
+{
+  int rc;
+  mu_stream_t flt;
+  const char *argv[3];
+  mu_off_t size;
+  size_t total;
+  char *blurb;
+  
+  rc = mu_stream_size (stream, &size);
+  if (rc)
+    return rc;
+  
+  argv[0] = "INLINE-COMMENT";
+  argv[1] = "#";
+  argv[2] = NULL;
+  rc = mu_filter_create_args (&flt, stream, argv[0], 2, argv,
+			      MU_FILTER_DECODE, MU_STREAM_READ);
+  if (rc)
+    {
+      mu_error (_("cannot open filter stream: %s"), mu_strerror (rc));
+      return rc;
+    }
+
+  blurb = malloc (size + 1);
+  if (!blurb)
+    {
+      mu_stream_destroy (&flt);
+      return ENOMEM;
+    }
+
+  total = 0;
+  while (1)
+    {
+      size_t n;
+      
+      rc = mu_stream_read (flt, blurb + total, size - total, &n);
+      if (rc)
+	break;
+      if (n == 0)
+	break;
+      total += n;
+    }
+
+  mu_stream_destroy (&flt);
+  if (rc)
+    {
+      free (blurb);
+      return rc;
+    }
+
+  rc = mu_header_create (phdr, blurb, total);
+  free (blurb);
+  return rc;
+}
+
+static int
+_mh_prop_write_stream (mu_header_t header, struct mu_mh_prop *mhprop,
+		       mu_stream_t stream)
+{
+  int rc;
+  mu_stream_t instream;
+  mu_off_t size;
+
+  mu_header_get_streamref (header, &instream);
+  rc = mu_stream_copy (stream, instream, 0, &size);
+  if (rc)
+    {
+      mu_error (_("error writing to context file %s: %s"),
+		mhprop->filename, mu_strerror (rc));
+      return rc;
+    }
+  else
+    rc = mu_stream_truncate (stream, size);
+  mu_stream_destroy (&instream);
+  return rc;
+}
+
+static int
+_mh_prop_fill (struct _mu_property *prop)
+{
+  struct mu_mh_prop *mhprop = prop->_prop_init_data;
+  int rc;
+  mu_stream_t stream;
+  mu_header_t header;
+  
+  rc = mu_file_stream_create (&stream, mhprop->filename, MU_STREAM_READ);
+  if (rc)
+    {
+      if ((rc = mu_header_create (&header, NULL, 0)) != 0)
+	mu_error (_("cannot create context %s: %s"),
+		  mhprop->filename, mu_strerror (rc));
+    }
+  else
+    {
+      rc = _mh_prop_read_stream (&header, stream);
+      mu_stream_unref (stream);
+    }
+  if (rc == 0)
+    prop->_prop_data = header;
+  return rc;
+}
+
+static int
+_mh_prop_save (struct _mu_property *prop)
+{
+  struct mu_mh_prop *mhprop = prop->_prop_init_data;
+  mu_header_t header = prop->_prop_data;
+  mu_stream_t stream;
+  int rc;
+  
+  if (mhprop->ro)
+    return 0;
+  
+  rc = mu_file_stream_create (&stream, mhprop->filename,
+			      MU_STREAM_WRITE|MU_STREAM_CREAT);
+  if (rc)
+    return rc;
+  rc = _mh_prop_write_stream (header, mhprop, stream);
+  mu_stream_unref (stream);
+  return rc;
+}
+
+int
+mu_mh_property_init (struct _mu_property *prop)
+{
+  struct mu_mh_prop *mhprop = prop->_prop_init_data;
+
+  if (!mhprop)
+    return EINVAL;
+  
+  prop->_prop_data = NULL;
+
+  prop->_prop_done = _mh_prop_done;
+  prop->_prop_fill = _mh_prop_fill;
+  prop->_prop_save = _mh_prop_save;
+  prop->_prop_getval = _mh_prop_getval;
+  prop->_prop_setval = _mh_prop_setval;
+  prop->_prop_unset = _mh_prop_unset;
+  prop->_prop_getitr = _mh_prop_getitr;
+  prop->_prop_clear = _mh_prop_clear;
+  return 0;
+}
diff --git a/libmailutils/url/urlstr.c b/libmailutils/property/propclr.c
similarity index 70%
copy from libmailutils/url/urlstr.c
copy to libmailutils/property/propclr.c
index 31e5197..fab9b25 100644
--- a/libmailutils/url/urlstr.c
+++ b/libmailutils/property/propclr.c
@@ -16,16 +16,23 @@
    <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
+#include <config.h>
 #endif
-#include <stdlib.h>
+
 #include <mailutils/types.h>
-#include <mailutils/sys/url.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/property.h>
 
-const char *
-mu_url_to_string (const mu_url_t url)
+int
+mu_property_clear (mu_property_t prop)
 {
-  if (url == NULL || url->name == NULL)
-    return "";
-  return url->name;
+  int rc = _mu_property_check (prop);
+  if (rc)
+    return rc;
+  if (!prop->_prop_clear)
+    return MU_ERR_EMPTY_VFN;
+  rc = prop->_prop_clear (prop);
+  if (rc == 0)
+    prop->_prop_flags |= MU_PROP_MODIFIED;
+  return rc;
 }
diff --git a/libmailutils/property/propget.c b/libmailutils/property/propget.c
new file mode 100644
index 0000000..79be2f5
--- /dev/null
+++ b/libmailutils/property/propget.c
@@ -0,0 +1,83 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/property.h>
+
+int
+mu_property_sget_value (mu_property_t prop, const char *key,
+			const char **pval)
+{
+  int rc = _mu_property_check (prop);
+  if (rc)
+    return rc;
+  if (!prop->_prop_getval)
+    return MU_ERR_EMPTY_VFN;
+  return prop->_prop_getval (prop, key, pval);
+}
+
+int
+mu_property_aget_value (mu_property_t prop, const char *key,
+			char **buffer)
+{
+  const char *value;
+  int rc = mu_property_sget_value (prop, key, &value);
+  if (rc == 0)
+    {
+      if ((*buffer = strdup (value)) == NULL)
+	return ENOMEM;
+    }
+  return rc;
+}
+
+int
+mu_property_get_value (mu_property_t prop, const char *key, char *buffer,
+		       size_t buflen, size_t *n)
+{
+  size_t len = 0;
+  const char *value;
+  int rc = mu_property_sget_value (prop, key, &value);
+  if (rc == 0)
+    {
+      len = strlen (value) + 1;
+      if (buffer && buflen)
+	{
+	  if (buflen < len)
+	    len = buflen;
+	  len--;
+	  memcpy (buffer, value, len);
+	  buffer[len] = 0;
+	}
+    }
+  if (n)
+    *n = len;
+  return rc;
+}
+
+int
+mu_property_is_set (mu_property_t prop, const char *key)
+{
+  if (_mu_property_check (prop))
+    return 0;
+  return mu_property_sget_value (prop, key, NULL) == 0;
+}
diff --git a/libmailutils/url/get-secret.c b/libmailutils/property/propinv.c
similarity index 67%
copy from libmailutils/url/get-secret.c
copy to libmailutils/property/propinv.c
index 34fb229..b4ee6fc 100644
--- a/libmailutils/url/get-secret.c
+++ b/libmailutils/property/propinv.c
@@ -16,29 +16,31 @@
    <http://www.gnu.org/licenses/>. */
 
 #ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
+#include <config.h>
 #endif
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/secret.h>
-#include <mailutils/sys/url.h>
+#include <mailutils/sys/property.h>
 
 int
-mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
+mu_property_invalidate (mu_property_t prop)
 {
-  if (url->_get_secret)
-    return url->_get_secret (url, psecret);
-  if (url->secret == NULL)
-    return MU_ERR_NOENT;
-  mu_secret_ref (url->secret);
-  *psecret = url->secret;
+  int rc;
+  
+  if (!prop)
+    return EINVAL;
+  rc = _mu_property_init (prop);
+  if (rc)
+    return rc;
+  if (prop->_prop_flags & MU_PROP_FILL)
+    {
+      if (!prop->_prop_clear)
+	return MU_ERR_EMPTY_VFN;
+      rc = prop->_prop_clear (prop);
+      if (rc)
+	return rc;
+      prop->_prop_flags &= ~(MU_PROP_FILL | MU_PROP_MODIFIED);
+    }
   return 0;
 }
diff --git a/include/mailutils/radius.h b/libmailutils/property/propitr.c
similarity index 67%
copy from include/mailutils/radius.h
copy to libmailutils/property/propitr.c
index 1ce4c24..87c9c2d 100644
--- a/include/mailutils/radius.h
+++ b/libmailutils/property/propitr.c
@@ -13,21 +13,24 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
+   Public License along with this library.  If not, see 
    <http://www.gnu.org/licenses/>. */
 
-#ifndef _MAILUTILS_RADIUS_H
-#define _MAILUTILS_RADIUS_H
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
 #include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/property.h>
 
-struct mu_radius_module_data
+int
+mu_property_get_iterator (mu_property_t prop, mu_iterator_t *pitr)
 {
-  char *config_dir;
-  char *auth_request;
-  char *getpwnam_request;
-  char *getpwuid_request;
-};
-
-extern int mu_radius_module_init (enum mu_gocs_op, void *data);
-
-#endif
+  int rc = _mu_property_check (prop);
+  if (rc)
+    return rc;
+  if (!prop->_prop_getitr)
+    return MU_ERR_EMPTY_VFN;
+  return prop->_prop_getitr (prop, pitr);
+}
diff --git a/libmailutils/property/propset.c b/libmailutils/property/propset.c
new file mode 100644
index 0000000..ed7c61b
--- /dev/null
+++ b/libmailutils/property/propset.c
@@ -0,0 +1,70 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010 Free
+   Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/sys/property.h>
+
+int
+mu_property_set_value (mu_property_t prop, const char *key,
+		       const char *value, int overwrite)
+{
+  int rc;
+  
+  if (!value)
+    rc = mu_property_unset (prop, key);
+  else
+    {
+      rc = _mu_property_check (prop);
+      if (rc)
+	return rc;
+      if (!prop->_prop_setval)
+	return MU_ERR_EMPTY_VFN;
+      rc = prop->_prop_setval (prop, key, value, overwrite);
+      if (rc == 0)
+	prop->_prop_flags |= MU_PROP_MODIFIED;
+    }
+  return rc;
+}
+
+int
+mu_property_unset (mu_property_t prop, const char *key)
+{
+  int rc = _mu_property_check (prop);
+  if (rc)
+    return rc;
+  if (!prop->_prop_unset)
+    return MU_ERR_EMPTY_VFN;
+  rc = prop->_prop_unset (prop, key);
+  if (rc == 0)
+    prop->_prop_flags |= MU_PROP_MODIFIED;
+  return rc;
+}
+
+int
+mu_property_set (mu_property_t prop, const char *key)
+{
+  return mu_property_set_value (prop, key, "", 1);
+}
+
+  
+
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index 0157222..8bdc039 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -11,6 +11,7 @@ encode2047
 fltst
 listop
 mailcap
+prop
 url-parse
 wicket
 wsp
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index e34d265..a3ae2aa 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -47,6 +47,7 @@ noinst_PROGRAMS = \
  fltst\
  listop\
  mailcap\
+ prop\
  url-parse\
  wicket\
  wsp
@@ -69,6 +70,7 @@ TESTSUITE_AT = \
  fromflt.at\
  list.at\
  mailcap.at\
+ prop.at\
  testsuite.at\
  url.at\
  wicket.at\
diff --git a/libmailutils/tests/prop.at b/libmailutils/tests/prop.at
new file mode 100644
index 0000000..298918a
--- /dev/null
+++ b/libmailutils/tests/prop.at
@@ -0,0 +1,124 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# This program 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 file is part of Mailfromd testsuite. 
+
+dnl ------------------------------------------------------------------
+dnl TESTPROP([NAME], [KW = `'], [PROG], [STDOUT = `'], [STDERR = `'])
+dnl
+m4_pushdef([TESTPROP],[
+AT_SETUP([prop: $1])
+AT_KEYWORDS([prop $2])
+AT_CHECK([$3],[0],[$4],[$5])
+AT_CLEANUP])
+
+TESTPROP([set],[prop00],[
+prop foo=bar ?foo +foo
+],
+[0: foo=bar: Success
+1: foo is set
+2: foo=bar
+])
+
+TESTPROP([overwrite],[prop01],[
+prop foo=bar foo=baz +foo
+],
+[0: foo=bar: Success
+1: foo=baz: Success
+2: foo=baz
+])
+
+TESTPROP([set without overwrite],[prop03],[
+prop foo=bar foo:=baz +foo
+],
+[0: foo=bar: Success
+1: foo=baz: Item already exists
+2: foo=bar
+])
+
+TESTPROP([set/unset],[prop04],[
+prop foo=bar ?foo +foo -foo ?foo
+],
+[0: foo=bar: Success
+1: foo is set
+2: foo=bar
+3: unset foo: Success
+4: foo is not set
+])
+
+TESTPROP([read/save],[prop06],[
+prop --file=db user=gray package=mailutils org=GNU test=6.a
+if test -f db; then
+  prop --file=db | sort
+else
+  echo 2>&1 "failed to create file"
+  exit 1
+fi
+
+prop --file=db -test
+prop --file=db | sort
+
+prop --file=db test=6.b descr="New test"
+prop --file=db | sort
+],
+[0: user=gray: Success
+1: package=mailutils: Success
+2: org=GNU: Success
+3: test=6.a: Success
+Property dump:
+org=GNU
+package=mailutils
+test=6.a
+user=gray
+0: unset test: Success
+Property dump:
+org=GNU
+package=mailutils
+user=gray
+0: test=6.b: Success
+1: descr=New test: Success
+Property dump:
+descr=New test
+org=GNU
+package=mailutils
+test=6.b
+user=gray
+])
+
+TESTPROP([clear],[prop07],[
+prop --dump user=gray package=mailutils org=GNU 0 ?org
+],
+[0: user=gray: Success
+1: package=mailutils: Success
+2: org=GNU: Success
+3: clear: Success
+4: org is not set
+Property dump:
+])
+
+TESTPROP([invalidate],[prop08],[
+prop --file=db user=foo
+prop --file=db ?user user=bar +user '!' +user
+],
+[0: user=foo: Success
+0: user is set
+1: user=bar: Success
+2: user=bar
+3: invalidate: Success
+4: user=foo
+])
+
+m4_popdef([TESTPROP])
+
diff --git a/libmailutils/tests/prop.c b/libmailutils/tests/prop.c
new file mode 100644
index 0000000..3cc4fd3
--- /dev/null
+++ b/libmailutils/tests/prop.c
@@ -0,0 +1,158 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif 
+#include <mailutils/mailutils.h>
+
+void
+help (char *progname)
+{
+  printf ("usage: %s [--file=NAME] [--dump] [COMMAND...]\n", progname);
+  printf ("Valid COMMANDs are:\n");
+  printf (" X=Y      set property X to value Y\n");
+  printf (" X:=Y     same, but fail if X has already been set\n");
+  printf (" ?X       query whether X is set\n");
+  printf (" +X       query the value of the property X\n");
+  printf (" -X       unset property X\n");
+  printf (" 0        clear all properties\n");
+  printf (" !        invalidate properties\n");
+  exit (0);
+}
+
+int
+main (int argc, char **argv)
+{
+  mu_property_t prop;
+  mu_iterator_t itr;
+  int i, j, rc;
+  char *filename = NULL;
+  int dumpit = 0;
+  mu_stream_t str = NULL;
+
+  if (argc == 1)
+    help (argv[0]);
+  
+  for (i = 1; i < argc; i++)
+    {
+      if (!(argv[i][0] == '-' && argv[i][1] == '-'))
+	break;
+      if (strcmp (argv[i], "--help") == 0)
+	help (argv[0]);
+      else if (strncmp (argv[i], "--file=", 7) == 0)
+	filename = argv[i] + 7;
+      else if (strcmp (argv[i], "--dump") == 0)
+	dumpit = 1;
+      else
+	{
+	  mu_error ("unknown switch: %s", argv[i]);
+	  return 1;
+	}
+    }
+
+  if (filename)
+    {
+      MU_ASSERT (mu_file_stream_create (&str, filename,
+					MU_STREAM_RDWR|MU_STREAM_CREAT));
+      if (i == argc)
+	dumpit = 1;
+    }
+
+  MU_ASSERT (mu_property_create_init (&prop, mu_assoc_property_init, str));
+
+  for (j = 0; i < argc; i++, j++)
+    {
+      char *key = argv[i];
+      char *p = strchr (key, '=');
+
+      if (p)
+	{
+	  int override;
+	  if (p > key && p[-1] == ':')
+	    {
+	      override = 0;
+	      p[-1] = 0;
+	    }
+	  else
+	    {
+	      override = 1;
+	      *p = 0;
+	    }
+	  p++;
+	  rc = mu_property_set_value (prop, key, p, override);
+	  printf ("%d: %s=%s: %s\n",
+		  j, key, p, mu_strerror (rc));
+	}
+      else if (key[0] == '?')
+	{
+	  key++;
+	  rc = mu_property_is_set (prop, key);
+	  printf ("%d: %s is %s\n", j, key, rc ? "set" : "not set");
+	}
+      else if (key[0] == '-')
+	{
+	  key++;
+	  rc = mu_property_unset (prop, key);
+	  printf ("%d: unset %s: %s\n", j, key, mu_strerror (rc));
+	}
+      else if (key[0] == '+')
+	{
+	  const char *val;
+	  
+	  key++;
+	  rc = mu_property_sget_value (prop, key, &val);
+	  if (rc)
+	    printf ("%d: cannot get %s: %s\n", j, key, mu_strerror (rc));
+	  else
+	    printf ("%d: %s=%s\n", j, key, val);
+	}
+      else if (key[0] == '0' && key[1] == 0)
+	{
+	  rc = mu_property_clear (prop);
+	  printf ("%d: clear: %s\n", j, mu_strerror (rc));
+	}
+      else if (key[0] == '!' && key[1] == 0)
+	{
+	  rc = mu_property_invalidate (prop);
+	  printf ("%d: invalidate: %s\n", j, mu_strerror (rc));
+	}      
+      else
+	{
+	  mu_error ("%d: unrecognized command", i);
+	}
+    }
+
+  if (dumpit)
+    {
+      if (mu_property_get_iterator (prop, &itr) == 0)
+	{
+	  printf ("Property dump:\n");
+	  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+	       mu_iterator_next (itr))
+	    {
+	      const char *name, *val;
+	      
+	      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
+	      printf ("%s=%s\n", name, val);
+	    }
+	  mu_iterator_destroy (&itr);
+	}
+    }
+  
+  mu_property_destroy (&prop);
+  return 0;
+}
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 78fb693..43806c7 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -65,4 +65,5 @@ m4_include([decode2047.at])
 m4_include([encode2047.at])
 m4_include([fromflt.at])
 m4_include([wicket.at])
+m4_include([prop.at])
 
diff --git a/libproto/mh/Makefile.am b/libproto/mh/Makefile.am
index 322d657..f39cbc9 100644
--- a/libproto/mh/Makefile.am
+++ b/libproto/mh/Makefile.am
@@ -22,6 +22,7 @@ libmu_mh_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
 libmu_mh_la_LIBADD = ${MU_LIB_MAILUTILS}
 libmu_mh_la_SOURCES = \
  folder.c\
- mbox.c
+ mbox.c\
+ profile.c
 
 
diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c
index c3e550a..9dbcce2 100644
--- a/libproto/mh/mbox.c
+++ b/libproto/mh/mbox.c
@@ -22,8 +22,6 @@
 # include <config.h>
 #endif
 
-#ifdef ENABLE_MH
-
 #include <sys/types.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -63,6 +61,7 @@
 #include <mailutils/observer.h>
 #include <mailutils/io.h>
 #include <mailutils/cctype.h>
+#include <mailutils/mh.h>
 #include <mailutils/sys/mailbox.h>
 #include <mailutils/sys/registrar.h>
 #include <mailutils/sys/amd.h>
@@ -359,6 +358,30 @@ mh_remove (struct _amd_data *amd)
 }
 
 
+static int
+mh_get_property (mu_mailbox_t mailbox, mu_property_t *pprop)
+{
+  struct _amd_data *amd = mailbox->data;
+  mu_property_t property = NULL;
+  struct mu_mh_prop *mhprop;
+  const char *p;
+  
+  mhprop = calloc (1, sizeof (mhprop[0]));
+  if (!mhprop)
+    return ENOMEM;
+  p = mu_mhprop_get_value (mu_mh_profile, "mh-sequences",
+			   MU_MH_SEQUENCES_FILE);
+  mhprop->filename = mu_make_file_name (amd->name, p);
+  mu_property_create_init (&property, mu_mh_property_init, mhprop);
+  mu_mailbox_set_property (mailbox, property);
+      
+  /*FIXME mu_property_set_value (property, "TYPE", "MH", 1);*/
+  *pprop = property;
+  return 0;
+}
+
+
+
 
 int
 _mailbox_mh_init (mu_mailbox_t mailbox)
@@ -383,14 +406,9 @@ _mailbox_mh_init (mu_mailbox_t mailbox)
   amd->next_uid = _mh_next_seq;
   amd->remove = mh_remove;
 
-  /* Set our properties.  */
-  {
-    mu_property_t property = NULL;
-    mu_mailbox_get_property (mailbox, &property);
-    mu_property_set_value (property, "TYPE", "MH", 1);
-  }
-
+  mailbox->_get_property = mh_get_property;
+  
   return 0;
 }
 
-#endif
+
diff --git a/libproto/mh/profile.c b/libproto/mh/profile.c
new file mode 100644
index 0000000..6e9ce55
--- /dev/null
+++ b/libproto/mh/profile.c
@@ -0,0 +1,60 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/property.h>
+#include <mailutils/iterator.h>
+#include <mailutils/errno.h>
+#include <mailutils/mh.h>
+
+mu_property_t mu_mh_profile;
+mu_property_t mu_mh_context;
+
+const char *
+mu_mhprop_get_value (mu_property_t prop, const char *name, const char *defval)
+{
+  const char *p;
+
+  if (!prop || mu_property_sget_value (prop, name, &p))
+    p = defval; 
+  return p;
+}
+
+int
+mu_mhprop_iterate (mu_property_t prop, mu_mhprop_iterator_t fp, void *data)
+{
+  mu_iterator_t itr;
+  int rc;
+
+  if (!prop)
+    return EINVAL;
+  rc = mu_property_get_iterator (prop, &itr);
+  if (rc)
+    return rc;
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name, *val;
+      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
+      rc = fp (name, val, data);
+      if (rc)
+	break;
+    }
+  mu_iterator_destroy (&itr);
+  return rc;
+}
diff --git a/mh/.gitignore b/mh/.gitignore
index df37d55..e1a9c51 100644
--- a/mh/.gitignore
+++ b/mh/.gitignore
@@ -28,6 +28,7 @@ mhpath
 pick
 pick-gram.c
 pick-gram.h
+prompter
 refile
 repl
 rmf
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 08218b2..5ddf5fd 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -64,6 +64,7 @@ noinst_LIBRARIES = libmh.a
 
 libmh_a_SOURCES= \
  compcommon.c\
+ mboxprop.c\
  mh_alias_gram.c\
  mh_alias_lex.c\
  mh_argp.c\
diff --git a/mh/folder.c b/mh/folder.c
index 57a9179..0df51c3 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -740,6 +740,7 @@ roll_back (const char *folder_name, struct pack_tab *pack_tab, size_t i)
 
 struct fixup_data
 {
+  mu_mailbox_t mbox;
   const char *folder_dir;
   struct pack_tab *pack_tab;
   size_t count;
@@ -797,12 +798,12 @@ _fixup (const char *name, const char *value, struct fixup_data *fd, int flags)
 
   mu_wordsplit_free (&ws);
   
-  mh_seq_add (name, &msgset, flags | SEQ_ZERO);
+  mh_seq_add (fd->mbox, name, &msgset, flags | SEQ_ZERO);
   free (msgset.list);
 
   if (verbose)
     {
-      const char *p = mh_seq_read (name, flags);
+      const char *p = mh_seq_read (fd->mbox, name, flags);
       fprintf (stderr, "Sequence %s: %s\n", name, p);
     }
   
@@ -917,18 +918,23 @@ action_pack ()
     fprintf (stderr, _("Finished packing messages.\n"));
 
   /* Fix-up sequences */
-  fd.folder_dir = folder_dir;
-  fd.pack_tab = pack_tab;
-  fd.count = count;
-  if (verbose)
-    fprintf (stderr, _("Fixing global sequences\n"));
-  mh_global_sequences_iterate (fixup_global, &fd);
-  if (verbose)
-    fprintf (stderr, _("Fixing private sequences\n"));
-  mh_global_context_iterate (fixup_private, &fd);
-
   if (!dry_run)
-    mh_global_save_state ();
+    {
+      mbox = mh_open_folder (mh_current_folder (), 0);
+      fd.mbox = mbox;
+      fd.folder_dir = folder_dir;
+      fd.pack_tab = pack_tab;
+      fd.count = count;
+      if (verbose)
+	fprintf (stderr, _("Fixing global sequences\n"));
+      mh_global_sequences_iterate (mbox, fixup_global, &fd);
+      if (verbose)
+	fprintf (stderr, _("Fixing private sequences\n"));
+      mh_global_context_iterate (fixup_private, &fd);
+      mu_mailbox_close (mbox);
+      mu_mailbox_destroy (&mbox);
+      mh_global_save_state ();
+    }
   
   return 0;
 }
diff --git a/mh/inc.c b/mh/inc.c
index dde43fe..76a38b2 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -175,6 +175,8 @@ main (int argc, char **argv)
   mh_argp_init ();
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, NULL);
+  /* Inc sets missing cur to 1 */
+  mh_mailbox_cur_default = 1;
 
   if (!quiet && mh_format_parse (format_str, &format))
     {
@@ -256,9 +258,11 @@ main (int argc, char **argv)
       if (n == 1 && changecur)
 	{
 	  mu_message_t msg = NULL;
-      
-	  mu_mailbox_get_message (output, lastmsg+1, &msg);
-	  mh_message_number (msg, &current_message);
+	  size_t cur;
+	  
+	  mu_mailbox_get_message (output, lastmsg + 1, &msg);
+	  mh_message_number (msg, &cur);
+	  mh_mailbox_set_cur (output, cur);
 	}
 	  
       if (!quiet)
@@ -272,8 +276,12 @@ main (int argc, char **argv)
 	}
     }
 
-  if (changecur)
-    mh_global_save_state ();
+  if (!changecur)
+    {
+      mu_property_t prop = mh_mailbox_get_property (output);
+      mu_property_invalidate (prop);
+    }
+  mh_global_save_state ();
   
   mu_mailbox_close (output);
   mu_mailbox_destroy (&output);
diff --git a/mh/mark.c b/mh/mark.c
index 03588bf..78ed6c3 100644
--- a/mh/mark.c
+++ b/mh/mark.c
@@ -116,31 +116,41 @@ opt_handler (int key, char *arg, struct argp_state *state)
     }
   return 0;
 }
+
+
+struct mark_closure
+{
+  mu_mailbox_t mbox;
+  mh_msgset_t *msgset;
+};
 
 static int
 action_add (void *item, void *data)
 {
-  mh_seq_add ((char *)item, (mh_msgset_t *)data, seq_flags);
+  struct mark_closure *clos = data;
+  mh_seq_add (clos->mbox, (char *)item, clos->msgset, seq_flags);
   return 0;
 }
 
 static int
 action_delete (void *item, void *data)
 {
-  mh_seq_delete ((char *)item, (mh_msgset_t *)data, seq_flags);
+  struct mark_closure *clos = data;
+  mh_seq_delete (clos->mbox, (char *)item, clos->msgset, seq_flags);
   return 0;
 }
 
 static int
 action_list (void *item, void *data)
 {
+  struct mark_closure *clos = data;
   char *name = item;
   const char *val;
   
-  val = mh_seq_read (name, 0);
+  val = mh_seq_read (clos->mbox, name, 0);
   if (val)
     printf ("%s: %s\n", name, val);
-  else if ((val = mh_seq_read (name, SEQ_PRIVATE)))
+  else if ((val = mh_seq_read (clos->mbox, name, SEQ_PRIVATE)))
     printf ("%s (%s): %s\n", name, _("private"), val);
   return 0;
 }
@@ -171,9 +181,9 @@ list_public (const char *name, const char *value, void *data)
 }
 
 static void
-list_all ()
+list_all (mu_mailbox_t mbox)
 {
-  mh_global_sequences_iterate (list_public, NULL);
+  mh_global_sequences_iterate (mbox, list_public, NULL);
   mh_global_context_iterate (list_private, NULL);
 }
 
@@ -184,6 +194,7 @@ main (int argc, char **argv)
   mh_msgset_t msgset;
   mu_mailbox_t mbox;
   mu_url_t url;
+  struct mark_closure clos;
   
   MU_APP_INIT_NLS ();
   mh_argp_init ();
@@ -201,6 +212,8 @@ main (int argc, char **argv)
   mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
   mh_msgset_uids (mbox, &msgset);
   
+  clos.mbox = mbox;
+  clos.msgset = &msgset;
   switch (action)
     {
     case ARG_ADD:
@@ -209,7 +222,7 @@ main (int argc, char **argv)
 	  mu_error (_("--add requires at least one --sequence argument"));
 	  return 1;
 	}
-      mu_list_do (seq_list, action_add, (void *) &msgset);
+      mu_list_do (seq_list, action_add, (void *) &clos);
       mh_global_save_state ();
       break;
       
@@ -219,17 +232,18 @@ main (int argc, char **argv)
 	  mu_error (_("--delete requires at least one --sequence argument"));
 	  return 1;
 	}
-      mu_list_do (seq_list, action_delete, (void *) &msgset);
+      mu_list_do (seq_list, action_delete, (void *) &clos);
       mh_global_save_state ();
       break;
       
     case ARG_LIST:
       if (!seq_list)
-	list_all ();
+	list_all (mbox);
       else
-	mu_list_do (seq_list, action_list, NULL);
+	mu_list_do (seq_list, action_list, &clos);
       break;
     }
-
+  mu_mailbox_close (mbox);
+  mu_mailbox_destroy (&mbox);
   return 0;
 }
diff --git a/mh/mboxprop.c b/mh/mboxprop.c
new file mode 100644
index 0000000..bba10e7
--- /dev/null
+++ b/mh/mboxprop.c
@@ -0,0 +1,74 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2005, 2006, 2007, 2009, 2010 Free
+   Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* MH message sets. */
+
+#include <mh.h>
+
+/* Default value for missing "cur".  Valid values are 0 and 1. */
+int mh_mailbox_cur_default = 0;
+
+void
+mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur)
+{
+  mu_property_t prop = NULL;
+  const char *s;
+  int rc = mu_mailbox_get_property (mbox, &prop);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_property", NULL, rc);
+      exit (1);
+    }
+  rc = mu_property_sget_value (prop, "cur", &s);
+  if (rc == MU_ERR_NOENT)
+    *pcur = mh_mailbox_cur_default;
+  else if (rc == 0)
+    {
+      char *p;
+      *pcur = strtoul (s, &p, 10);
+      if (*p)
+	{
+	  mu_error (_("invalid \"cur\" value (%s)"), s);
+	  *pcur = 1;
+	}
+    }
+  else
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_sget_value", NULL, rc);
+      exit (1);
+    }
+}
+      
+void
+mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur)
+{
+  mu_property_t prop = NULL;
+  int rc = mu_mailbox_get_property (mbox, &prop);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_property", NULL, rc);
+      exit (1);
+    }      
+  rc = mu_property_set_value (prop, "cur", mu_umaxtostr (0, cur), 1);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_set_value", NULL, rc);
+      exit (1);
+    }
+}
+
+    
diff --git a/mh/mh.h b/mh/mh.h
index 17289c0..b9b89ef 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -55,6 +55,7 @@
 #include <mailutils/envelope.h>
 #include <mailutils/mime.h>
 #include <mailutils/io.h>
+#include <mailutils/property.h>
 
 #include <mu_umaxtostr.h>
 
@@ -233,9 +234,9 @@ typedef int (*mh_context_iterator) (const char *field, const char *value,
 #define SEQ_PRIVATE 1
 #define SEQ_ZERO    2
 
-extern size_t current_message;
 extern char mh_list_format[];
 extern int rcpt_mask;
+extern int mh_mailbox_cur_default;
 
 void mh_init (void);
 void mh_init2 (void);
@@ -251,13 +252,19 @@ const char *mh_global_context_get (const char *name, const char *defval);
 int mh_global_context_set (const char *name, const char *value);
 const char *mh_set_current_folder (const char *val);
 const char *mh_current_folder (void);
-const char *mh_global_sequences_get (const char *name, const char *defval);
-int mh_global_sequences_set (const char *name, const char *value);
+
+mu_property_t mh_mailbox_get_property (mu_mailbox_t mbox);
+const char *mh_global_sequences_get (mu_mailbox_t mbox,
+				     const char *name, const char *defval);
+void mh_global_sequences_set (mu_mailbox_t mbox,
+			      const char *name, const char *value);
+void mh_global_sequences_iterate (mu_mailbox_t mbox,
+				  mh_context_iterator fp, void *data);
+void mh_global_sequences_drop (mu_mailbox_t mbox);
+
 void mh_global_save_state (void);
 int mh_global_profile_iterate (mh_context_iterator fp, void *data);
 int mh_global_context_iterate (mh_context_iterator fp, void *data);
-int mh_global_sequences_iterate (mh_context_iterator fp, void *data);
-void mh_global_sequences_drop (void);
 
 int mh_interactive_mode_p (void);
 int mh_getyn (const char *fmt, ...) MU_PRINTFLIKE(1,2);
@@ -300,7 +307,7 @@ int mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
 int mh_msgset_member (mh_msgset_t *msgset, size_t num);
 void mh_msgset_reverse (mh_msgset_t *msgset);
 void mh_msgset_negate (mu_mailbox_t mbox, mh_msgset_t *msgset);
-int mh_msgset_current (mu_mailbox_t mbox, mh_msgset_t *msgset, int index);
+void mh_msgset_current (mu_mailbox_t mbox, mh_msgset_t *msgset, int index);
 void mh_msgset_free (mh_msgset_t *msgset);
 void mh_msgset_uids (mu_mailbox_t mbox, mh_msgset_t *msgset);
 
@@ -358,9 +365,11 @@ int mhl_format_run (mu_list_t fmt, int width, int length, int flags,
 		    mu_message_t msg, mu_stream_t output);
 void mhl_format_destroy (mu_list_t *fmt);
 
-void mh_seq_add (const char *name, mh_msgset_t *mset, int flags);
-int mh_seq_delete (const char *name, mh_msgset_t *mset, int flags);
-const char *mh_seq_read (const char *name, int flags);
+void mh_seq_add (mu_mailbox_t mbox, const char *name, mh_msgset_t *mset,
+		 int flags);
+int mh_seq_delete (mu_mailbox_t mbox, const char *name, mh_msgset_t *mset,
+		   int flags);
+const char *mh_seq_read (mu_mailbox_t mbox, const char *name, int flags);
 
 void mh_comp_draft (const char *formfile, const char *defformfile,
 		    const char *draftfile);
@@ -371,3 +380,6 @@ void ali_verbatim (int enable);
 
 char *mh_safe_make_file_name (const char *dir, const char *file);
   
+void mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur);
+void mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur);
+
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 60b8d7b..523d943 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -913,8 +913,19 @@ static void
 builtin_cur (struct mh_machine *mach)
 {
   size_t msgno = mach->msgno;
+  size_t cur;
+  int rc;
+  mu_mailbox_t mbox;
+  
+  rc = mu_message_get_mailbox (mach->message, &mbox);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_message_get_mailbox", NULL, rc);
+      exit (1);
+    }
   mh_message_number (mach->message, &msgno);
-  mach->arg_num = msgno == current_message;
+  mh_mailbox_get_cur (mbox, &cur); /* FIXME: Cache this */
+  mach->arg_num = msgno == cur;
 }
 
 static void
diff --git a/mh/mh_format.h b/mh/mh_format.h
index 64c1a66..0149fbc 100644
--- a/mh/mh_format.h
+++ b/mh/mh_format.h
@@ -49,7 +49,7 @@ struct mh_machine
 
   mu_list_t addrlist;       /* The list of email addresses output this far */
   int fmtflags;             /* Current formatting flags */
-  
+
   mu_message_t message;     /* Current message */
   size_t msgno;             /* Its number */
 };
diff --git a/mh/mh_global.c b/mh/mh_global.c
index 25873dd..2294477 100644
--- a/mh/mh_global.c
+++ b/mh/mh_global.c
@@ -20,10 +20,8 @@
 #include <mh.h>
 
 static const char *current_folder = NULL;
-size_t current_message = 0;
 mh_context_t *context;
 mh_context_t *profile;
-mh_context_t *sequences;
 int rcpt_mask = RCPT_DEFAULT;
 int mh_auto_install = 1;
 
@@ -137,54 +135,88 @@ mh_set_current_folder (const char *val)
   current_folder = mh_current_folder ();
   return current_folder;
 }
-
+
 /* Global sequences */
-
-void
-_mh_init_global_sequences ()
+mu_property_t
+mh_mailbox_get_property (mu_mailbox_t mbox)
 {
-  const char *name;
-  char *p, *seq_name;
-
-  if (sequences)
-    return;
-  
-  _mh_init_global_context ();
-  name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE);
-  p = mh_expand_name (NULL, current_folder, 0);
-  seq_name = mh_safe_make_file_name (p, name);
-  free (p);
-  sequences = mh_context_create (seq_name, 1);
-  if (mh_context_read (sequences) == 0)
-    current_message = strtoul (mh_context_get_value (sequences, "cur", "0"),
-			       NULL, 10);
+  mu_property_t prop;
+  int rc = mu_mailbox_get_property (mbox, &prop);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_property", NULL, rc);
+      exit (1);
+    }
+  return prop;
 }
-
+  
 void
-mh_global_sequences_drop ()
+mh_global_sequences_drop (mu_mailbox_t mbox)
 {
-  mh_context_destroy (&sequences);
+  mu_property_t prop = mh_mailbox_get_property (mbox);
+  int rc = mu_property_clear (prop);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_clear", NULL, rc);
+      exit (1);
+    }
 }
 
 const char *
-mh_global_sequences_get (const char *name, const char *defval)
-{
-  _mh_init_global_sequences ();
-  return mh_context_get_value (sequences, name, defval);
+mh_global_sequences_get (mu_mailbox_t mbox, const char *name,
+			 const char *defval)
+{
+  mu_property_t prop = mh_mailbox_get_property (mbox);
+  const char *s;
+  int rc = mu_property_sget_value (prop, name, &s);
+  if (rc == MU_ERR_NOENT)
+    s = defval;
+  else if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_sget_value", name, rc);
+      exit (1);
+    }
+  return s;
 }
 
-int
-mh_global_sequences_set (const char *name, const char *value)
+void
+mh_global_sequences_set (mu_mailbox_t mbox, const char *name,
+			 const char *value)
 {
-  _mh_init_global_sequences ();
-  return mh_context_set_value (sequences, name, value);
+  mu_property_t prop = mh_mailbox_get_property (mbox);
+  int rc = mu_property_set_value (prop, name, value, 1);
+  if (rc && !(!value && rc == MU_ERR_NOENT))
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_set_value", name, rc);
+      exit (1);
+    }
 }
 
-int
-mh_global_sequences_iterate (mh_context_iterator fp, void *data)
+/* FIXME: Rewrite using mu_mhprop_iterate */
+void
+mh_global_sequences_iterate (mu_mailbox_t mbox,
+			     mh_context_iterator fp, void *data)
 {
-  _mh_init_global_context ();
-  return mh_context_iterate (sequences, fp, data);
+  int rc;
+  mu_iterator_t itr;
+  mu_property_t prop = mh_mailbox_get_property (mbox);
+
+  rc = mu_property_get_iterator (prop, &itr);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_get_iterator", NULL, rc);
+      exit (1);
+    }
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name, *val;
+      
+      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
+      if (fp (name, val, data))
+	break;
+    }
+  mu_iterator_destroy (&itr);
 }
 
 /* Global state */
@@ -192,9 +224,6 @@ mh_global_sequences_iterate (mh_context_iterator fp, void *data)
 void
 mh_global_save_state ()
 {
-  mh_context_set_value (sequences, "cur", mu_umaxtostr (0, current_message));
-  mh_context_write (sequences);
-
   mh_context_set_value (context, "Current-Folder", current_folder);
   mh_context_write (context);
 }
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 9f37b86..f35c08f 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -67,7 +67,6 @@ void
 mh_init2 ()
 {
   mh_current_folder ();
-  mh_global_sequences_get ("cur", NULL);
 }
 
 int
diff --git a/mh/mh_msgset.c b/mh/mh_msgset.c
index 41eb036..6e058a2 100644
--- a/mh/mh_msgset.c
+++ b/mh/mh_msgset.c
@@ -18,7 +18,6 @@
 /* MH message sets. */
 
 #include <mh.h>
-#include <mailutils/argcv.h>
 
 /* Expand a message set (msgcnt;msglist) to accomodate `inc' more
    elements */
@@ -72,13 +71,16 @@ msgset_cur (mu_mailbox_t mbox, size_t *pnum)
 {
   size_t i, count = 0;
   static int cached_n = 0;
+  size_t cur;
 
+  mh_mailbox_get_cur (mbox, &cur);
+  
   if (cached_n)
     {
       *pnum = cached_n;
       return 0;
     }
-  
+
   mu_mailbox_messages_count (mbox, &count);
   for (i = 1; i <= count; i++)
     {
@@ -87,7 +89,7 @@ msgset_cur (mu_mailbox_t mbox, size_t *pnum)
       
       mu_mailbox_get_message (mbox, i, &msg);
       mh_message_number (msg, &uid);
-      if (uid == current_message)
+      if (uid == cur)
 	{
 	  *pnum = cached_n = i;
 	  return 0;
@@ -244,7 +246,7 @@ expand_user_seq (mu_mailbox_t mbox, mh_msgset_t *msgset, char *arg)
   p = strchr (arg, ':');
   if (p)
     *p++ = 0;
-  listp = mh_global_sequences_get (arg, NULL);
+  listp = mh_global_sequences_get (mbox, arg, NULL);
   if (!listp)
     {
       int len;
@@ -255,7 +257,7 @@ expand_user_seq (mu_mailbox_t mbox, mh_msgset_t *msgset, char *arg)
       if (strncmp (arg, neg, len))
 	return 1;
       negate = 1;
-      listp = mh_global_sequences_get (arg + len, NULL);
+      listp = mh_global_sequences_get (mbox, arg + len, NULL);
       if (!listp)
 	return 1;
     }
@@ -569,13 +571,21 @@ mh_msgset_reverse (mh_msgset_t *msgset)
 
 /* Set the current message to that contained at position `index'
    in the given message set */
-int
+void
 mh_msgset_current (mu_mailbox_t mbox, mh_msgset_t *msgset, int index)
 {
   mu_message_t msg = NULL;
-  if (mu_mailbox_get_message (mbox, msgset->list[index], &msg))
-    return 1;
-  return mh_message_number (msg, &current_message);
+  int rc;
+  size_t cur;
+  
+  rc = mu_mailbox_get_message (mbox, msgset->list[index], &msg);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_message", NULL, rc);
+      exit (1);
+    }
+  mh_message_number (msg, &cur);
+  mh_mailbox_set_cur (mbox, cur);
 }
 
 /* Free memory allocated for the message set. Note, that the msgset
diff --git a/mh/mh_sequence.c b/mh/mh_sequence.c
index f80b855..df459bd 100644
--- a/mh/mh_sequence.c
+++ b/mh/mh_sequence.c
@@ -28,7 +28,7 @@ private_sequence_name (const char *name)
 }
 
 const char *
-mh_seq_read (const char *name, int flags)
+mh_seq_read (mu_mailbox_t mbox, const char *name, int flags)
 {
   const char *value;
 
@@ -39,12 +39,12 @@ mh_seq_read (const char *name, int flags)
       free (p);
     }
   else
-    value = mh_global_sequences_get (name, NULL);
+    value = mh_global_sequences_get (mbox, name, NULL);
   return value;
 }
 
 static void
-write_sequence (const char *name, char *value, int private)
+write_sequence (mu_mailbox_t mbox, const char *name, char *value, int private)
 {
   if (private)
     {
@@ -53,24 +53,24 @@ write_sequence (const char *name, char *value, int private)
       free (p);
     }
   else
-    mh_global_sequences_set (name, value);
+    mh_global_sequences_set (mbox, name, value);
 }
 
 static void
-delete_sequence (const char *name, int private)
+delete_sequence (mu_mailbox_t mbox, const char *name, int private)
 {
-  write_sequence (name, NULL, private);
+  write_sequence (mbox, name, NULL, private);
 }
 
 void
-mh_seq_add (const char *name, mh_msgset_t *mset, int flags)
+mh_seq_add (mu_mailbox_t mbox, const char *name, mh_msgset_t *mset, int flags)
 {
-  const char *value = mh_seq_read (name, flags);
+  const char *value = mh_seq_read (mbox, name, flags);
   char *new_value, *p;
   const char *buf;
   size_t i, len;
 
-  delete_sequence (name, !(flags & SEQ_PRIVATE));
+  delete_sequence (mbox, name, !(flags & SEQ_PRIVATE));
 
   if (flags & SEQ_ZERO)
     value = NULL;
@@ -99,9 +99,11 @@ mh_seq_add (const char *name, mh_msgset_t *mset, int flags)
       *p++ = ' ';
     }
   *p = 0;
-  write_sequence (name, new_value, flags & SEQ_PRIVATE);
+  write_sequence (mbox, name, new_value, flags & SEQ_PRIVATE);
+  /* FIXME
   if (mu_c_strcasecmp (name, "cur") == 0)
     current_message = strtoul (new_value, NULL, 0);
+  */
   free (new_value);
 }
 
@@ -119,9 +121,10 @@ cmp_msgnum (const void *a, const void *b)
 }
 
 int
-mh_seq_delete (const char *name, mh_msgset_t *mset, int flags)
+mh_seq_delete (mu_mailbox_t mbox, const char *name,
+	       mh_msgset_t *mset, int flags)
 {
-  const char *value = mh_seq_read (name, flags);
+  const char *value = mh_seq_read (mbox, name, flags);
   char *new_val;
   char *p;
   size_t i, count;
@@ -167,7 +170,7 @@ mh_seq_delete (const char *name, mh_msgset_t *mset, int flags)
 	}
     }
   *p = 0;
-  write_sequence (name, count > 0 ? new_val : NULL, flags & SEQ_PRIVATE);
+  write_sequence (mbox, name, count > 0 ? new_val : NULL, flags & SEQ_PRIVATE);
   mu_wordsplit_free (&ws);
   free (new_val);
   
diff --git a/mh/pick.c b/mh/pick.c
index 0bbf3ba..d9677cc 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -298,10 +298,18 @@ pick_message (mu_mailbox_t mbox, mu_message_t msg, size_t num, void *data)
     }
 }
 
+
+struct pick_closure
+{
+  mu_mailbox_t mbox;
+  mh_msgset_t *msgset;
+};
+
 static int
 action_add (void *item, void *data)
 {
-  mh_seq_add ((char *)item, (mh_msgset_t *)data, seq_flags);
+  struct pick_closure *clos = data;
+  mh_seq_add (clos->mbox, (char *)item, clos->msgset, seq_flags);
   return 0;
 }
 
@@ -395,13 +403,18 @@ main (int argc, char **argv)
 
   if (seq_list)
     {
+      struct pick_closure clos;
       mh_msgset_t msgset;
       msgset.count = msgno_count;
       msgset.list = obstack_finish (&msgno_stk);
-      mu_list_do (seq_list, action_add, (void*) &msgset);
+      clos.mbox = mbox;
+      clos.msgset = &msgset;
+      mu_list_do (seq_list, action_add, &clos);
     }
 
   mh_global_save_state ();
+  mu_mailbox_close (mbox);
+  mu_mailbox_destroy (&mbox);
   return status;
 }
   
diff --git a/mh/prompter.c b/mh/prompter.c
index 7de7a43..062bd9c 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -255,6 +255,7 @@ main (int argc, char **argv)
 	  mu_opool_destroy (&opool);
 	}
     }
+  mu_iterator_destroy (&itr);
   mu_stream_printf (strout, "--------\n");
   mu_stream_write (tmp, "\n", 1, NULL);
 
@@ -263,7 +264,7 @@ main (int argc, char **argv)
   if (prepend_option)
     {
       mu_stream_printf (strout, "\n--------%s\n\n", _("Enter initial text"));
-      while (newval = prompter_get_line ())
+      while ((newval = prompter_get_line ()))
 	{
 	  mu_stream_write (tmp, newval, strlen (newval), NULL);
 	  free (newval);
@@ -286,7 +287,7 @@ main (int argc, char **argv)
   if (!prepend_option && !rapid_option)
     {
       printf ("\n--------%s\n\n", _("Enter additional text"));
-      while (newval = prompter_get_line ())
+      while ((newval = prompter_get_line ()))
 	{
 	  mu_stream_write (tmp, newval, strlen (newval), NULL);
 	  free (newval);
diff --git a/mh/rmf.c b/mh/rmf.c
index bf07fe4..656c9fc 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -53,7 +53,7 @@ struct mh_option mh_option[] = {
 
 int explicit_folder; /* Was the folder explicitly given */
 int interactive; /* Ask for confirmation before deleting */
-int recurse;     /* Recursively process all the sub-directories */
+int recursive;     /* Recursively process all the sub-directories */
 
 static char *cur_folder_path; /* Full pathname of the current folder */
 static char *folder_name;     /* Name of the (topmost) folder to be
@@ -78,11 +78,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 	
     case ARG_RECURSIVE:
-      recurse = is_true (arg);
+      recursive = is_true (arg);
       break;
       
     case ARG_NORECURSIVE:
-      recurse = 0;
+      recursive = 0;
       break;
 
     default:
@@ -107,6 +107,31 @@ current_folder_path ()
 static int
 rmf (const char *name)
 {
+  mu_mailbox_t mbox = NULL;
+  int rc;
+  
+  rc = mu_mailbox_create_default (&mbox, name);
+  if (rc)
+    {
+      mu_error (_("cannot create mailbox %s: %s"),
+		name, strerror (rc));
+      return 1;
+    }
+
+  rc = mu_mailbox_remove (mbox);
+  mu_mailbox_destroy (&mbox);
+  if (rc)
+    {
+      mu_error (_("cannot remove %s: %s"), name, mu_strerror (rc));
+      return 1;
+    }
+  return 0;
+}
+
+/* Recursive rmf */
+static int
+recrmf (const char *name)
+{
   DIR *dir;
   struct dirent *entry;
   int failures = 0;
@@ -137,50 +162,24 @@ rmf (const char *name)
 	  mu_diag_funcall (MU_DIAG_ERROR, "stat", p, errno);
 	}
       else if (S_ISDIR (st.st_mode))
-	{
-	  if (recurse)
-	    failures += rmf (p);
-	  else
-	    {
-	      printf ("%s: file `%s' not deleted, continuing...\n",
-		      mu_program_name, p);
-	      failures++;
-	    }
-	}
-      else
-	{
-	  if (unlink (p))
-	    {
-	      mu_diag_funcall (MU_DIAG_ERROR, "unlink", p, errno);
-	      failures++;
-	    }
-	}
+	failures += recrmf (p);
       free (p);
     }
   closedir (dir);
 
   if (failures == 0)
-    failures += rmdir (name);
+    failures += rmf (name);
   else
     printf ("%s: folder `%s' not removed\n",
 	    mu_program_name, name);
 
-  if (failures == 0)
-    {
-      if (cur_folder_path && strcmp (name, cur_folder_path) == 0)
-	{
-	  mh_set_current_folder ("inbox");
-	  mh_global_sequences_drop ();
-	  mh_global_save_state ();
-	  printf ("[+inbox now current]\n");
-	}
-    }
   return failures;
 }
 
 int
 main (int argc, char **argv)
 {
+  int status;
   char *name;
 
   /* Native Language Support */
@@ -199,6 +198,23 @@ main (int argc, char **argv)
     }
   else
     name = mh_expand_name (NULL, folder_name, 0);
-  rmf (name);
-  return 0;
+  if (recursive)
+    status = recrmf (name);
+  else
+    {
+      if (interactive && !mh_getyn (_("Remove folder %s"), name))
+	exit (0);
+      status = rmf (name);
+    }
+  if (status == 0)
+    {
+      if (cur_folder_path && strcmp (name, cur_folder_path) == 0)
+	{
+	  mh_set_current_folder ("inbox");
+	  mh_global_save_state ();
+	  printf ("[+inbox now current]\n");
+	}
+      return 0;
+    }      
+  return 1;
 }
diff --git a/mh/scan.c b/mh/scan.c
index 0fe0ee4..05ec180 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -219,7 +219,8 @@ main (int argc, char **argv)
 
   clear_screen ();
   mh_global_save_state ();
-  
+  mu_mailbox_close (mbox);
+  mu_mailbox_destroy (&mbox);
   return status;
 }
 
diff --git a/mh/tests/folder.at b/mh/tests/folder.at
index e7d0204..cd1b9b9 100644
--- a/mh/tests/folder.at
+++ b/mh/tests/folder.at
@@ -96,7 +96,6 @@ Mail/inbox/2
 Mail/inbox/3
 Mail/inbox/4
 Mail/inbox/5
-Mail/inbox/.mh_sequences
 ])
 
 MH_CHECK([folder --pack=N],[folder06 folder--pack=N],[
@@ -115,7 +114,6 @@ Mail/inbox/2
 Mail/inbox/3
 Mail/inbox/4
 Mail/inbox/5
-Mail/inbox/.mh_sequences
 ])
 
 MH_CHECK([folder -push/-pop],[folder07 folder-push folder-pop folder-push-pop],
diff --git a/mh/tests/inc.at b/mh/tests/inc.at
index 64bcedb..e2150c8 100644
--- a/mh/tests/inc.at
+++ b/mh/tests/inc.at
@@ -22,7 +22,7 @@ inc -notruncate -file ./mbox1 | sed 's/ *$//'
 cmp $abs_top_srcdir/testsuite/spool/mbox1 mbox1
 ],
 [0],
-[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+[   1+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
    2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
@@ -36,7 +36,7 @@ echo "Next"
 inc -truncate -file ./mbox1 | sed 's/ *$//'
 ],
 [0],
-[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+[   1+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
    2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
@@ -50,12 +50,42 @@ mkdir Mail/new
 inc +new -file ./mbox1 | sed 's/ *$//'
 ],
 [0],
-[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+[   1+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
    2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
 ])
 
+MH_CHECK([inc -changecur],[inc03 inc-changecur],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
+inc -changecur -file ./mbox1 | sed 's/ *$//'
+],
+[0],
+[   6+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   7  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   8  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   9  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+  10  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+])
+
+MH_CHECK([inc -nochangecur],[inc04 inc-nochangecur],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 1" > Mail/inbox/.mh_sequences
+MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
+inc -nochangecur -file ./mbox1 | sed 's/ *$//'
+grep ^cur: Mail/inbox/.mh_sequences
+],
+[0],
+[   6  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   7  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+   8  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
+   9  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
+  10  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
+cur: 1  
+])
+
+
 m4_popdef[MH_KEYWORDS])
 # End of inc.at
diff --git a/mu/Makefile.am b/mu/Makefile.am
index 7684892..a4eb398 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -78,7 +78,7 @@ AM_CPPFLAGS = \
   -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
   -DI18NLIBS="\"$(LIBINTL)\""
 
-BUILD_SOURCES=mu-setup.c mu-setup.h
+BUILT_SOURCES=mu-setup.c mu-setup.h
 EXTRA_DIST=mu-setup.c mu-setup.h
 
 mu-setup.h: Makefile.am $(MODULES) $(IDLE_MODULES) 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Nov 20 18:04:02 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PJwTS-0003JV-Po
	for mharc-commit-mailutils@gnu.org; Sat, 20 Nov 2010 18:04:02 -0500
Received: from [140.186.70.92] (port=53276 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PJwTM-0003IK-Mc
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 18:04:01 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJwTI-0001WA-87
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 18:03:56 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:53731
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJwTI-0001W6-1e
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 18:03:52 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJwTH-0005qL-KN
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 23:03:51 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PJwT5-0001J5-AD
	for commit-mailutils@gnu.org; Sat, 20 Nov 2010 23:03:51 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: c08b926f664b27953483a0dffcbe381ddaa154e5
X-Git-Newrev: 597404315ba308889ea2776c56c184d1eb9b02fc
Message-Id: <E1PJwT5-0001J5-AD@vcs-noshell.in.savannah.gnu.org>
Date: Sat, 20 Nov 2010 23:03:41 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-207-g5974043
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 20 Nov 2010 23:04: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=597404315ba308889ea2776c56c184d1eb9b02fc

The branch, master has been updated
       via  597404315ba308889ea2776c56c184d1eb9b02fc (commit)
       via  72beac0a0f1bc97283ffefac9c79730b94e62f53 (commit)
      from  c08b926f664b27953483a0dffcbe381ddaa154e5 (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 597404315ba308889ea2776c56c184d1eb9b02fc
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Nov 21 00:45:46 2010 +0200

    mh: improve component reading (profile, context and whom).
    
    * libmailutils/filter/header.c: New file.
    * libmailutils/filter/Makefile.am (libfilter_la_SOURCES): Add header.c.
    * libmailutils/filter/filter.c (mu_filter_get_list): Register
    mu_header_filter.
    * libmailutils/filter/inline-comment.c: (ilcmt_ws)
    (ilcmt_rollback): New states.
    (ILCMT_REMOVE_EMPTY_LINES,ILCMT_SQUEEZE_WS): New flags.
    (ilcmt_data)<buf,size,level,replay>: New members.
    (ilcmt_action): New enum
    (new_ilcmt_state): Return enum ilcmt_action.
    (_ilcmt_decoder): Optionally remove
    empty lines and squeeze leading white space.
    * libmailutils/property/mhprop.c (_mh_prop_read_stream): Remove
    empty lines from the input.
    
    * libmailutils/tests/Makefile.am (TESTSUITE_AT): Add hdrflt.at
    and inline-comment.at.
    * libmailutils/tests/testsuite.at: Include hdrflt.at and inline-comment.at.
    * libmailutils/tests/fltst.c: Pass optional arguments to the
    filter creation procedure.
    
    * mh/mh_whom.c (read_header): New function.
    (mh_whom): Rewrite using headers.
    
    * include/mailutils/filter.h: Fix a typo.
    * libmailutils/stream/fltstream.c: Likewise.
    * libmu_auth/gsasl.c: Likewise.

commit 72beac0a0f1bc97283ffefac9c79730b94e62f53
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Nov 20 21:12:12 2010 +0200

    Move MH profile & context support to libproto.
    
    * mh/mh_ctx.c: Remove.
    * mh/Makefile.am (libmh_a_SOURCES): Remove mh_ctx.c
    * mh/folder.c (read_seq_file): Use mu_property_t.
    * mh/mh.h (mh_context_iterator): Remove typedef.
    (mh_global_profile_get, mh_global_profile_set)
    (mh_global_profile_iterate)
    (mh_global_context_set,mh_global_context_set)
    (mh_global_context_iterate): Rewrite as macros.
    (mh_global_sequences_iterate): Change signature.
    (mh_read_property_file,mh_property_merge): New protos.
    (mh_context_create,mh_context_read,mh_context_write)
    (mh_context_get_value,mh_context_set_value,mh_context_iterate)
    (mh_context_destroy,mh_context_merge): Remove protos.
    * mh/mh_global.c (mh_global_profile_get, mh_global_profile_set)
    (mh_global_profile_iterate)
    (mh_global_context_set,mh_global_context_set)
    (mh_global_context_iterate): Remove.
    (mh_read_property_file,mh_property_merge): New functions.
    (_mh_init_global_context,mh_read_profile)
    (mh_set_current_folder,mh_global_sequences_iterate): Rewrite.
    (mh_global_save_state): Rewrite.
    * mh/mh_whom.c (mh_whom): Use mu_property_t.
    * mh/send.c: Use mu_property_t.
    * po/POTFILES.in: Add mh/mboxprop.c.

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

Summary of changes:
 include/mailutils/filter.h                      |    3 +-
 libmailutils/filter/Makefile.am                 |    1 +
 libmailutils/filter/filter.c                    |    1 +
 libmailutils/filter/header.c                    |  121 ++++++++++++
 libmailutils/filter/inline-comment.c            |  171 ++++++++++++++++--
 libmailutils/property/mhprop.c                  |    5 +-
 libmailutils/stream/fltstream.c                 |    6 +-
 libmailutils/tests/Makefile.am                  |    2 +
 libmailutils/tests/fltst.c                      |   24 ++-
 mh/tests/mhl.at => libmailutils/tests/hdrflt.at |   38 ++--
 libmailutils/tests/inline-comment.at            |  113 +++++++++++
 libmailutils/tests/testsuite.at                 |    2 +
 libmu_auth/gsasl.c                              |    4 +-
 mh/Makefile.am                                  |    1 -
 mh/folder.c                                     |   11 +-
 mh/mh.h                                         |   40 ++--
 mh/mh_ctx.c                                     |  231 -----------------------
 mh/mh_global.c                                  |  145 ++++++++-------
 mh/mh_whom.c                                    |  100 +++++++++--
 mh/send.c                                       |   71 +++++---
 po/POTFILES.in                                  |    1 +
 21 files changed, 677 insertions(+), 414 deletions(-)
 create mode 100644 libmailutils/filter/header.c
 copy mh/tests/mhl.at => libmailutils/tests/hdrflt.at (58%)
 create mode 100644 libmailutils/tests/inline-comment.at
 delete mode 100644 mh/mh_ctx.c

diff --git a/include/mailutils/filter.h b/include/mailutils/filter.h
index aff0031..20d4880 100644
--- a/include/mailutils/filter.h
+++ b/include/mailutils/filter.h
@@ -56,7 +56,7 @@ enum mu_filter_command
 enum mu_filter_result
   {
     mu_filter_ok,
-    mu_filter_falure,
+    mu_filter_failure,
     mu_filter_moreinput,
     mu_filter_moreoutput,
     mu_filter_again
@@ -109,6 +109,7 @@ extern mu_filter_record_t mu_rfc_2047_Q_filter;
 extern mu_filter_record_t mu_rfc_2047_B_filter;
 extern mu_filter_record_t mu_from_filter;
 extern mu_filter_record_t mu_inline_comment_filter;
+extern mu_filter_record_t mu_header_filter;
 
 enum mu_iconv_fallback_mode
   {
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index e870a09..0dc7388 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -27,6 +27,7 @@ libfilter_la_SOURCES =\
  filter.c\
  filter_iconv.c\
  fromflt.c\
+ header.c\
  inline-comment.c\
  linelenflt.c\
  qpflt.c
diff --git a/libmailutils/filter/filter.c b/libmailutils/filter/filter.c
index 7525cf1..5b37cc6 100644
--- a/libmailutils/filter/filter.c
+++ b/libmailutils/filter/filter.c
@@ -79,6 +79,7 @@ mu_filter_get_list (mu_list_t *plist)
       mu_list_append (filter_list, mu_rfc_2047_B_filter);
       mu_list_append (filter_list, mu_from_filter);
       mu_list_append (filter_list, mu_inline_comment_filter);
+      mu_list_append (filter_list, mu_header_filter);
       /* FIXME: add the default encodings?  */
     }
   *plist = filter_list;
diff --git a/libmailutils/filter/header.c b/libmailutils/filter/header.c
new file mode 100644
index 0000000..8369d6a
--- /dev/null
+++ b/libmailutils/filter/header.c
@@ -0,0 +1,121 @@
+/* Message header filter for GNU Mailutils.
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+/* This filter reads the input data up to the first empty line (i.e. \n\n).
+   It is suitable to extract headers from RFC822 messages.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/errno.h>
+#include <mailutils/filter.h>
+#include <mailutils/cctype.h>
+
+enum hflt_state
+  {
+    hflt_initial,
+    hflt_newline,
+    hflt_copy
+  };
+
+static int
+new_state (int *pd, unsigned c)
+{
+  switch (*pd)
+    {
+    case hflt_initial:
+    case hflt_copy:
+      *pd = (c == '\n') ? hflt_newline : hflt_copy;
+      break;
+      
+    case hflt_newline:
+      if (c == '\n')
+	return 1;
+      *pd = hflt_copy;
+      break;
+    }
+  return 0;
+}
+
+static enum mu_filter_result
+_hflt_decoder (void *xd, enum mu_filter_command cmd,
+		struct mu_filter_io *iobuf)
+{
+  int *pd = xd;
+  size_t i, j;
+  const unsigned char *iptr;
+  size_t isize;
+  char *optr;
+  size_t osize;
+
+  switch (cmd)
+    {
+    case mu_filter_init:
+      *pd = hflt_initial;
+      return mu_filter_ok;
+      
+    case mu_filter_done:
+      return mu_filter_ok;
+      
+    default:
+      break;
+    }
+  
+  iptr = (const unsigned char *) iobuf->input;
+  isize = iobuf->isize;
+  optr = iobuf->output;
+  osize = iobuf->osize;
+
+  for (i = j = 0; i < isize && j < osize; i++)
+    {
+      unsigned char c = *iptr++;
+      if (new_state (pd, c))
+	{
+	  iobuf->eof = 1;
+	  break;
+	}
+      optr[j++] = c;
+    }
+
+  iobuf->isize = i;
+  iobuf->osize = j;
+  return mu_filter_ok;
+}
+  
+static int
+alloc_state (void **pret, int mode MU_ARG_UNUSED,
+	     int argc MU_ARG_UNUSED, const char **argv MU_ARG_UNUSED)
+{
+  int *pd = malloc (sizeof (*pd));
+  
+  if (!pd)
+    return ENOMEM;
+  *pret = pd;
+  return 0;
+}
+
+static struct _mu_filter_record _header_filter = {
+  "HEADER",
+  0,
+  alloc_state,
+  NULL,
+  _hflt_decoder
+};
+
+mu_filter_record_t mu_header_filter = &_header_filter;
diff --git a/libmailutils/filter/inline-comment.c b/libmailutils/filter/inline-comment.c
index ec6d238..018e70f 100644
--- a/libmailutils/filter/inline-comment.c
+++ b/libmailutils/filter/inline-comment.c
@@ -36,22 +36,65 @@
 #include <string.h>
 #include <mailutils/errno.h>
 #include <mailutils/filter.h>
+#include <mailutils/cctype.h>
 
 enum ilcmt_state
   {
     ilcmt_initial,
     ilcmt_newline,
     ilcmt_copy,
-    ilcmt_comment
+    ilcmt_comment,
+    ilcmt_ws,
+    ilcmt_rollback
   };
 
+#define ILCMT_REMOVE_EMPTY_LINES 0x01
+#define ILCMT_SQUEEZE_WS         0x02
+
 struct ilcmt_data
 {
   enum ilcmt_state state;
   int cstart;
+  int flags;
+  char *buf;
+  size_t size;
+  size_t level;
+  size_t replay;
 };
 
+enum ilcmt_action
+  {
+    action_echo,
+    action_noecho,
+    action_error
+  };
+
+#define ILCMT_BUF_INIT 80
+#define ILCMT_BUF_INCR 16
+
 static int
+ilcmt_save (struct ilcmt_data *pd, int c)
+{
+  if (pd->level == pd->size)
+    {
+      size_t nsz;
+      char *np;
+      
+      if (pd->size == 0)
+	nsz = ILCMT_BUF_INIT;
+      else
+	nsz = pd->size + ILCMT_BUF_INCR;
+      np = realloc (pd->buf, nsz);
+      if (!np)
+	return 1;
+      pd->buf = np;
+      pd->size = nsz;
+    }
+  pd->buf[pd->level++] = c;
+  return 0;
+}
+
+static enum ilcmt_action
 new_ilcmt_state (struct ilcmt_data *pd, int c)
 {
   switch (pd->state)
@@ -61,11 +104,47 @@ new_ilcmt_state (struct ilcmt_data *pd, int c)
       if (c == pd->cstart)
 	{
 	  pd->state = ilcmt_comment;
-	  return 0;
+	  return action_noecho;
 	}
-      else
-	pd->state = ilcmt_copy;
+      else if (c == '\n')
+	{
+	  if (pd->flags & ILCMT_REMOVE_EMPTY_LINES)
+	    return action_noecho;
+	}
+      else if (mu_isspace (c))
+	{
+	  if (pd->flags & ILCMT_REMOVE_EMPTY_LINES)
+	    {
+	      pd->state = ilcmt_ws;
+	      pd->level = 0;
+	      if (!(pd->flags & ILCMT_SQUEEZE_WS))
+		{
+		  if (ilcmt_save (pd, c))
+		    return action_error;
+		}
+	      return action_noecho;
+	    }
+	}
+      pd->state = ilcmt_copy;
       break;
+
+    case ilcmt_ws:
+      if (c == '\n')
+	pd->state = ilcmt_newline;
+      else if (mu_isspace (c))
+	{
+	  if (!(pd->flags & ILCMT_SQUEEZE_WS))
+	    {
+	      if (ilcmt_save (pd, c))
+		return action_error;
+	    }
+	}
+      else
+	{
+	  pd->replay = 0;
+	  pd->state = ilcmt_rollback;
+	}
+      return action_noecho;
       
     case ilcmt_copy:
       if (c == '\n')
@@ -75,9 +154,13 @@ new_ilcmt_state (struct ilcmt_data *pd, int c)
     case ilcmt_comment:
       if (c == '\n')
 	pd->state = ilcmt_newline;
-      return 0;
+      return action_noecho;
+
+    default:
+      /* should not happen */
+      break;
     }
-  return 1;
+  return action_echo;
 }
 
 static enum mu_filter_result
@@ -109,11 +192,50 @@ _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
   optr = iobuf->output;
   osize = iobuf->osize;
 
-  for (i = j = 0; i < isize && j < osize; i++)
+  i = j = 0;
+  if (pd->state == ilcmt_rollback)
+    {
+      if (pd->flags & ILCMT_SQUEEZE_WS)
+	{
+	  if (j == osize)
+	    {
+	      iobuf->osize = 1;
+	      return mu_filter_moreoutput;
+	    }
+	  optr[j++] = ' ';
+	  pd->state = ilcmt_copy;
+	}
+      else
+	while (j < osize)
+	  {
+	    if (pd->replay == pd->level)
+	      {
+		pd->state = ilcmt_copy;
+		break;
+	      }
+	    optr[j++] = pd->buf[pd->replay++];
+	  }
+      
+      if (pd->state == ilcmt_copy)
+	{
+	  /* Clear the buffer state. */
+	  pd->level = pd->replay = 0;
+	}
+    }
+    
+  for (; i < isize && j < osize; i++)
     {
       unsigned char c = *iptr++;
-      if (new_ilcmt_state (pd, c))
+      enum ilcmt_action action = new_ilcmt_state (pd, c);
+      if (action == action_echo)
 	optr[j++] = c;
+      else if (action == action_noecho)
+	{
+	  if (pd->state == ilcmt_rollback)
+	    break;
+	}
+      else
+	return mu_filter_failure;
     }
 
   iobuf->isize = i;
@@ -125,14 +247,39 @@ static int
 alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
 {
   struct ilcmt_data *pd = malloc (sizeof (*pd));
+  int i;
   
   if (!pd)
     return ENOMEM;
 
-  if (argc == 2)
-    pd->cstart = argv[1][0];
-  else
-    pd->cstart = ';';
+  pd->cstart = ';';
+  pd->flags = 0;
+  pd->buf = NULL;
+  pd->size = pd->level = pd->replay = 0;
+
+  for (i = 1; i < argc; i++)
+    {
+      if (argv[i][1] == 0)
+	pd->cstart = argv[i][0];
+      else if (argv[i][0] == '-')
+	{
+	  switch (argv[i][1])
+	    {
+	    case 'r':
+	      pd->flags |= ILCMT_REMOVE_EMPTY_LINES;
+	      break;
+
+	    case 's':
+	      pd->flags |= ILCMT_SQUEEZE_WS;
+	      break;
+
+	    default:
+	      free (pd);
+	      return MU_ERR_PARSE;
+	    }
+	}
+    }
+
   *pret = pd;
   
   return 0;
diff --git a/libmailutils/property/mhprop.c b/libmailutils/property/mhprop.c
index 12b16e9..9aedd22 100644
--- a/libmailutils/property/mhprop.c
+++ b/libmailutils/property/mhprop.c
@@ -100,7 +100,7 @@ _mh_prop_read_stream (mu_header_t *phdr, mu_stream_t stream)
 {
   int rc;
   mu_stream_t flt;
-  const char *argv[3];
+  const char *argv[4];
   mu_off_t size;
   size_t total;
   char *blurb;
@@ -111,7 +111,8 @@ _mh_prop_read_stream (mu_header_t *phdr, mu_stream_t stream)
   
   argv[0] = "INLINE-COMMENT";
   argv[1] = "#";
-  argv[2] = NULL;
+  argv[2] = "-r";
+  argv[3] = NULL;
   rc = mu_filter_create_args (&flt, stream, argv[0], 2, argv,
 			      MU_FILTER_DECODE, MU_STREAM_READ);
   if (rc)
diff --git a/libmailutils/stream/fltstream.c b/libmailutils/stream/fltstream.c
index ad4d0f1..ea08c81 100644
--- a/libmailutils/stream/fltstream.c
+++ b/libmailutils/stream/fltstream.c
@@ -60,7 +60,7 @@ filter_stream_init (struct _mu_filter_stream *fs)
     {
       struct mu_filter_io iobuf;
       memset (&iobuf, 0, sizeof (iobuf));
-      if (fs->xcode (fs->xdata, mu_filter_init, &iobuf) == mu_filter_falure)
+      if (fs->xcode (fs->xdata, mu_filter_init, &iobuf) == mu_filter_failure)
 	return iobuf.errcode;
     }
   return 0;
@@ -182,7 +182,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
 		}
 	      break;
 	  
-	    case mu_filter_falure:
+	    case mu_filter_failure:
 	      return iobuf.errcode;
 	      
 	    case mu_filter_moreinput:
@@ -288,7 +288,7 @@ filter_write_internal (mu_stream_t stream, enum mu_filter_command cmd,
 	    }
 	  break;
 	  
-	case mu_filter_falure:
+	case mu_filter_failure:
 	  return iobuf.errcode;
 	  
 	case mu_filter_moreinput:
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index a3ae2aa..67b62fc 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -68,6 +68,8 @@ TESTSUITE_AT = \
  decode2047.at\
  encode2047.at\
  fromflt.at\
+ hdrflt.at\
+ inline-comment.at\
  list.at\
  mailcap.at\
  prop.at\
diff --git a/libmailutils/tests/fltst.c b/libmailutils/tests/fltst.c
index cc72f2d..a92f1ec 100644
--- a/libmailutils/tests/fltst.c
+++ b/libmailutils/tests/fltst.c
@@ -99,7 +99,7 @@ usage (const char *diag)
     fp = stdout;
 
   fprintf (fp, "%s",
-	   "usage: fltst FILTER {encode|decode} {read|write} [shift=N] [linelen=N] [verbose] [printable] [nl]\n");
+	   "usage: fltst FILTER {encode|decode} {read|write} [shift=N] [linelen=N] [verbose] [printable] [nl] [-- args]\n");
   exit (diag ? 1 : 0);
 }
 
@@ -152,9 +152,17 @@ main (int argc, char * argv [])
 	printable++;
       else if (strcmp (argv[i], "nl") == 0)
 	newline_option++;
+      else if (strcmp (argv[i], "--") == 0)
+	{
+	  argv[i] = fltname;
+	  break;
+	}
       else
 	usage ("wrong option");
     }
+
+  argc -= i;
+  argv += i;
   
   MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0));
   MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
@@ -164,17 +172,21 @@ main (int argc, char * argv [])
   
   if (flags == MU_STREAM_READ)
     {
-      MU_ASSERT (mu_filter_create (&flt, in, fltname, mode,
-				   MU_STREAM_READ|MU_STREAM_SEEK|
-				   MU_STREAM_AUTOCLOSE));
+      MU_ASSERT (mu_filter_create_args (&flt, in, fltname,
+					argc, (const char **)argv,
+					mode,
+					MU_STREAM_READ|MU_STREAM_SEEK|
+					MU_STREAM_AUTOCLOSE));
       if (shift)
 	MU_ASSERT (mu_stream_seek (flt, shift, MU_SEEK_SET, NULL));
       c_copy (out, flt);
     }
   else
     {
-      MU_ASSERT (mu_filter_create (&flt, out, fltname, mode,
-				   MU_STREAM_WRITE));
+      MU_ASSERT (mu_filter_create_args (&flt, out, fltname,
+					argc, (const char **)argv,
+					mode,
+					MU_STREAM_WRITE));
       if (shift)
 	MU_ASSERT (mu_stream_seek (in, shift, MU_SEEK_SET, NULL));
       c_copy (flt, in);
diff --git a/mh/tests/mhl.at b/libmailutils/tests/hdrflt.at
similarity index 58%
copy from mh/tests/mhl.at
copy to libmailutils/tests/hdrflt.at
index c9c99da..aed3c96 100644
--- a/mh/tests/mhl.at
+++ b/libmailutils/tests/hdrflt.at
@@ -14,25 +14,29 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef([MH_KEYWORDS],[mhl])
+AT_SETUP([header filter])
+AT_KEYWORDS([header-filter hdrflt])
 
-MH_CHECK([mhl],[mhl00],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
-mhl -form $abs_top_srcdir/mh/mhl.format Mail/inbox/2
-],
-[0],
-[ -- using template mhl.format --
-Date:    Mon, 29 Jul 2002 22:00:02 +0100
-To:      March Hare  <hare@wonder.land>
+AT_DATA([input],
+[From: gray@gnu.org
+To: root@example.com
+Subject: test
 
-From:    Alice  <alice@wonder.land>
-Subject: Re: Invitation
+Mon beau pays par l'hiver soumis
+Quand reverrons-nous l'hirondelle
+Noire et blanche, noire et blanche
+Quand reverrons-nous l'hirondelle
+Blanche au ventre et noire aux ailes
+])
 
-X-Envelope-Date: Mon Jul 29 22:00:09 2002
-X-Envelope-Sender: alice@wonder.land
+AT_DATA([expout],[dnl
+From: gray@gnu.org
+To: root@example.com
+Subject: test
+])
 
-I don't see any wine
-]) 
 
-m4_popdef[MH_KEYWORDS])
-# End of mhl.at
+AT_CHECK([fltst header decode read < input],[0],[expout])
+AT_CHECK([fltst header decode write < input],[0],[expout])
+
+AT_CLEANUP
\ No newline at end of file
diff --git a/libmailutils/tests/inline-comment.at b/libmailutils/tests/inline-comment.at
new file mode 100644
index 0000000..bfaf492
--- /dev/null
+++ b/libmailutils/tests/inline-comment.at
@@ -0,0 +1,113 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+dnl -------------------------------------------------------------------
+dnl INLINECOM(NAME, [KW = `'], [OPTS = `'], [TEXT], [OUTPUT = `'])
+dnl -------------------------------------------------------------------
+m4_pushdef([INLINECOM],[
+AT_SETUP([inline-comment: $1])
+AT_KEYWORDS([filter inline-comment icmt $2])
+sed 's/\$.*//' > input <<EOT
+$4
+EOT
+sed 's/\$.*//' > expout <<EOT
+$5
+EOT
+
+AT_CHECK([fltst inline-comment decode read $3 < input],
+[0],
+[expout])
+AT_CHECK([fltst inline-comment decode write $3 < input],
+[0],
+[expout])
+AT_CLEANUP
+])
+
+dnl -------------------------------------------------------------------
+
+INLINECOM([default], [icmt00], [],
+[; comment 1
+text 1
+; comment 2
+text 2
+
+text 3
+; comment 3
+],
+[text 1
+text 2
+
+text 3
+])
+
+INLINECOM([change comment starter], [icmt02], [-- %],
+[% comment 1
+text 1
+% comment 2
+text 2
+
+text 3
+% comment 3
+],
+[text 1
+text 2
+
+text 3
+])
+
+INLINECOM([remove empty lines],[icmt03],[-- -r],
+[; comment 1
+text 1
+; comment 2
+; comment 3
+text 2
+
+	text 3
+
+	$
+text 4
+     text 5
+],
+[text 1
+text 2
+	text 3
+text 4
+     text 5[]dnl
+])	
+
+INLINECOM([remove empty lines/squeeze whitespace],[icmt04],[-- -r -s],
+[; comment 1
+text 1
+; comment 2
+; comment 3
+text 2
+
+	text 3
+
+	$
+text 4
+     text 5
+],
+[text 1
+text 2
+ text 3
+text 4
+ text 5[]dnl
+])	
+
+
+m4_popdef([INLINECOM])
+# End of inline-comment.at
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 43806c7..722e839 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -66,4 +66,6 @@ m4_include([encode2047.at])
 m4_include([fromflt.at])
 m4_include([wicket.at])
 m4_include([prop.at])
+m4_include([inline-comment.at])
+m4_include([hdrflt.at])
 
diff --git a/libmu_auth/gsasl.c b/libmu_auth/gsasl.c
index 10b14bf..0ff7e5d 100644
--- a/libmu_auth/gsasl.c
+++ b/libmu_auth/gsasl.c
@@ -82,7 +82,7 @@ _gsasl_encoder (void *xdata,
       if (status)
 	{
 	  flt->gsasl_err = status;
-	  return mu_filter_falure;
+	  return mu_filter_failure;
 	}
     }
     
@@ -141,7 +141,7 @@ _gsasl_decoder (void *xdata,
 	  
 	default:
 	  flt->gsasl_err = status;
-	  return mu_filter_falure;
+	  return mu_filter_failure;
 	}
     }
 
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 5ddf5fd..07bc60c 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -68,7 +68,6 @@ libmh_a_SOURCES= \
  mh_alias_gram.c\
  mh_alias_lex.c\
  mh_argp.c\
- mh_ctx.c\
  mh_getopt.c\
  mh_global.c\
  mh_format.c\
diff --git a/mh/folder.c b/mh/folder.c
index 0df51c3..d38bc4b 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -272,18 +272,15 @@ static void
 read_seq_file (struct folder_info *info, const char *prefix, const char *name)
 {
   char *pname = NULL;
-  mh_context_t *ctx;
+  mu_property_t prop;
   const char *p;
   
   pname = mh_safe_make_file_name (prefix, name);
-  ctx = mh_context_create (pname, 1);
-  mh_context_read (ctx);
+  prop = mh_read_property_file (pname, 1);
   
-  p = mh_context_get_value (ctx, "cur", NULL);
-  if (p)
+  if (mu_property_sget_value (prop, "cur", &p) == 0)
     info->cur = strtoul (p, NULL, 0);
-  free (pname);
-  free (ctx);
+  mu_property_destroy (&prop);
 }
 
 static void
diff --git a/mh/mh.h b/mh/mh.h
index b9b89ef..b2873f3 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -56,6 +56,7 @@
 #include <mailutils/mime.h>
 #include <mailutils/io.h>
 #include <mailutils/property.h>
+#include <mailutils/mh.h>
 
 #include <mu_umaxtostr.h>
 
@@ -228,9 +229,6 @@ struct mh_whatnow_env     /* whatnow shell environment */
 #define DISP_USE 1
 #define DISP_REPLACE 2
 
-typedef int (*mh_context_iterator) (const char *field, const char *value,
-				    void *data);
-
 #define SEQ_PRIVATE 1
 #define SEQ_ZERO    2
 
@@ -246,10 +244,23 @@ mu_message_t mh_file_to_message (const char *folder, const char *file_name);
 mu_message_t mh_stream_to_message (mu_stream_t stream);
 void mh_install (char *name, int automode);
 
-const char *mh_global_profile_get (const char *name, const char *defval);
-int mh_global_profile_set (const char *name, const char *value);
-const char *mh_global_context_get (const char *name, const char *defval);
-int mh_global_context_set (const char *name, const char *value);
+mu_property_t mh_read_property_file (char *name, int ro);
+void mh_property_merge (mu_property_t dst, mu_property_t src);
+
+#define mh_global_profile_get(name, defval) \
+  mu_mhprop_get_value (mu_mh_profile, name, defval)
+#define mh_global_profile_set(name, value) \
+  mu_property_set_value (mu_mh_profile, name, value, 1))
+#define mh_global_profile_iterate(fp, data) \
+  mu_mhprop_iterate (mu_mh_profile, fp, data)
+
+#define mh_global_context_get(name, defval) \
+  mu_mhprop_get_value (mu_mh_context, name, defval)
+#define mh_global_context_set(name, value) \
+  mu_property_set_value (mu_mh_context, name, value, 1)
+#define mh_global_context_iterate(fp, data) \
+  mu_mhprop_iterate (mu_mh_context, fp, data)
+
 const char *mh_set_current_folder (const char *val);
 const char *mh_current_folder (void);
 
@@ -259,12 +270,10 @@ const char *mh_global_sequences_get (mu_mailbox_t mbox,
 void mh_global_sequences_set (mu_mailbox_t mbox,
 			      const char *name, const char *value);
 void mh_global_sequences_iterate (mu_mailbox_t mbox,
-				  mh_context_iterator fp, void *data);
+				  mu_mhprop_iterator_t fp, void *data);
 void mh_global_sequences_drop (mu_mailbox_t mbox);
 
 void mh_global_save_state (void);
-int mh_global_profile_iterate (mh_context_iterator fp, void *data);
-int mh_global_context_iterate (mh_context_iterator fp, void *data);
 
 int mh_interactive_mode_p (void);
 int mh_getyn (const char *fmt, ...) MU_PRINTFLIKE(1,2);
@@ -287,17 +296,6 @@ void mh_err_memory (int fatal);
 FILE *mh_audit_open (char *name, mu_mailbox_t mbox);
 void mh_audit_close (FILE *fp);
 
-mh_context_t *mh_context_create (const char *name, int copy);
-int mh_context_read (mh_context_t *ctx);
-int mh_context_write (mh_context_t *ctx);
-const char *mh_context_get_value (mh_context_t *ctx, const char *name,
-				  const char *defval);
-int mh_context_set_value (mh_context_t *ctx, const char *name,
-			  const char *value);
-int mh_context_iterate (mh_context_t *ctx, mh_context_iterator fp, void *data);
-void mh_context_destroy (mh_context_t **pctx);
-void mh_context_merge (mh_context_t *dst, mh_context_t *src);
-
 int mh_message_number (mu_message_t msg, size_t *pnum);
 
 mu_mailbox_t mh_open_folder (const char *folder, int create);
diff --git a/mh/mh_ctx.c b/mh/mh_ctx.c
deleted file mode 100644
index ca497f2..0000000
--- a/mh/mh_ctx.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009,
-   2010 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
-
-/* MH context functions. */
-  
-#include <mh.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-mh_context_t *
-mh_context_create (const char *name, int copy)
-{
-  mh_context_t *ctx;
-  ctx = malloc (sizeof (*ctx));
-  if (!ctx)
-    mh_err_memory (1);
-  if (copy)
-    ctx->name = name;
-  else
-    {
-      ctx->name = strdup (name);
-      if (!ctx->name)
-        mh_err_memory (1);
-    }
-  ctx->header = NULL;
-  return ctx;
-}
-
-void
-mh_context_destroy (mh_context_t **pctx)
-{
-  mh_context_t *ctx = *pctx;
-  
-  free ((char*) ctx->name);
-  if (ctx->header)
-    mu_header_destroy (&ctx->header);
-  free (ctx);
-  *pctx = NULL;
-}
-
-void
-mh_context_merge (mh_context_t *dst, mh_context_t *src)
-{
-  if (!dst->header)
-    {
-      dst->header = src->header;
-      src->header = NULL;
-    }
-  else
-    {
-      size_t i, count;
-      
-      mu_header_get_field_count (src->header, &count);
-      for (i = 1; i <= count; i++)
-	{
-	  const char *name = NULL;
-	  const char *value = NULL;
-	  
-	  mu_header_sget_field_name (src->header, i, &name);
-	  mu_header_sget_field_value (src->header, i, &value);
-	  mu_header_set_value (dst->header, name, value, 1);
-	}
-    }
-}
-
-int 
-mh_context_read (mh_context_t *ctx)
-{
-  int rc;
-  char *blurb, *p;
-  mu_stream_t stream;
-  mu_off_t stream_size;
-  char *buf = NULL;
-  size_t size = 0, n;
-  
-  if (!ctx)
-    return MU_ERR_OUT_NULL;
-  
-  rc = mu_file_stream_create (&stream, ctx->name, MU_STREAM_READ);
-  if (rc)
-    return rc;
-
-  rc = mu_stream_size (stream, &stream_size);
-  if (rc)
-    {
-      mu_stream_destroy (&stream);
-      return rc;
-    }
-
-  blurb = malloc (stream_size + 1);
-  if (!blurb)
-    {
-      mu_stream_destroy (&stream);
-      return ENOMEM;
-    }
-  
-  p = blurb;
-  while (mu_stream_getline (stream, &buf, &size, &n) == 0 && n > 0)
-    {
-      char *q = mu_str_skip_class (buf, MU_CTYPE_SPACE);
-      if (!*q || *q == '#')
-	continue;
-      for (q = buf; *q;)
-	*p++ = *q++;
-    }
-  mu_stream_destroy (&stream);
-  rc = mu_header_create (&ctx->header, blurb, p - blurb);
-  free (blurb);
-
-  return rc;
-}
-
-int 
-mh_context_write (mh_context_t *ctx)
-{
-  int rc;
-  mu_stream_t instream, outstream;
-  mu_off_t size;
-  
-  if (!ctx)
-    return MU_ERR_OUT_NULL;
-
-  rc = mu_file_stream_create (&outstream, ctx->name,
-			      MU_STREAM_WRITE|MU_STREAM_CREAT);
-  if (rc)
-    {
-      mu_error (_("cannot open context file %s for writing: %s"),
-		ctx->name, mu_strerror (rc));
-      return MU_ERR_FAILURE;
-    }
-  
-  mu_header_get_streamref (ctx->header, &instream);
-  rc = mu_stream_copy (outstream, instream, 0, &size);
-  if (rc)
-    {
-      mu_error (_("error writing to context file %s: %s"),
-		ctx->name, mu_strerror (rc));
-      return MU_ERR_FAILURE;
-    }
-  else
-    rc = mu_stream_truncate (outstream, size);
-  mu_stream_destroy (&instream);
-  mu_stream_destroy (&outstream);
-  return 0;
-}
-
-const char *
-mh_context_get_value (mh_context_t *ctx, const char *name, const char *defval)
-{
-  const char *p;
-
-  if (!ctx || mu_header_sget_value (ctx->header, name, &p))
-    p = defval; 
-  return p;
-}
-
-int
-mh_context_set_value (mh_context_t *ctx, const char *name, const char *value)
-{
-  if (!ctx)
-    return EINVAL;
-  if (!ctx->header)
-    {
-      int rc;
-      if ((rc = mu_header_create (&ctx->header, NULL, 0)) != 0)
-	{
-	  mu_error (_("cannot create context %s: %s"),
-		    ctx->name,
-		    mu_strerror (rc));
-	  return 1;
-	}
-    }
-  return mu_header_set_value (ctx->header, name, value, 1);
-}
-
-int
-mh_context_iterate (mh_context_t *ctx, mh_context_iterator fp, void *data)
-{
-  size_t i, nfields;
-  int rc = 0;
-  
-  if (!ctx)
-    return EINVAL;
-  if (!ctx->header)
-    return 0;
-  rc = mu_header_get_field_count (ctx->header, &nfields);
-  if (rc)
-    {
-      mu_error (_("cannot obtain field count for context %s"), ctx->name);
-      return rc;
-    }
-  
-  for (i = 1; i <= nfields && rc == 0; i++)
-    {
-      const char *name, *value;
-      
-      rc = mu_header_sget_field_name (ctx->header, i, &name);
-      if (rc)
-	{
-	  mu_error (_("cannot obtain field name for context %s:%d: %s"),
-		    ctx->name,i,mu_strerror (rc));
-	  break;
-	}
-      
-      rc = mu_header_sget_field_value (ctx->header, i, &value);
-      if (rc)
-	{
-	  mu_error (_("cannot obtain field value for context %s:%d: %s"),
-		    ctx->name,i,mu_strerror (rc));
-	  break;
-	}
-      
-      rc = fp (name, value, data);
-    }
-
-  return rc;
-}
diff --git a/mh/mh_global.c b/mh/mh_global.c
index 2294477..7de44b8 100644
--- a/mh/mh_global.c
+++ b/mh/mh_global.c
@@ -20,29 +20,70 @@
 #include <mh.h>
 
 static const char *current_folder = NULL;
-mh_context_t *context;
-mh_context_t *profile;
 int rcpt_mask = RCPT_DEFAULT;
 int mh_auto_install = 1;
 
-/* Global profile */
+mu_property_t
+mh_read_property_file (char *name, int ro)
+{
+  mu_property_t prop;
+  struct mu_mh_prop *mhprop;
+  int rc;
+  
+  mhprop = xzalloc (sizeof (mhprop[0]));
+  mhprop->filename = name;
+  mhprop->ro = ro;
+  rc = mu_property_create_init (&prop, mu_mh_property_init, mhprop);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_property_create_init", name, rc);
+      exit (1);
+    }
+  return prop;
+}
 
-const char *
-mh_global_profile_get (const char *name, const char *defval)
+static int
+prop_merger (const char *field, const char *value, void *data)
 {
-  return mh_context_get_value (profile, name, defval);
+  mu_property_t dst;
+  return mu_property_set_value (dst, field, value, 1);
 }
 
-int
-mh_global_profile_set (const char *name, const char *value)
+void
+mh_property_merge (mu_property_t dst, mu_property_t src)
 {
-  return mh_context_set_value (profile, name, value);
+  int rc;
+  
+  if (!src)
+    return;
+  rc = mu_mhprop_iterate (src, prop_merger, dst);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mhprop_iterate", NULL, rc);
+      exit (1);
+    }
 }
+  
+/* Global profile */
 
-int
-mh_global_profile_iterate (mh_context_iterator fp, void *data)
+void
+_mh_init_global_context ()
 {
-  return mh_context_iterate (profile, fp, data);
+  char *p, *ctx_name;
+  
+  if (mu_mh_context)
+    return;
+  p = getenv ("CONTEXT");
+  if (!p)
+    p = MH_CONTEXT_FILE;
+  ctx_name = mh_expand_name (NULL, p, 0);
+
+  mu_mh_context = mh_read_property_file (ctx_name, 0);
+  
+  if (!current_folder)
+    current_folder = mh_global_context_get ("Current-Folder",
+					    mh_global_profile_get ("Inbox",
+								   "inbox"));
 }
 
 void
@@ -66,8 +107,7 @@ mh_read_profile ()
   if (mh_auto_install && access (p, R_OK))
     mh_install (p, 1);
 
-  profile = mh_context_create (p, 1);
-  mh_context_read (profile);
+  mu_mh_profile = mh_read_property_file (p, 0);
 
   mu_set_folder_directory (mh_get_dir ());
 
@@ -75,55 +115,15 @@ mh_read_profile ()
   fallback = mh_global_profile_get ("Decode-Fallback", NULL);
   if (fallback && mu_set_default_fallback (fallback))
     mu_error (_("Incorrect value for decode-fallback"));
-}
-
-/* Global context */
 
-void
-_mh_init_global_context ()
-{
-  char *p, *ctx_name;
-  
-  if (context)
-    return;
-  p = getenv ("CONTEXT");
-  if (!p)
-    p = MH_CONTEXT_FILE;
-  ctx_name = mh_expand_name (NULL, p, 0);
-  context = mh_context_create (ctx_name, 1);
-  mh_context_read (context);
-  
-  if (!current_folder)
-    current_folder = mh_context_get_value (context, "Current-Folder",
-					   mh_global_profile_get ("Inbox",
-							          "inbox"));
-}
-
-const char *
-mh_global_context_get (const char *name, const char *defval)
-{
-  _mh_init_global_context ();
-  return mh_context_get_value (context, name, defval);
-}
-
-int
-mh_global_context_set (const char *name, const char *value)
-{
   _mh_init_global_context ();
-  return mh_context_set_value (context, name, value);
 }
 
-int
-mh_global_context_iterate (mh_context_iterator fp, void *data)
-{
-  _mh_init_global_context ();
-  return mh_context_iterate (context, fp, data);
-}
+/* Global context */
 
 const char *
 mh_current_folder ()
 {
-  _mh_init_global_context ();
   return mh_global_context_get ("Current-Folder",
 				mh_global_profile_get ("Inbox", "inbox"));
 }
@@ -131,7 +131,13 @@ mh_current_folder ()
 const char *
 mh_set_current_folder (const char *val)
 {
-  mh_global_context_set ("Current-Folder", val);
+  int rc = mh_global_context_set ("Current-Folder", val);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mh_global_context_set",
+		       "Current-Folder", rc);
+      exit (1);
+    }
   current_folder = mh_current_folder ();
   return current_folder;
 }
@@ -192,10 +198,9 @@ mh_global_sequences_set (mu_mailbox_t mbox, const char *name,
     }
 }
 
-/* FIXME: Rewrite using mu_mhprop_iterate */
 void
 mh_global_sequences_iterate (mu_mailbox_t mbox,
-			     mh_context_iterator fp, void *data)
+                             mu_mhprop_iterator_t fp, void *data)
 {
   int rc;
   mu_iterator_t itr;
@@ -207,16 +212,7 @@ mh_global_sequences_iterate (mu_mailbox_t mbox,
       mu_diag_funcall (MU_DIAG_ERROR, "mu_property_get_iterator", NULL, rc);
       exit (1);
     }
-  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
-       mu_iterator_next (itr))
-    {
-      const char *name, *val;
-      
-      mu_iterator_current_kv (itr, (const void **)&name, (void**)&val);
-      if (fp (name, val, data))
-	break;
-    }
-  mu_iterator_destroy (&itr);
+  mu_mhprop_iterate (prop, fp, data);
 }
 
 /* Global state */
@@ -224,6 +220,15 @@ mh_global_sequences_iterate (mu_mailbox_t mbox,
 void
 mh_global_save_state ()
 {
-  mh_context_set_value (context, "Current-Folder", current_folder);
-  mh_context_write (context);
+  int rc;
+  
+  mh_global_context_set ("Current-Folder", current_folder);
+  rc = mu_property_save (mu_mh_context);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_save", "context", rc);
+      exit (1);
+    }
 }
+
+
diff --git a/mh/mh_whom.c b/mh/mh_whom.c
index 4b70b25..8523a16 100644
--- a/mh/mh_whom.c
+++ b/mh/mh_whom.c
@@ -197,31 +197,101 @@ _print_local_recipient (void *item, void *data)
   (*count)++;
   return 0;
 }
-		  
+
+static mu_header_t
+read_header (mu_stream_t stream)
+{
+  int rc;
+  mu_stream_t flt;
+  mu_off_t size;
+  size_t total;
+  char *blurb;
+  mu_header_t hdr;
+  
+  rc = mu_stream_size (stream, &size);
+  if (rc)
+    {
+      mu_error (_("cannot get stream size: %s"), mu_strerror (rc));
+      exit (1);
+    }
+  
+  rc = mu_filter_create (&flt, stream, "HEADER",
+			 MU_FILTER_DECODE, MU_STREAM_READ);
+  if (rc)
+    {
+      mu_error (_("cannot open filter stream: %s"), mu_strerror (rc));
+      exit (1);
+    }
+
+  blurb = xmalloc (size + 1);
+
+  total = 0;
+  while (1)
+    {
+      size_t n;
+      
+      rc = mu_stream_read (flt, blurb + total, size - total, &n);
+      if (rc)
+	break;
+      if (n == 0)
+	break;
+      total += n;
+    }
+
+  mu_stream_destroy (&flt);
+  if (rc)
+    {
+      free (blurb);
+      mu_error (_("read error: %s"), mu_strerror (rc));
+      exit (1);
+    }
+
+  rc = mu_header_create (&hdr, blurb, total);
+  free (blurb);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_header_create", NULL, rc);
+      exit (1);
+    }
+  return hdr;
+}
+
 int
 mh_whom (const char *filename, int check)
 {
   int rc = 0;
-  mh_context_t *ctx;
 
-  mh_read_aliases ();
-  ctx = mh_context_create (filename, 1);
-  if ((rc = mh_context_read (ctx)))
+  if (access (filename, R_OK))
     {
-      if (rc == ENOENT)
-	mu_error ("%s: %s", filename, mu_strerror (rc));
-      else
-	mu_error ("%s: %s (%s)", filename, _("malformed message"),
-		  mu_strerror (rc));
+      mu_error ("%s: %s", filename, mu_strerror (errno));
       rc = -1;
     }
   else
     {
       size_t count = 0;
-      
-      scan_addrs (mh_context_get_value (ctx, MU_HEADER_TO, NULL), 0);
-      scan_addrs (mh_context_get_value (ctx, MU_HEADER_CC, NULL), 0);
-      scan_addrs (mh_context_get_value (ctx, MU_HEADER_BCC, NULL), 1);
+      mu_header_t hdr;
+      mu_stream_t str;
+      int rc;
+      const char *val;
+
+      rc = mu_file_stream_create (&str, filename, MU_STREAM_READ);
+      if (rc)
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_file_stream_create",
+			   filename, rc);
+	  exit (1);
+	}
+      hdr = read_header (str);
+      mu_stream_unref (str);
+
+      mh_read_aliases ();
+
+      if (mu_header_sget_value (hdr, MU_HEADER_TO, &val) == 0)
+	scan_addrs (val, 0);
+      if (mu_header_sget_value (hdr, MU_HEADER_CC, &val) == 0)
+	scan_addrs (val, 0);
+      if (mu_header_sget_value (hdr, MU_HEADER_BCC, &val) == 0)
+	scan_addrs (val, 1);
 
       if (local_rcp)
 	{
@@ -240,8 +310,8 @@ mh_whom (const char *filename, int check)
 	  mu_error(_("no recipients"));
 	  rc = -1;
 	}
+      mu_header_destroy (&hdr);
     }
-  free (ctx);
   destroy_addrs (&network_rcp);
   destroy_addrs (&local_rcp);
   return rc;
diff --git a/mh/send.c b/mh/send.c
index d717bb9..f4b799f 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -283,7 +283,7 @@ struct list_elt           /* Element of the send list */
 };
 
 static mu_list_t mesg_list;
-static mh_context_t *mts_profile;
+static mu_property_t mts_profile;
 
 int
 check_file (char *name)
@@ -313,36 +313,42 @@ check_file (char *name)
 void
 read_mts_profile ()
 {
+  char *name;
   const char *p;
   char *hostname = NULL;
   int rc;
-  mh_context_t *local_profile;
+  mu_property_t local_profile;
 
-  p = mh_expand_name (MHLIBDIR, "mtstailor", 0);
-  mts_profile = mh_context_create (p, 1);
-  mh_context_read (mts_profile);
+  name = mh_expand_name (MHLIBDIR, "mtstailor", 0);
+  mts_profile = mh_read_property_file (name, 1);
 
-  p = mu_tilde_expansion ("~/.mtstailor", "/", NULL);
-  local_profile = mh_context_create (p, 1);
-  if (mh_context_read (local_profile) == 0)
-    mh_context_merge (mts_profile, local_profile);
-  mh_context_destroy (&local_profile);
+  name = mu_tilde_expansion ("~/.mtstailor", "/", NULL);
+  local_profile = mh_read_property_file (name, 1);
 
-  if ((p = mh_context_get_value (mts_profile, "localname", NULL)))
+  mh_property_merge (mts_profile, local_profile);
+  mu_property_destroy (&local_profile);
+
+  rc = mu_property_aget_value (mts_profile, "localname", &hostname);
+  if (rc == MU_ERR_NOENT)
+    {
+      rc = mu_get_host_name (&hostname);
+      if (rc)
+	{
+	  mu_error (_("cannot get system host name: %s"), mu_strerror (rc));
+	  exit (1);
+	}
+    }
+  else
     {
-      hostname = xstrdup (p);
-      mu_set_user_email_domain (p);
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_aget_value", "localname", rc);
+      exit (1);
     }
-  else if ((rc = mu_get_host_name (&hostname)))
-    mu_error (_("cannot get system host name: %s"), mu_strerror (rc));
 
-  if ((p = mh_context_get_value (mts_profile, "localdomain", NULL)))
+  rc = mu_property_sget_value (mts_profile, "localdomain", &p);
+  if (rc == 0)
     {
       char *newdomain;
 
-      if (!hostname)
-	exit (1);
-      
       newdomain = xmalloc (strlen (hostname) + 1 + strlen (p) + 1);
       strcpy (newdomain, hostname);
       strcat (newdomain, ".");
@@ -355,8 +361,15 @@ read_mts_profile ()
 	  exit (1);
 	}
     }
-
-  if ((p = mh_context_get_value (mts_profile, "username", NULL)))
+  else if (rc != MU_ERR_NOENT)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_sget_value",
+		       "localdomain", rc);
+      exit (1);
+    }
+  
+  rc = mu_property_sget_value (mts_profile, "username", &p);
+  if (rc == 0)
     {
       size_t len;
       const char *domain;
@@ -385,15 +398,21 @@ read_mts_profile ()
       
       free (newemail);
     }
+  else if (rc != MU_ERR_NOENT)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_profile_sget_value",
+		       "username", rc);
+      exit (1);
+    }
 }
 
 
 mu_mailer_t
 open_mailer ()
 {
-  const char *url = mh_context_get_value (mts_profile,
-					  "url",
-					  "sendmail:/usr/sbin/sendmail");
+  const char *url = mu_mhprop_get_value (mts_profile,
+					 "url",
+					 "sendmail:/usr/sbin/sendmail");
   mu_mailer_t mailer;
   int status;
     
@@ -667,8 +686,8 @@ _action_send (void *item, void *data)
 
       if (mu_header_get_value (hdr, MU_HEADER_X_MAILER, NULL, 0, &n))
 	{
-	  const char *p = mh_context_get_value (mts_profile,
-						"x-mailer", "yes");
+	  const char *p = mu_mhprop_get_value (mts_profile,
+					       "x-mailer", "yes");
 
 	  if (!strcmp (p, "yes"))
 	    mu_header_set_value (hdr, MU_HEADER_X_MAILER,
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 001f754..d1ecf45 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -165,6 +165,7 @@ mh/forw.c
 mh/inc.c
 mh/install-mh.c
 mh/mark.c
+mh/mboxprop.c
 mh/mh_argp.c
 mh/mh_ctx.c
 mh/mh_fmtgram.y


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Nov 21 12:21:52 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PKDbr-0007KP-Vl
	for mharc-commit-mailutils@gnu.org; Sun, 21 Nov 2010 12:21:52 -0500
Received: from [140.186.70.92] (port=45349 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PKDbn-0007Im-RM
	for commit-mailutils@gnu.org; Sun, 21 Nov 2010 12:21:50 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKDbl-0000ny-GX
	for commit-mailutils@gnu.org; Sun, 21 Nov 2010 12:21:47 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:57066
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKDbl-0000nu-ED
	for commit-mailutils@gnu.org; Sun, 21 Nov 2010 12:21:45 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKDbk-0001NO-VV
	for commit-mailutils@gnu.org; Sun, 21 Nov 2010 17:21:45 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKDbN-0003dM-9l
	for commit-mailutils@gnu.org; Sun, 21 Nov 2010 17:21:44 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 597404315ba308889ea2776c56c184d1eb9b02fc
X-Git-Newrev: e6927c46013d391242d76b63cdb7b044d9ba8065
Message-Id: <E1PKDbN-0003dM-9l@vcs-noshell.in.savannah.gnu.org>
Date: Sun, 21 Nov 2010 17:21:22 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-208-ge6927c4
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 21 Nov 2010 17:21:50 -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=e6927c46013d391242d76b63cdb7b044d9ba8065

The branch, master has been updated
       via  e6927c46013d391242d76b63cdb7b044d9ba8065 (commit)
      from  597404315ba308889ea2776c56c184d1eb9b02fc (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 e6927c46013d391242d76b63cdb7b044d9ba8065
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Nov 21 19:14:06 2010 +0200

    mh: Fix compatibility issues in the draftfolder facility. Implement whatnowproc.
    
    * mh/whatnowenv.c: New source.
    * mh/Makefile.am (libmh_a_SOURCES): Add whatnowenv.c
    * mh/TODO: Update.
    * mh/comp.c: Implement draftfolder, whatnowproc and the -use option.
    * mh/forw.c: Likewise.
    * mh/repl.c: Likewise.
    * mh/compcommon.c (check_draft_disposition): Fix typo.
    * mh/mh.h (mh_whatnow_env) <draftfolder>: Remove.
    <mbox>: New member.
    (mh_whatnowproc): New proto.
    (mh_whatnow_env_from_environ)
    (mh_whatnow_env_to_environ): New proto.
    * mh/mh_global.c (prop_merger): Bugfix: initialize dst.
    * mh/mh_init.c (mh_draft_message): Update cur msg.
    * mh/mh_whatnow.c (mh_whatnowproc): New function.
    * mh/whatnow.c (opt_handler): Do not read Draft-Folder variable.
    (main): Initialize data from the environment.

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

Summary of changes:
 mh/Makefile.am  |    3 +-
 mh/TODO         |    6 +-
 mh/comp.c       |   82 +++++++++++++++++++++++--------
 mh/compcommon.c |    2 +-
 mh/forw.c       |   26 ++++++----
 mh/mh.h         |    7 ++-
 mh/mh_global.c  |    2 +-
 mh/mh_init.c    |    4 ++
 mh/mh_whatnow.c |   78 ++++++++++++++++++++++++++++-
 mh/repl.c       |   30 +++++++-----
 mh/send.c       |   25 +++++++++-
 mh/whatnow.c    |   20 +++-----
 mh/whatnowenv.c |  147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 13 files changed, 367 insertions(+), 65 deletions(-)
 create mode 100644 mh/whatnowenv.c

diff --git a/mh/Makefile.am b/mh/Makefile.am
index 07bc60c..01dbdd0 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -78,7 +78,8 @@ libmh_a_SOURCES= \
  mh_sequence.c\
  mh_stream.c\
  mh_whatnow.c\
- mh_whom.c
+ mh_whom.c\
+ whatnowenv.c
 noinst_HEADERS = mh.h mh_alias.h mh_format.h mh_getopt.h
 
 LISPSRC = mailutils-mh.el
diff --git a/mh/TODO b/mh/TODO
index ba6b410..7bc3a40 100644
--- a/mh/TODO
+++ b/mh/TODO
@@ -19,9 +19,9 @@ State	Nice	Utility		Comments
 -------------------------------------------
 +	-20	scan
 +	-20	inc
-*	-20	repl		--inplace,--whatnowproc
-+	-20	comp		Interactive prompting.
-*	-20	forw		--inplace,--whatnowproc
+*	-20	repl		--inplace
++	-20	comp		
+*	-20	forw		--inplace
 *	-20	send		--alias,--filter,--format,--forward,--mime,
 				--width
 *	-20	refile		--link copies messages; rmmproc ignored.
diff --git a/mh/comp.c b/mh/comp.c
index 4def4f8..b882326 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -47,9 +47,9 @@ static struct argp_option options[] = {
   {"form",          ARG_FORM, N_("FILE"), 0,
    N_("read format from given file")},
   {"whatnowproc",   ARG_WHATNOWPROC, N_("PROG"), 0,
-   N_("* set the replacement for whatnow program")},
+   N_("set the replacement for whatnow program")},
   {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
-   N_("* ignore whatnowproc variable. Use standard `whatnow' shell instead.")},
+   N_("ignore whatnowproc variable. Use standard `whatnow' shell instead.")},
   {"use",           ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL,
    N_("use draft file preserved after the last session") },
   {"nouse",         ARG_NOUSE, NULL, OPTION_HIDDEN, ""},
@@ -68,15 +68,18 @@ struct mh_option mh_option[] = {
   { "noedit" },
   { "whatnowproc",   MH_OPT_ARG, "program" },
   { "nowhatnowproc" },
+  { "use" },
   { NULL }
 };
 
 struct mh_whatnow_env wh_env = { 0 };
-const char *formfile;
 static int initial_edit = 1;
+static const char *whatnowproc;
+const char *formfile;
 static int build_only = 0; /* --build flag */
 static int use_draft = 0;  /* --use flag */
 static char *draftmessage = "new";
+static const char *draftfolder = NULL;
 
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
@@ -84,8 +87,9 @@ opt_handler (int key, char *arg, struct argp_state *state)
   switch (key)
     {
     case ARGP_KEY_INIT:
-      wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
-						  mu_folder_directory ());
+      draftfolder = mh_global_profile_get ("Draft-Folder",
+					   mu_folder_directory ());
+      whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
       break;
 
     case ARG_BUILD:
@@ -93,7 +97,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_DRAFTFOLDER:
-      wh_env.draftfolder = arg;
+      draftfolder = arg;
       break;
       
     case ARG_EDITOR:
@@ -126,7 +130,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 	
     case ARG_NODRAFTFOLDER:
-      wh_env.draftfolder = NULL;
+      draftfolder = NULL;
       break;
 
     case ARG_NOEDIT:
@@ -134,8 +138,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_WHATNOWPROC:
+      whatnowproc = arg;
+      break;
+
     case ARG_NOWHATNOWPROC:
-      mh_opt_notimpl ("-[no]whatnowproc");
+      whatnowproc = NULL;
       break;
 
     default:
@@ -143,7 +150,8 @@ opt_handler (int key, char *arg, struct argp_state *state)
     }
   return 0;
 }
-  
+
+/* Copy Nth message from mailbox MBOX to FILE. */
 int
 copy_message (mu_mailbox_t mbox, size_t n, const char *file)
 {
@@ -188,16 +196,48 @@ main (int argc, char **argv)
   mh_argp_init ();
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, &index);
-
-  if (build_only || !wh_env.draftfolder)
-    wh_env.file = mh_expand_name (NULL, "draft", 0);
-  else if (wh_env.draftfolder)
+  
+  if (wh_env.draftfile)
+    {
+      if (build_only)
+	{
+	  mu_error (_("--build and --file cannot be used together"));
+	  exit (1);
+	}
+    }
+  else
     {
-      if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file))
-	return 1;
+      if (build_only || !draftfolder)
+	wh_env.file = mh_expand_name (NULL, "draft", 0);
+      else if (draftfolder)
+	{
+	  /* Comp accepts a `file', and it will, if given
+	     `-draftfolder +folder'  treat this arguments  as `msg'. */
+	  if (index < argc)
+	    {
+	      mh_msgset_t msgset;
+	      mu_mailbox_t mbox;
+	      
+	      mbox = mh_open_folder (draftfolder, 1);
+	      mh_msgset_parse (mbox, &msgset, argc - index, argv + index,
+			       "new");
+	      mu_mailbox_destroy (&mbox);
+	      if (msgset.count != 1)
+		{
+		  mu_error (_("only one message at a time!"));
+		  return 1;
+		}
+	      draftmessage = mu_umaxtostr (0, msgset.list[0]);
+	      mh_msgset_free (&msgset);
+	      index = argc;
+	    }
+	  if (mh_draft_message (draftfolder, draftmessage,
+				&wh_env.file))
+	    return 1;
+	}
+      wh_env.draftfile = wh_env.file;
     }
-  wh_env.draftfile = wh_env.file;
-
+  
   switch (check_draft_disposition (&wh_env, use_draft))
     {
     case DISP_QUIT:
@@ -211,8 +251,8 @@ main (int argc, char **argv)
   
       if (index < argc)
 	{
-	  static mh_msgset_t msgset;
-	  static mu_mailbox_t mbox;
+	  mh_msgset_t msgset;
+	  mu_mailbox_t mbox;
 	  
 	  mbox = mh_open_folder (mh_current_folder (), 0);
 	  mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
@@ -222,6 +262,8 @@ main (int argc, char **argv)
 	      return 1;
 	    }
 	  copy_message (mbox, msgset.list[0], wh_env.file);
+	  mu_mailbox_destroy (&mbox);
+	  mh_msgset_free (&msgset);
 	}
       else
 	mh_comp_draft (formfile, "components", wh_env.file);
@@ -231,5 +273,5 @@ main (int argc, char **argv)
   if (build_only)
     return 0;
 
-  return mh_whatnow (&wh_env, initial_edit);
+  return mh_whatnowproc (&wh_env, initial_edit, whatnowproc);
 }
diff --git a/mh/compcommon.c b/mh/compcommon.c
index f277f59..83890c6 100644
--- a/mh/compcommon.c
+++ b/mh/compcommon.c
@@ -90,7 +90,7 @@ check_draft_disposition (struct mh_whatnow_env *wh, int use_draft)
       else
 	{
 	  printf (ngettext ("Draft \"%s\" exists (%s byte).\n",
-                            "Draft \"%s\" exists (%su bytes).\n",
+                            "Draft \"%s\" exists (%s bytes).\n",
                             (unsigned long) st.st_size),
 		  wh->draftfile, mu_umaxtostr (0, st.st_size));
 	  disp = mh_disposition (wh->draftfile);
diff --git a/mh/forw.c b/mh/forw.c
index 639706b..a41c968 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -60,9 +60,9 @@ static struct argp_option options[] = {
   {"nomime",        ARG_NOMIME,        NULL, OPTION_HIDDEN, "" },
   {"width", ARG_WIDTH, N_("NUMBER"), 0, N_("Set output width")},
   {"whatnowproc",   ARG_WHATNOWPROC,   N_("PROG"), 0,
-   N_("* set the replacement for whatnow program")},
+   N_("set the replacement for whatnow program")},
   {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
-   N_("* ignore whatnowproc variable, use standard `whatnow' shell instead")},
+   N_("ignore whatnowproc variable, use standard `whatnow' shell instead")},
   {"use",           ARG_USE,           N_("BOOL"), OPTION_ARG_OPTIONAL,
    N_("use draft file preserved after the last session") },
   {"nouse",         ARG_NOUSE,         N_("BOOL"), OPTION_HIDDEN, "" },
@@ -98,6 +98,7 @@ enum encap_type {
 static char *formfile;
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
+static const char *whatnowproc;
 static char *mhl_filter = NULL; /* --filter flag */
 static int build_only = 0;      /* --build flag */
 static int annotate = 0;        /* --annotate flag */
@@ -106,6 +107,7 @@ static enum encap_type encap = encap_clear; /* controlled by --format, --form
 static int use_draft = 0;       /* --use flag */
 static int width = 80;          /* --width flag */
 static char *draftmessage = "new";
+static const char *draftfolder = NULL;
 
 static mh_msgset_t msgset;
 static mu_mailbox_t mbox;
@@ -116,8 +118,9 @@ opt_handler (int key, char *arg, struct argp_state *state)
   switch (key)
     {
     case ARGP_KEY_INIT:
-      wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
-                                                   mu_folder_directory ());
+      draftfolder = mh_global_profile_get ("Draft-Folder",
+					   mu_folder_directory ());
+      whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
       break;
 
     case ARG_ANNOTATE:
@@ -129,11 +132,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 
     case ARG_DRAFTFOLDER:
-      wh_env.draftfolder = arg;
+      draftfolder = arg;
       break;
 
     case ARG_NODRAFTFOLDER:
-      wh_env.draftfolder = NULL;
+      draftfolder = NULL;
       break;
       
     case ARG_DRAFTMESSAGE:
@@ -202,10 +205,13 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 
     case ARG_WHATNOWPROC:
+      whatnowproc = arg;
+      break;
+
     case ARG_NOWHATNOWPROC:
-      mh_opt_notimpl ("-[no]whatnowproc");
+      whatnowproc = NULL;
       break;
- 
+
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -428,7 +434,7 @@ main (int argc, char **argv)
   mbox = mh_open_folder (mh_current_folder (), 0);
   mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
   
-  if (build_only || !wh_env.draftfolder)
+  if (build_only || !draftfolder)
     wh_env.file = mh_expand_name (NULL, "draft", 0);
   else 
     {
@@ -460,7 +466,7 @@ main (int argc, char **argv)
       return 0;
     }
   
-  rc = mh_whatnow (&wh_env, initial_edit);
+  rc = mh_whatnowproc (&wh_env, initial_edit, whatnowproc);
 
   mu_mailbox_sync (mbox);
   mu_mailbox_close (mbox);
diff --git a/mh/mh.h b/mh/mh.h
index b2873f3..8e658d7 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -218,11 +218,11 @@ struct mh_whatnow_env     /* whatnow shell environment */
   char *file;             /* The file being processed */
   char *msg;              /* File name of the original message (if any) */
   char *draftfile;        /* File to preserve the draft into */
-  const char *draftfolder;
   const char *editor;
   char *prompt;
   char *anno_field;       /* Annotate field to be used */
   mu_list_t anno_list;    /* List of messages (mu_message_t) to annotate */
+  mu_mailbox_t mbox;
 };
 
 #define DISP_QUIT 0
@@ -330,6 +330,9 @@ int mh_draft_message (const char *name, const char *msgspec, char **pname);
      
 int mh_spawnp (const char *prog, const char *file);
 int mh_whatnow (struct mh_whatnow_env *wh, int initial_edit);
+int mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit,
+		    const char *prog);
+
 int mh_disposition (const char *filename);
 int mh_usedraft (const char *filename);
 int mh_file_copy (const char *from, const char *to);
@@ -381,3 +384,5 @@ char *mh_safe_make_file_name (const char *dir, const char *file);
 void mh_mailbox_get_cur (mu_mailbox_t mbox, size_t *pcur);
 void mh_mailbox_set_cur (mu_mailbox_t mbox, size_t cur);
 
+void mh_whatnow_env_from_environ (struct mh_whatnow_env *wh);
+void mh_whatnow_env_to_environ (struct mh_whatnow_env *wh);
diff --git a/mh/mh_global.c b/mh/mh_global.c
index 7de44b8..c19c611 100644
--- a/mh/mh_global.c
+++ b/mh/mh_global.c
@@ -45,7 +45,7 @@ mh_read_property_file (char *name, int ro)
 static int
 prop_merger (const char *field, const char *value, void *data)
 {
-  mu_property_t dst;
+  mu_property_t dst = data;
   return mu_property_set_value (dst, field, value, 1);
 }
 
diff --git a/mh/mh_init.c b/mh/mh_init.c
index f35c08f..7adc649 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -982,10 +982,14 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
 
   if (strcmp (msgspec, "new") == 0)
     {
+      mu_property_t prop;
+      
       rc = mu_mailbox_uidnext (mbox, &uid);
       if (rc)
 	mu_error (_("cannot obtain sequence number for the new message: %s"),
 		  mu_strerror (rc));
+      mu_mailbox_get_property (mbox, &prop);
+      mu_property_set_value (prop, "cur", mu_umaxtostr (0, uid), 1);
     }
   else
     {
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 9ba2195..0d8dd61 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -17,6 +17,14 @@
 
 #include <mh.h>
 
+#if defined (HAVE_SYSCONF) && defined (_SC_OPEN_MAX)
+# define getmaxfd() sysconf (_SC_OPEN_MAX)
+#elif defined (HAVE_GETDTABLESIZE)
+# define getmaxfd() getdtablesize ()
+#else
+# define getmaxfd() 64
+#endif
+
 typedef int (*handler_fp) (struct mh_whatnow_env *wh,
 			   int argc, char **argv,
 			   int *status);
@@ -342,10 +350,11 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
       
       printf ("%s ", wh->prompt);
       fflush (stdout);
-      status = mu_stream_getline (in, &line, &size, NULL);
+      rc = mu_stream_getline (in, &line, &size, NULL);
       if (rc)
 	{
 	  mu_error (_("cannot read input stream: %s"), mu_strerror (rc));
+	  status = 1;
 	  break;
 	}
 
@@ -355,6 +364,7 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
 	{
 	  mu_error (_("cannot split line `%s': %s"), line,
 		    mu_wordsplit_strerror (&ws));
+	  status = 1;
 	  break;
 	}
       wsflags |= MU_WRDSF_REUSE;
@@ -554,8 +564,8 @@ static struct action_tab whatnow_tab[] = {
   { NULL }
 };
 
-int
-mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
+static void
+set_default_editor (struct mh_whatnow_env *wh)
 {
   if (!wh->editor)
     {
@@ -565,6 +575,12 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
 					    p : (p = (getenv ("EDITOR"))) ?
 					          p : "prompter");	  
     }
+}
+
+int
+mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
+{
+  set_default_editor (wh);
   
   if (initial_edit)
     mh_spawnp (wh->editor, wh->file);
@@ -575,6 +591,62 @@ mh_whatnow (struct mh_whatnow_env *wh, int initial_edit)
   return _whatnow (wh, whatnow_tab);
 }
 
+int
+mh_whatnowproc (struct mh_whatnow_env *wh, int initial_edit, const char *prog)
+{
+  int rc;
+  pid_t pid;
+  
+  if (!prog)
+    return mh_whatnow (wh, initial_edit);
+
+  pid = fork ();
+  if (pid == -1)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "fork", NULL, errno);
+      return 1;
+    }
+  
+  if (pid == 0)
+    {
+      struct mu_wordsplit ws;
+      int i;
+      
+      if (mu_wordsplit (prog, &ws,
+			MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES))
+	{
+	  mu_error (_("cannot parse command line (%s): %s"), prog,
+		    mu_wordsplit_strerror (&ws));
+	  _exit (127);
+	}
+      
+      set_default_editor (wh);
+      mh_whatnow_env_to_environ (wh);
+      for (i = getmaxfd (); i > 2; i--)
+	close (i);
+      execvp (ws.ws_wordv[0], ws.ws_wordv);
+      mu_diag_funcall (MU_DIAG_ERROR, "execvp", prog, errno);
+      _exit (127);
+    }
+
+  /* Master */
+  rc = 0;
+  while (1)
+    {
+      int status;
+      
+      if (waitpid (pid, &status, 0) == (pid_t)-1)
+	{
+	  if (errno == EINTR)
+	    continue;
+	  mu_diag_funcall (MU_DIAG_ERROR, "waitpid", prog, errno);
+	  rc = 1;
+	}
+      break;
+    }
+  return rc;
+}
+
 /* Disposition shell */
 static struct action_tab disp_tab[] = {
   { "help", disp_help },
diff --git a/mh/repl.c b/mh/repl.c
index 6a9d496..09c85a7 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -61,9 +61,9 @@ static struct argp_option options[] = {
    N_("query for addresses to place in To: and Cc: lists")},
   {"width", ARG_WIDTH, N_("NUMBER"), 0, N_("set output width")},
   {"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
-   N_("* set the replacement for whatnow program")},
+   N_("set the replacement for whatnow program")},
   {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
-   N_("* ignore whatnowproc variable; use standard `whatnow' shell instead")},
+   N_("ignore whatnowproc variable; use standard `whatnow' shell instead")},
   {"use", ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL, N_("use draft file preserved after the last session") },
   { 0 }
 };
@@ -110,6 +110,7 @@ static int width = 80;
 
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
+static const char *whatnowproc;
 static mh_msgset_t msgset;
 static mu_mailbox_t mbox;
 static int build_only = 0; /* --build flag */
@@ -118,6 +119,7 @@ static int use_draft = 0;  /* --use flag */
 static char *mhl_filter = NULL; /* --filter flag */
 static int annotate;       /* --annotate flag */
 static char *draftmessage = "new";
+static const char *draftfolder = NULL;
 static struct obstack fcc_stack;
 static int has_fcc;
 
@@ -141,8 +143,9 @@ opt_handler (int key, char *arg, struct argp_state *state)
   switch (key)
     {
     case ARGP_KEY_INIT:
-      wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
-						  mu_folder_directory ());
+      draftfolder = mh_global_profile_get ("Draft-Folder",
+					   mu_folder_directory ());
+      whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
       break;
       
     case ARG_ANNOTATE:
@@ -162,7 +165,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 	
     case ARG_DRAFTFOLDER:
-      wh_env.draftfolder = arg;
+      draftfolder = arg;
       break;
       
     case ARG_EDITOR:
@@ -214,7 +217,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 
     case ARG_NODRAFTFOLDER:
-      wh_env.draftfolder = NULL;
+      draftfolder = NULL;
       break;
 
     case ARG_NOEDIT:
@@ -255,8 +258,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_WHATNOWPROC:
+      whatnowproc = arg;
+      break;
+
     case ARG_NOWHATNOWPROC:
-      mh_opt_notimpl ("-[no]whatnowproc");
+      whatnowproc = NULL;
       break;
 
     case ARGP_KEY_FINI:
@@ -412,14 +418,14 @@ main (int argc, char **argv)
     }
   
   if (build_only)
-    wh_env.file = mh_expand_name (wh_env.draftfolder, "reply", 0);
-  else if (wh_env.draftfolder)
+    wh_env.file = mh_expand_name (draftfolder, "reply", 0);
+  else if (draftfolder)
     {
-      if (mh_draft_message (wh_env.draftfolder, draftmessage, &wh_env.file))
+      if (mh_draft_message (draftfolder, draftmessage, &wh_env.file))
 	return 1;
     }
   else
-    wh_env.file = mh_expand_name (wh_env.draftfolder, "draft", 0);
+    wh_env.file = mh_expand_name (draftfolder, "draft", 0);
   wh_env.draftfile = wh_env.file;
 
   make_draft (mbox, DISP_REPLACE, &wh_env);
@@ -428,7 +434,7 @@ main (int argc, char **argv)
   if (build_only)
     return 0;
 
-  rc = mh_whatnow (&wh_env, initial_edit);
+  rc = mh_whatnowproc (&wh_env, initial_edit, whatnowproc);
   
   mu_mailbox_sync (mbox);
   mu_mailbox_close (mbox);
diff --git a/mh/send.c b/mh/send.c
index f4b799f..8d95989 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -133,6 +133,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
   
   switch (key)
     {
+    case ARGP_KEY_INIT:
+      draft_folder = mh_global_profile_get ("Draft-Folder",
+					    mu_folder_directory ());
+      break;
+      
     case ARG_ALIAS:
       mh_alias_read (arg, 1);
       break;
@@ -785,7 +790,25 @@ main (int argc, char **argv)
     {
       struct stat st;
       static char *xargv[2];
-      xargv[0] = mh_draft_name ();
+
+      if (draft_folder)
+	{
+	  mh_msgset_t msgset;
+	  mu_mailbox_t mbox;
+	  mu_url_t url;
+	  const char *path;
+	  
+	  mbox = mh_open_folder (draft_folder, 1);
+	  mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
+	  mu_mailbox_get_url (mbox, &url);
+	  mu_url_sget_path (url, &path);
+	  xargv[0] = mu_make_file_name (path,
+					mu_umaxtostr (0, msgset.list[0]));
+	  mu_mailbox_destroy (&mbox);
+	  mh_msgset_free (&msgset);
+	}
+      else
+	xargv[0] = mh_draft_name ();
 
       if (stat (xargv[0], &st))
 	{
diff --git a/mh/whatnow.c b/mh/whatnow.c
index aa47a8c..1fb9438 100644
--- a/mh/whatnow.c
+++ b/mh/whatnow.c
@@ -50,19 +50,15 @@ struct mh_option mh_option[] = {
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
 static char *draftmessage = "cur";
+static const char *draftfolder = NULL;
 
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
 {
   switch (key)
     {
-    case ARGP_KEY_INIT:
-      wh_env.draftfolder = mh_global_profile_get ("Draft-Folder",
-						  mu_folder_directory ());
-      break;
-      
     case ARG_DRAFTFOLDER:
-      wh_env.draftfolder = arg;
+      draftfolder = arg;
       break;
       
     case ARG_EDITOR:
@@ -70,7 +66,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_NODRAFTFOLDER:
-      wh_env.draftfolder = NULL;
+      draftfolder = NULL;
       break;
 
     case ARG_NOEDIT:
@@ -99,22 +95,22 @@ main (int argc, char **argv)
   MU_APP_INIT_NLS ();
 
   mh_argp_init ();
+  mh_whatnow_env_from_environ (&wh_env);
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, &index);
   argc -= index;
   argv += index;
   if (argc)
     wh_env.draftfile = argv[0];
-  else if (wh_env.draftfolder)
+  else if (draftfolder)
     {
-      if (mh_draft_message (wh_env.draftfolder, draftmessage,
-			    &wh_env.file))
+      if (mh_draft_message (draftfolder, draftmessage, &wh_env.file))
 	return 1;
     }
   else
-    wh_env.draftfile = mh_expand_name (wh_env.draftfolder, "draft", 0);
+    wh_env.draftfile = mh_expand_name (draftfolder, "draft", 0);
   wh_env.draftfile = wh_env.file;
-  wh_env.msg = getenv ("mhaltmsg");
+
   return mh_whatnow (&wh_env, initial_edit);
 }
   
diff --git a/mh/whatnowenv.c b/mh/whatnowenv.c
new file mode 100644
index 0000000..844c4ae
--- /dev/null
+++ b/mh/whatnowenv.c
@@ -0,0 +1,147 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2003, 2005, 2006, 2007, 2009, 2010 Free Software
+   Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <mh.h>
+
+void
+mh_whatnow_env_from_environ (struct mh_whatnow_env *wh)
+{
+  char *folder = getenv ("mhfolder");
+
+  memset (wh, 0, sizeof (*wh));
+  
+  wh->file = getenv ("mhdraft");
+  wh->msg = getenv ("mhaltmsg");
+  wh->draftfile = wh->file;
+  wh->editor = getenv ("mheditor");
+  wh->prompt = getenv ("mhprompt"); /* extension */
+  if (folder)
+    {
+      wh->anno_field = getenv ("mhannotate");
+      if (wh->anno_field)
+	{
+	  char *p = getenv ("mhmessages");
+	  if (!p)
+	    wh->anno_field = NULL;
+	  else
+	    {
+	      size_t i;
+	      struct mu_wordsplit ws;
+	      mh_msgset_t msgset;
+	      mu_mailbox_t mbox = mh_open_folder (folder, 0);
+	      
+	      if (mu_wordsplit (p, &ws,
+				MU_WRDSF_DEFFLAGS & ~MU_WRDSF_CESCAPES))
+		{
+		  mu_error (_("cannot parse mhmessages (%s): %s"), p,
+			    mu_wordsplit_strerror (&ws));
+		  exit (1);
+		}
+	      mh_msgset_parse (mbox, &msgset, ws.ws_wordc, ws.ws_wordv, "cur");
+	      mu_wordsplit_free (&ws);
+
+	      wh->mbox = mbox;
+	      mu_list_create (&wh->anno_list);
+	      for (i = 0; i < msgset.count; i++)
+		{
+		  mu_message_t msg;
+		  int rc = mu_mailbox_get_message (mbox, msgset.list[i], &msg);
+		  if (rc)
+		    {
+		      mu_error (_("cannot get message %lu from %s: %s"),
+				(unsigned long) msgset.list[i],
+				folder,
+				mu_strerror (rc));
+		      continue;
+		    }
+		  mu_list_append (wh->anno_list, msg);
+		}
+	      mh_msgset_free (&msgset);
+	      /* FIXME:
+		 wh->anno_inplace = getenv ("mhinplace");
+	      */
+	    }
+	}
+    }
+}
+
+void
+mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
+{
+  if (wh->file)
+    setenv ("mhdraft", wh->file, 1);
+  if (wh->msg)
+    setenv ("mhaltmsg", wh->msg, 1);
+  if (wh->editor)
+    setenv ("mheditor", wh->editor, 1);
+  if (wh->prompt)
+    setenv ("mhprompt", wh->prompt, 1);
+  if (wh->anno_field)
+    setenv ("mhannotate", wh->anno_field, 1);
+  if (wh->anno_list)
+    {
+      mu_opool_t opool;
+      mu_iterator_t itr;
+      size_t prev_uid = 0;
+      int mrange = 0;
+      const char *s;
+      
+      mu_opool_create (&opool, 1);
+      mu_list_get_iterator (wh->anno_list, &itr);
+      for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+	   mu_iterator_next (itr))
+	{
+	  mu_message_t msg;
+	  size_t uid;
+	  
+	  mu_iterator_current (itr, (void**)&msg);
+	  mu_message_get_uid (msg, &uid);
+	  if (prev_uid == 0)
+	    {
+	      s = mu_umaxtostr (0, uid);
+	      mu_opool_append (opool, s, strlen (s));
+	      mrange = 0;
+	    }
+	  else if (uid == prev_uid + 1)
+	    mrange = 1;
+	  else
+	    {
+	      if (mrange)
+		{
+		  mu_opool_append_char (opool, '-');
+		  s = mu_umaxtostr (0, prev_uid);
+		  mu_opool_append (opool, s, strlen (s));
+		}
+	      mu_opool_append_char (opool, ' ');
+	      s = mu_umaxtostr (0, uid);
+	      mu_opool_append (opool, s, strlen (s));
+	      mrange = 0;
+	    }
+	}
+
+      if (mrange)
+	{
+	  mu_opool_append_char (opool, '-');
+	  s = mu_umaxtostr (0, prev_uid);
+	  mu_opool_append (opool, s, strlen (s));
+	}
+      mu_opool_append_char (opool, 0);
+      s = mu_opool_finish (opool, NULL);
+      setenv ("mhmessages", s, 1);
+      mu_opool_destroy (&opool);
+    }
+}


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Nov 22 10:15:55 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PKY7X-00041J-IP
	for mharc-commit-mailutils@gnu.org; Mon, 22 Nov 2010 10:15:55 -0500
Received: from [140.186.70.92] (port=35699 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PKY7P-0003wl-PC
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 10:15:52 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKY7K-0002BQ-4p
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 10:15:47 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:48984
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKY7K-0002BI-1w
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 10:15:42 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKY7J-00081P-Bb
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 15:15:41 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKY78-0000RY-3B
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 15:15:41 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: e6927c46013d391242d76b63cdb7b044d9ba8065
X-Git-Newrev: e34d8c168f9031dbfc2441006e0eb24182ef4389
Message-Id: <E1PKY78-0000RY-3B@vcs-noshell.in.savannah.gnu.org>
Date: Mon, 22 Nov 2010 15:15:31 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-209-ge34d8c1
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Nov 2010 15:15:52 -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=e34d8c168f9031dbfc2441006e0eb24182ef4389

The branch, master has been updated
       via  e34d8c168f9031dbfc2441006e0eb24182ef4389 (commit)
      from  e6927c46013d391242d76b63cdb7b044d9ba8065 (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 e34d8c168f9031dbfc2441006e0eb24182ef4389
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 22 16:49:51 2010 +0200

    mh: fix msgset parser and some more comp compatibility issues; provide testsuite for comp.
    * mh/Makefile.am (bin_PROGRAMS): Add mhseq.
    * mh/comp.c (main): Rewrite to fix compatibility issues.
    * mh/mh.h (MH_MSGSET_UID): New define.
    (mh_msgset_t) <flags,size>: New members.
    * mh/mh_init.c (mh_draft_message): Bugfix: convert msgset to UIDs.
    * mh/mh_msgset.c: Rewrite from scratch.
    
    * mh/tests/comp.at: New file.
    * mh/tests/mhseq.at: New file.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add comp.at, mhseq.at.
    * mh/tests/testsuite.at: Include comp.at and mhseq.at.
    
    * libmailutils/property/mhprop.c (_mh_prop_read_stream): Minor fix.
    Do remove empty lines.
    * mh/mh_whatnow.c (_whatnow): Detect EOF.
    (call_send): Quit after successful send.

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

Summary of changes:
 libmailutils/property/mhprop.c |    2 +-
 mh/.gitignore                  |    1 +
 mh/Makefile.am                 |    1 +
 mh/comp.c                      |   95 +++--
 mh/mh.h                        |   10 +-
 mh/mh_init.c                   |   12 +-
 mh/mh_msgset.c                 | 1001 ++++++++++++++++++++++------------------
 mh/mh_whatnow.c                |   12 +-
 mh/{rmm.c => mhseq.c}          |   60 ++--
 mh/tests/Makefile.am           |    2 +
 mh/tests/comp.at               |  148 ++++++
 mh/tests/mhed                  |    8 +
 mh/tests/mhseq.at              |  386 ++++++++++++++++
 mh/tests/testsuite.at          |    2 +
 14 files changed, 1204 insertions(+), 536 deletions(-)
 copy mh/{rmm.c => mhseq.c} (66%)
 create mode 100644 mh/tests/comp.at
 create mode 100755 mh/tests/mhed
 create mode 100644 mh/tests/mhseq.at

diff --git a/libmailutils/property/mhprop.c b/libmailutils/property/mhprop.c
index 9aedd22..f263d00 100644
--- a/libmailutils/property/mhprop.c
+++ b/libmailutils/property/mhprop.c
@@ -113,7 +113,7 @@ _mh_prop_read_stream (mu_header_t *phdr, mu_stream_t stream)
   argv[1] = "#";
   argv[2] = "-r";
   argv[3] = NULL;
-  rc = mu_filter_create_args (&flt, stream, argv[0], 2, argv,
+  rc = mu_filter_create_args (&flt, stream, argv[0], 3, argv,
 			      MU_FILTER_DECODE, MU_STREAM_READ);
   if (rc)
     {
diff --git a/mh/.gitignore b/mh/.gitignore
index e1a9c51..fecc9d2 100644
--- a/mh/.gitignore
+++ b/mh/.gitignore
@@ -23,6 +23,7 @@ mh_alias_lex.c
 mh_fmtgram.c
 mhl
 mhn
+mhseq
 mhparam
 mhpath
 pick
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 01dbdd0..a78eb65 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -33,6 +33,7 @@ bin_PROGRAMS = \
  mhn\
  mhparam\
  mhpath\
+ mhseq\
  pick\
  prompter\
  refile\
diff --git a/mh/comp.c b/mh/comp.c
index b882326..964baf4 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -80,6 +80,7 @@ static int build_only = 0; /* --build flag */
 static int use_draft = 0;  /* --use flag */
 static char *draftmessage = "new";
 static const char *draftfolder = NULL;
+static int folder_set; /* Folder is set on the command line */
 
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
@@ -87,8 +88,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
   switch (key)
     {
     case ARGP_KEY_INIT:
-      draftfolder = mh_global_profile_get ("Draft-Folder",
-					   mu_folder_directory ());
+      draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
       whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
       break;
 
@@ -106,6 +106,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       
     case ARG_FOLDER: 
       mh_set_current_folder (arg);
+      folder_set = 1;
       break;
 
     case ARG_FORM:
@@ -126,7 +127,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_FILE:
-      wh_env.draftfile = mh_expand_name (NULL, arg, 0);
+      wh_env.file = mh_expand_name (NULL, arg, 0);
       break;
 	
     case ARG_NODRAFTFOLDER:
@@ -197,7 +198,7 @@ main (int argc, char **argv)
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, &index);
   
-  if (wh_env.draftfile)
+  if (wh_env.file)
     {
       if (build_only)
 	{
@@ -205,68 +206,90 @@ main (int argc, char **argv)
 	  exit (1);
 	}
     }
+  else if (folder_set)
+    {
+      wh_env.file = mh_expand_name (NULL, "draft", 0);
+    }
   else
     {
       if (build_only || !draftfolder)
-	wh_env.file = mh_expand_name (NULL, "draft", 0);
+	{
+	  switch (argc - index)
+	    {
+	    case 0:
+	      wh_env.file = mh_expand_name (NULL, "draft", 0);
+	      break;
+
+	    case 1:
+	      wh_env.file = mh_expand_name (NULL, argv[index], 0);
+	      break;
+	      
+	    default:
+	      mu_error (_("only one message at a time!"));
+	      return 1;
+	    }
+	}
       else if (draftfolder)
 	{
 	  /* Comp accepts a `file', and it will, if given
 	     `-draftfolder +folder'  treat this arguments  as `msg'. */
-	  if (index < argc)
+	  if (use_draft || index < argc)
 	    {
 	      mh_msgset_t msgset;
 	      mu_mailbox_t mbox;
 	      
 	      mbox = mh_open_folder (draftfolder, 1);
-	      mh_msgset_parse (mbox, &msgset, argc - index, argv + index,
-			       "new");
+	      mh_msgset_parse (mbox, &msgset, 
+	                       argc - index, argv + index,
+			       use_draft ? "cur" : "new");
 	      mu_mailbox_destroy (&mbox);
 	      if (msgset.count != 1)
 		{
 		  mu_error (_("only one message at a time!"));
 		  return 1;
 		}
+              mh_msgset_uids (mbox, &msgset);	
 	      draftmessage = mu_umaxtostr (0, msgset.list[0]);
 	      mh_msgset_free (&msgset);
-	      index = argc;
 	    }
 	  if (mh_draft_message (draftfolder, draftmessage,
 				&wh_env.file))
 	    return 1;
 	}
-      wh_env.draftfile = wh_env.file;
     }
-  
-  switch (check_draft_disposition (&wh_env, use_draft))
-    {
-    case DISP_QUIT:
-      exit (0);
+  wh_env.draftfile = wh_env.file;
 
-    case DISP_USE:
-      break;
-	  
-    case DISP_REPLACE:
-      unlink (wh_env.draftfile);
-  
-      if (index < argc)
+  if (folder_set && index < argc)
+    {
+      mh_msgset_t msgset;
+      mu_mailbox_t mbox;
+      
+      mbox = mh_open_folder (mh_current_folder (), 0);
+      mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
+      if (msgset.count != 1)
 	{
-	  mh_msgset_t msgset;
-	  mu_mailbox_t mbox;
+	  mu_error (_("only one message at a time!"));
+	  return 1;
+	}
+      unlink (wh_env.file);
+      copy_message (mbox, msgset.list[0], wh_env.file);
+      mu_mailbox_destroy (&mbox);
+      mh_msgset_free (&msgset);
+    }
+  else
+    {
+      switch (check_draft_disposition (&wh_env, use_draft))
+	{
+	case DISP_QUIT:
+	  exit (0);
+
+	case DISP_USE:
+	  break;
 	  
-	  mbox = mh_open_folder (mh_current_folder (), 0);
-	  mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
-	  if (msgset.count != 1)
-	    {
-	      mu_error (_("only one message at a time!"));
-	      return 1;
-	    }
-	  copy_message (mbox, msgset.list[0], wh_env.file);
-	  mu_mailbox_destroy (&mbox);
-	  mh_msgset_free (&msgset);
+	case DISP_REPLACE:
+	  unlink (wh_env.draftfile);
+	  mh_comp_draft (formfile, "components", wh_env.file);
 	}
-      else
-	mh_comp_draft (formfile, "components", wh_env.file);
     }
   
   /* Exit immediately if --build is given */
diff --git a/mh/mh.h b/mh/mh.h
index 8e658d7..a4c66cf 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -195,10 +195,14 @@ typedef struct
   mu_header_t header;
 } mh_context_t;
 
+#define MH_MSGSET_UID   0x01
+
 typedef struct
 {
-  size_t count;
+  int flags;
   size_t *list;
+  size_t count;
+  size_t size;
 } mh_msgset_t;
 
 typedef void (*mh_iterator_fp) (mu_mailbox_t mbox, mu_message_t msg,
@@ -300,8 +304,8 @@ int mh_message_number (mu_message_t msg, size_t *pnum);
 
 mu_mailbox_t mh_open_folder (const char *folder, int create);
 
-int mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
-		     int argc, char **argv, char *def);
+void mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
+		      int argc, char **argv, char *def);
 int mh_msgset_member (mh_msgset_t *msgset, size_t num);
 void mh_msgset_reverse (mh_msgset_t *msgset);
 void mh_msgset_negate (mu_mailbox_t mbox, mh_msgset_t *msgset);
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 7adc649..bebfed9 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -998,14 +998,14 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
       
       argv[0] = (char*) msgspec;
       argv[1] = NULL;
-      rc = mh_msgset_parse (mbox, &msgset, 1, argv, "cur");
-      if (rc)
-	mu_error (_("invalid message number: %s"), msgspec);
-      else if (msgset.count > 1)
+      mh_msgset_parse (mbox, &msgset, 1, argv, "cur");
+      if (msgset.count > 1)
 	mu_error (_("only one message at a time!"));
       else
-	uid = msgset.list[0];
-
+	{
+	  mh_msgset_uids (mbox, &msgset);
+	  uid = msgset.list[0];
+	}
       mh_msgset_free (&msgset);
     }
   
diff --git a/mh/mh_msgset.c b/mh/mh_msgset.c
index 6e058a2..fd0287f 100644
--- a/mh/mh_msgset.c
+++ b/mh/mh_msgset.c
@@ -19,473 +19,184 @@
 
 #include <mh.h>
 
-/* Expand a message set (msgcnt;msglist) to accomodate `inc' more
-   elements */
-static void
-_expand (size_t *msgcnt, size_t **msglist, size_t inc)
+int
+mh_uid_to_msgno (mu_mailbox_t mbox, size_t uid, size_t *msgno)
 {
-  if (!inc)
-    return;
-
-  *msgcnt += inc;
-  *msglist = realloc (*msglist, (*msgcnt)*sizeof(**msglist));
-  if (!*msglist)
-    mh_err_memory (1);
+  size_t num = mh_get_message (mbox, uid, NULL);
+  if (num == 0)
+    return MU_ERR_NOENT;
+  *msgno = num;
+  return 0;
 }
 
-/* Fatal error handler */ 
-static void
-msgset_abort (const char *arg)
+int
+mh_msgno_to_uid (mu_mailbox_t mbox, size_t msgno, size_t *uid)
 {
-  mu_error (_("bad message list `%s'"), arg);
-  exit (1);
+  mu_message_t msg;
+  int rc = mu_mailbox_get_message (mbox, msgno, &msg);
+  if (rc)
+    return rc;
+  return mu_message_get_uid (msg, uid);
 }
 
-/* Handlers for expansion of the reserved message names */
-
-static int
-msgset_first (mu_mailbox_t mbox, size_t *pnum)
+
+void
+mh_msgset_init (mh_msgset_t *msgset)
 {
-  *pnum = 1;
-  return 0;
+  memset (msgset, 0, sizeof (*msgset));
 }
 
-static int
-msgset_last (mu_mailbox_t mbox, size_t *pnum)
+void
+mh_msgset_expand (mh_msgset_t *msgset, size_t count)
 {
-  int rc;
-  size_t count = 0;
+  size_t rest = msgset->size - msgset->count;
 
-  rc = mu_mailbox_messages_count (mbox, &count);
-  if (rc)
+  if (rest < count)
     {
-      mu_error (_("cannot get last message: %s"), mu_strerror (rc));
-      exit (1);
+      msgset->size += count;
+      msgset->list = xrealloc (msgset->list,
+			       msgset->size * sizeof (msgset->list[0]));
     }
-  *pnum = count;
-  return 0;
 }
 
-static int
-msgset_cur (mu_mailbox_t mbox, size_t *pnum)
+void
+mh_msgset_add (mh_msgset_t *msgset, size_t n)
 {
-  size_t i, count = 0;
-  static int cached_n = 0;
-  size_t cur;
-
-  mh_mailbox_get_cur (mbox, &cur);
-  
-  if (cached_n)
-    {
-      *pnum = cached_n;
-      return 0;
-    }
-
-  mu_mailbox_messages_count (mbox, &count);
-  for (i = 1; i <= count; i++)
-    {
-      mu_message_t msg = NULL;
-      size_t uid = 0;
-      
-      mu_mailbox_get_message (mbox, i, &msg);
-      mh_message_number (msg, &uid);
-      if (uid == cur)
-	{
-	  *pnum = cached_n = i;
-	  return 0;
-	}
-    }
-  mu_error (_("no cur message"));
-  exit (1);
+  mh_msgset_expand (msgset, 1);
+  msgset->list[msgset->count++] = n;
 }
 
 static int
-msgset_prev (mu_mailbox_t mbox, size_t *pnum)
+comp_mesg (const void *a, const void *b)
 {
-  size_t cur_n = 0;
-  msgset_cur (mbox, &cur_n);
-  if (cur_n < 1)
-    {
-      mu_error (_("no prev message"));
-      exit (1);
-    }
-  *pnum = cur_n - 1;
+  size_t an = *(size_t*)a;
+  size_t bn = *(size_t*)b;
+  if (an > bn)
+    return 1;
+  else if (an < bn)
+    return -1;
   return 0;
 }
 
-static int
-msgset_next (mu_mailbox_t mbox, size_t *pnum)
+void
+mh_msgset_optimize (mh_msgset_t *msgset)
 {
-  size_t cur_n = 0, total = 0;
-  msgset_cur (mbox, &cur_n);
-  mu_mailbox_messages_count (mbox, &total);
-  if (cur_n + 1 > total)
-    {
-      mu_error (_("no next message"));
-      exit (1);
-    }
-  *pnum = cur_n + 1;
-  return 0;
-}
+  size_t i, msgno;
+  size_t msgcnt = msgset->count;
+  size_t *msglist = msgset->list;
+      
+  /* Sort the resulting message set */
+  qsort (msglist, msgcnt, sizeof (*msgset->list), comp_mesg);
 
-static struct msgset_keyword {
-  char *name;
-  int (*handler) (mu_mailbox_t mbox, size_t *pnum);
-} keywords[] = {
-  { "first", msgset_first },
-  { "last", msgset_last },
-  { "prev", msgset_prev },
-  { "next", msgset_next },
-  { "cur", msgset_cur },
-  { NULL },
-};
+  /* Remove duplicates. */
+  for (i = 0, msgno = 1; i < msgset->count; i++)
+    if (msglist[msgno-1] != msglist[i])
+      msglist[msgno++] = msglist[i];
+  msgset->count = msgno;
+}
 
-/* Preprocess a part of a complex message designation. Returns
-   a pointer to the allocated memory containing expanded part of
-   the designation. Pointer to the beginning of the not expanded
-   part (in arg) is placed into *rest */
-static char *
-msgset_preproc_part (mu_mailbox_t mbox, char *arg, char **rest)
+/* Check if message with ordinal number `num' is contained in the
+   message set. */
+int
+mh_msgset_member (mh_msgset_t *msgset, size_t num)
 {
-  struct msgset_keyword *p;
-  char *cp;
-  
-  for (p = keywords; p->name; p++)
-    if (strncmp (arg, p->name, strlen (p->name)) == 0)
-      {
-	int rc;
-	size_t uid, num;
-	mu_message_t msg;
-	
-	if (p->handler (mbox, &num))
-	  msgset_abort (arg);
-	rc = mu_mailbox_get_message (mbox, num, &msg);
-	if (rc)
-	  {
-	    mu_error (_("cannot get message %lu: %s"),
-		      (unsigned long) num, mu_strerror (rc));
-	    exit (1);
-	  }
-	*rest = arg + strlen (p->name);
-	mu_message_get_uid (msg, &uid);
-	return xstrdup (mu_umaxtostr (0, uid));
-      }
-  cp = strchr (arg, '-');
-  if (cp)
-    {
-      char *ret;
-
-      *rest = cp;
-      ret = xmalloc (cp - arg + 1);
-      memcpy (ret, arg, cp - arg);
-      ret[cp - arg] = 0;
-      return ret;
-    }
+  size_t i;
 
-  *rest = arg + strlen (arg);
-  return strdup (arg);
+  for (i = 0; i < msgset->count; i++)
+    if (msgset->list[i] == num)
+      return i + 1;
+  return 0;
 }
 
-/* Preprocess (expand) a single message designation */
-static char *
-msgset_preproc (mu_mailbox_t mbox, char *arg)
+/* Reverse the order of messages in the message set */
+void
+mh_msgset_reverse (mh_msgset_t *msgset)
 {
-  char *buf, *tail;
-  
-  if (strcmp (arg, "all") == 0 || strcmp (arg, ".") == 0)
-    {
-      /* Special case */
-      arg = "first-last";
-    }
+  int head, tail;
 
-  buf = msgset_preproc_part (mbox, arg, &tail);
-  if (tail[0] == '-')
-    {
-      char *rest = msgset_preproc_part (mbox, tail+1, &tail);
-      char *p = NULL;
-      mu_asprintf (&p, "%s-%s", buf, rest);
-      free (rest);
-      free (buf);
-      buf = p;
-    }
-  
-  if (tail[0])
+  for (head = 0, tail = msgset->count-1; head < tail; head++, tail--)
     {
-      char *p = NULL;
-      mu_asprintf (&p, "%s%s", buf, tail);
-      free (buf);
-      buf = p;
+      size_t val = msgset->list[head];
+      msgset->list[head] = msgset->list[tail];
+      msgset->list[tail] = val;
     }
-  return buf;
 }
 
-static int
-comp_mesg (const void *a, const void *b)
-{
-  if (*(size_t*)a > *(size_t*)b)
-    return 1;
-  else if (*(size_t*)a < *(size_t*)b)
-    return -1;
-  return 0;
-}
-
-static int _mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
-			     int argc, char **argv);
-
-/* Treat arg as a name of user-defined sequence and attempt to
-   expand it. Return 0 if succeeded, non-zero otherwise. */
-int
-expand_user_seq (mu_mailbox_t mbox, mh_msgset_t *msgset, char *arg)
+/* Set the current message to that contained at position `index'
+   in the given message set */
+void
+mh_msgset_current (mu_mailbox_t mbox, mh_msgset_t *msgset, int index)
 {
-  struct mu_wordsplit ws;
-  char *p;
-  const char *listp;
-  int rc = 1;
-  int negate = 0;
-  
-  p = strchr (arg, ':');
-  if (p)
-    *p++ = 0;
-  listp = mh_global_sequences_get (mbox, arg, NULL);
-  if (!listp)
-    {
-      int len;
-      const char *neg = mh_global_profile_get ("Sequence-Negation", NULL);
-      if (!neg)
-	return 1;
-      len = strlen (neg);
-      if (strncmp (arg, neg, len))
-	return 1;
-      negate = 1;
-      listp = mh_global_sequences_get (mbox, arg + len, NULL);
-      if (!listp)
-	return 1;
-    }
-
-  if (mu_wordsplit (listp, &ws, MU_WRDSF_DEFFLAGS))
-    {
-      mu_error (_("cannot split line `%s': %s"), listp,
-		mu_wordsplit_strerror (&ws));
-    }
-  else
-    {
-      rc = _mh_msgset_parse (mbox, msgset, ws.ws_wordc, ws.ws_wordv);
-      mu_wordsplit_free (&ws);
-    }
+  mu_message_t msg = NULL;
+  int rc;
+  size_t cur;
   
+  rc = mu_mailbox_get_message (mbox, msgset->list[index], &msg);
   if (rc)
-    return rc;
-
-  if (negate)
-    mh_msgset_negate (mbox, msgset);
-  
-  if (p)
     {
-      int first, num;
-      
-      num = strtoul (p, &p, 0);
-      if (*p)
-	{
-	  mh_msgset_free (msgset);
-	  return 1;
-	}
-      if (num < 0)
-	{
-	  first = num + msgset->count;
-	  num = - num;
-	}
-      else
-	first = 0;
-      if (num > msgset->count)
-	{
-	  mh_msgset_free (msgset);
-	  return 1;
-	}
-
-      if (first > 0)
-	memmove (msgset->list, &msgset->list[first],
-		 sizeof (msgset->list[0]) * num);
-      msgset->count = num;
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_message", NULL, rc);
+      exit (1);
     }
-  
-  return rc;
+  mh_message_number (msg, &cur);
+  mh_mailbox_set_cur (mbox, cur);
 }
 
-/* Parse a message specification from (argc;argv). Returned msgset is
-   not sorted nor optimised */
-int
-_mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset, int argc, char **argv)
+/* Free memory allocated for the message set. Note, that the msgset
+   itself is supposed to reside in the statically allocated memory and
+   therefore is not freed */
+void
+mh_msgset_free (mh_msgset_t *msgset)
 {
-  size_t msgcnt;
-  size_t *msglist;
-  size_t i, msgno;
-  
-  if (argc == 0)
-    return 1;
-  
-  msgcnt = argc;
-  msglist = calloc (msgcnt, sizeof(*msglist));
-  for (i = 0, msgno = 0; i < argc; i++)
-    {
-      char *p = NULL, *q;
-      size_t start, end;
-      size_t msg_first, n;
-      long num;
-      char *arg = msgset_preproc (mbox, argv[i]);
-
-      if (!mu_isdigit (arg[0]))
-	{
-	  int j;
-	  mh_msgset_t m;
-	  
-	  if (expand_user_seq (mbox, &m, arg))
-	    {
-	      mu_error (_("message set %s does not exist"), arg);
-	      exit (1);
-	    }
-	  _expand (&msgcnt, &msglist, m.count);
-	  for (j = 0; j < m.count; j++)
-	    msglist[msgno++] = m.list[j];
-	  mh_msgset_free (&m);
-	}
-      else
-	{
-	  start = strtoul (arg, &p, 0);
-	  switch (*p)
-	    {
-	    case 0:
-	      n = mh_get_message (mbox, start, NULL);
-	      if (!n)
-		{
-		  mu_error (_("message %lu does not exist"),
-			    (unsigned long) start);
-		  exit (1);
-		}
-	      msglist[msgno++] = n;
-	      break;
-	      
-	    case '-':
-	      end = strtoul (p+1, &p, 0);
-	      if (*p)
-		msgset_abort (argv[i]);
-	      if (end < start)
-		{
-		  size_t t = start;
-		  start = end;
-		  end = t;
-		}
-	      _expand (&msgcnt, &msglist, end - start);
-	      msg_first  = msgno;
-	      for (; start <= end; start++)
-		{
-		  n = mh_get_message (mbox, start, NULL);
-		  if (n)
-		    msglist[msgno++] = n;
-		}
-	      if (msgno == msg_first)
-		{
-		  mu_error (_("no messages in range %s"), argv[i]);
-		  exit (1);
-		}
-	      break;
-	      
-	    case ':':
-	      num = strtoul (p+1, &q, 0);
-	      if (*q)
-		msgset_abort (argv[i]);
-	      if (p[1] != '+' && p[1] != '-')
-		{
-		  if (strncmp (argv[i], "last:", 5) == 0
-		      || strncmp (argv[i], "prev:", 5) == 0)
-		    num = -num;
-		}
-	      end = start + num;
-	      if (end < start)
-		{
-		  size_t t = start;
-		  start = end + 1;
-		  end = t;
-		}
-	      else
-		end--;
-	      _expand (&msgcnt, &msglist, end - start);
-	      msg_first  = msgno;
-	      for (; start <= end; start++)
-		{
-		  n = mh_get_message (mbox, start, NULL);
-		  if (n)
-		    msglist[msgno++] = n;
-		}
-	      if (msgno == msg_first)
-		{
-		  mu_error (_("no messages in range %s"), argv[i]);
-		  exit (1);
-		}
-	      break;
-	      
-	    default:
-	      msgset_abort (argv[i]);
-	    }
-	}
-      free (arg);
-    }
-
-  msgset->count = msgno;
-  msgset->list = msglist;
-  return 0;
+  if (msgset->count)
+    free (msgset->list);
 }
 
-/* Parse a message specification from (argc;argv). Returned msgset is
-   sorted and optimised (i.e. it does not contain duplicate message
-   numbers) */
-int
-mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
-		 int argc, char **argv, char *def)
+/* Negate the message set: on return `msgset' consists of the messages
+   _not contained_ in the input message set. Any memory associated with
+   the input message set is freed */
+void
+mh_msgset_negate (mu_mailbox_t mbox, mh_msgset_t *msgset)
 {
-  char *xargv[2];
-  int rc;
-  
-  if (argc == 0)
+  size_t i, total = 0, msgno;
+  size_t *list;
+
+  mu_mailbox_messages_count (mbox, &total);
+  list = calloc (total, sizeof (list[0]));
+  if (!list)
+    mh_err_memory (1);
+  for (i = 1, msgno = 0; i <= total; i++)
     {
-      argc = 1;
-      argv = xargv;
-      argv[0] = def ? def : "cur";
-      argv[1] = NULL;
+      if (!mh_msgset_member (msgset, i))
+	list[msgno++] = i;
     }
-  
-  rc = _mh_msgset_parse (mbox, msgset, argc, argv);
 
-  if (rc == 0)
+  list = realloc (list, sizeof (list[0]) * msgno);
+  if (!list)
     {
-      size_t i, msgno;
-      size_t msgcnt = msgset->count;
-      size_t *msglist = msgset->list;
-      
-      /* Sort the resulting message set */
-      qsort (msglist, msgcnt, sizeof (*msgset->list), comp_mesg);
-
-      /* Remove duplicates. */
-      for (i = 0, msgno = 1; i < msgset->count; i++)
-	if (msglist[msgno-1] != msglist[i])
-	  msglist[msgno++] = msglist[i];
-      msgset->count = msgno;
+      mu_error (_("not enough memory"));
+      abort ();
     }
-  return rc;
+  mh_msgset_free (msgset);
+  msgset->count = msgno;
+  msgset->list = list;
 }
 
-/* Check if message with ordinal number `num' is contained in the
-   message set. */
-int
-mh_msgset_member (mh_msgset_t *msgset, size_t num)
+void
+mh_msgset_uids (mu_mailbox_t mbox, mh_msgset_t *msgset)
 {
   size_t i;
 
+  if (msgset->flags & MH_MSGSET_UID)
+    return;
   for (i = 0; i < msgset->count; i++)
-    if (msgset->list[i] == num)
-      return i + 1;
-  return 0;
+    {
+      mu_message_t msg;
+      mu_mailbox_get_message (mbox, msgset->list[i], &msg);
+      mh_message_number (msg, &msgset->list[i]);
+    }
+  msgset->flags |= MH_MSGSET_UID;
 }
-
+
 /* Auxiliary function. Performs binary search for a message with the
    given sequence number */
 static size_t
@@ -555,87 +266,457 @@ mh_get_message (mu_mailbox_t mbox, size_t seqno, mu_message_t *mesg)
   return mh_search_message (mbox, 1, count, seqno, mesg);
 }
 
-/* Reverse the order of messages in the message set */
-void
-mh_msgset_reverse (mh_msgset_t *msgset)
+
+struct msgset_parser
 {
-  int head, tail;
+  mu_mailbox_t mbox;
+  mh_msgset_t *msgset;
+  char *curp;
+  int argc;
+  char **argv;
+
+  int sign;
+  size_t number;
+  int validuid;
+};
 
-  for (head = 0, tail = msgset->count-1; head < tail; head++, tail--)
+static void
+msgset_parser_init (struct msgset_parser *parser, mu_mailbox_t mbox,
+		    mh_msgset_t *msgset, int argc, char **argv)
+{
+  parser->mbox = mbox;
+  parser->msgset = msgset;
+  parser->argc = argc;
+  parser->argv = argv;
+  parser->curp = "";
+
+  parser->sign = 0;
+  parser->number = 0;
+}
+
+static void
+msgset_abort (const char *arg)
+{
+  mu_error (_("bad message list `%s'"), arg);
+  exit (1);
+}
+
+static void
+emptyrange_abort (const char *range)
+{
+  mu_error (_("no messages in range %s"), range);
+  exit (1);
+}
+
+/* Advance parser to the next argument */
+static int
+nextarg (struct msgset_parser *parser)
+{
+  if (parser->argc == 0)
+    return 0;
+  parser->argc--;
+  parser->curp = *parser->argv++;
+  return 1;
+}
+
+static void msgset_parser_run (struct msgset_parser *parser);
+
+static int
+_expand_sequence (struct msgset_parser *parser, char *term)
+{
+  struct mu_wordsplit ws;
+  const char *listp;
+  int negate = 0;
+
+  listp = mh_global_sequences_get (parser->mbox, term, NULL);
+  if (!listp)
     {
-      size_t val = msgset->list[head];
-      msgset->list[head] = msgset->list[tail];
-      msgset->list[tail] = val;
+      int len;
+      const char *neg = mh_global_profile_get ("Sequence-Negation", NULL);
+      if (!neg)
+	return 1;
+      len = strlen (neg);
+      if (strncmp (term, neg, len))
+	return 1;
+      negate = 1;
+      listp = mh_global_sequences_get (parser->mbox, term + len, NULL);
+      if (!listp)
+	return 1;
+    }
+
+  if (mu_wordsplit (listp, &ws, MU_WRDSF_DEFFLAGS))
+    {
+      mu_error (_("cannot split line `%s': %s"), listp,
+		mu_wordsplit_strerror (&ws));
+      exit (1);
+    }
+  else
+    {
+      struct msgset_parser clone;
+      
+      msgset_parser_init (&clone, parser->mbox,  parser->msgset,
+			  ws.ws_wordc, ws.ws_wordv);
+      msgset_parser_run (&clone);
+      mu_wordsplit_free (&ws);
     }
+  
+  if (negate)
+    mh_msgset_negate (parser->mbox, parser->msgset);
+  return 0;
 }
 
-/* Set the current message to that contained at position `index'
-   in the given message set */
-void
-mh_msgset_current (mu_mailbox_t mbox, mh_msgset_t *msgset, int index)
+static int
+parse_count (struct msgset_parser *parser)
+{
+  char *endp;
+  if (!*parser->curp && nextarg (parser) == 0)
+    return 0;
+  if (*parser->curp == '-')
+    {
+      parser->sign = 1;
+      parser->curp++;
+    }
+  else if (*parser->curp == '+')
+    {
+      parser->sign = 0;
+      parser->curp++;
+    }
+  parser->number = strtoul (parser->curp, &endp, 10);
+  if (*endp)
+    msgset_abort (parser->curp);
+  parser->curp = endp;
+  return 1;
+}
+
+
+static int
+msgset_first (mu_mailbox_t mbox, size_t *pnum)
+{
+  *pnum = 1;
+  return 0;
+}
+
+static int
+msgset_last (mu_mailbox_t mbox, size_t *pnum)
 {
-  mu_message_t msg = NULL;
   int rc;
-  size_t cur;
-  
-  rc = mu_mailbox_get_message (mbox, msgset->list[index], &msg);
+
+  rc = mu_mailbox_messages_count (mbox, pnum);
   if (rc)
     {
-      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_message", NULL, rc);
+      mu_error (_("cannot get last message: %s"), mu_strerror (rc));
       exit (1);
     }
-  mh_message_number (msg, &cur);
-  mh_mailbox_set_cur (mbox, cur);
+  return 0;
 }
 
-/* Free memory allocated for the message set. Note, that the msgset
-   itself is supposed to reside in the statically allocated memory and
-   therefore is not freed */
-void
-mh_msgset_free (mh_msgset_t *msgset)
+static int
+msgset_cur (mu_mailbox_t mbox, size_t *pnum)
 {
-  if (msgset->count)
-    free (msgset->list);
+  size_t num;
+  mh_mailbox_get_cur (mbox, &num);
+  return mh_uid_to_msgno (mbox, num, pnum);
 }
 
-/* Negate the message set: on return `msgset' consists of the messages
-   _not contained_ in the input message set. Any memory associated with
-   the input message set is freed */
-void
-mh_msgset_negate (mu_mailbox_t mbox, mh_msgset_t *msgset)
+static int
+msgset_prev (mu_mailbox_t mbox, size_t *pnum)
 {
-  size_t i, total = 0, msgno;
-  size_t *list;
+  size_t cur_n = 0;
+  msgset_cur (mbox, &cur_n);
+  if (cur_n < 1)
+    {
+      mu_error (_("no prev message"));
+      exit (1);
+    }
+  *pnum = cur_n - 1;
+  return 0;
+}
 
+static int
+msgset_next (mu_mailbox_t mbox, size_t *pnum)
+{
+  size_t cur_n = 0, total = 0;
+  msgset_cur (mbox, &cur_n);
   mu_mailbox_messages_count (mbox, &total);
-  list = calloc (total, sizeof (list[0]));
-  if (!list)
-    mh_err_memory (1);
-  for (i = 1, msgno = 0; i <= total; i++)
+  if (cur_n + 1 > total)
     {
-      if (!mh_msgset_member (msgset, i))
-	list[msgno++] = i;
+      mu_error (_("no next message"));
+      exit (1);
     }
+  *pnum = cur_n + 1;
+  return 0;
+}
 
-  list = realloc (list, sizeof (list[0]) * msgno);
-  if (!list)
+struct msgset_keyword
+{
+  char *name;
+  size_t len;
+  int (*handler) (mu_mailbox_t mbox, size_t *pnum);
+  int sign;
+};
+
+static struct msgset_keyword keywords[] = {
+#define S(s) #s, sizeof (#s) - 1
+  { S(first), msgset_first, 0 },
+  { S(last), msgset_last, 1 },
+  { S(prev), msgset_prev, 1 },
+  { S(next), msgset_next, 0 },
+  { S(cur), msgset_cur, 0 },
+  { NULL }
+};
+
+#define PARSE_EOF  0
+#define PARSE_MORE 1
+#define PARSE_SUCCESS 2
+
+/* term : NUMBER
+        | "first"
+	| "last"
+	| "cur"
+	| "prev"
+	| "next"
+	;
+*/
+static int
+parse_term (struct msgset_parser *parser, int seq)
+{
+  size_t tlen;
+  char *term;
+  
+  if (!*parser->curp && nextarg (parser) == 0)
+    return PARSE_EOF;
+
+  term = parser->curp;
+  parser->curp = mu_str_skip_class (term, MU_CTYPE_ALPHA|MU_CTYPE_DIGIT);
+  tlen = parser->curp - term;
+  if (mu_isalpha (*term))
     {
-      mu_error (_("not enough memory"));
-      abort ();
+      struct msgset_keyword *p;
+
+      for (p = keywords; p->name; p++)
+	if (tlen == p->len && memcmp (p->name, term, tlen) == 0)
+	  {
+	    if (p->handler (parser->mbox, &parser->number))
+	      msgset_abort (term);
+	    parser->sign = p->sign;
+	    parser->validuid = 1;
+	    return PARSE_MORE;
+	  }
+
+      if (*parser->curp == 0 && seq)
+	{
+	  /* See if it is a user-defined sequence */
+	  if (_expand_sequence (parser, term) == 0)
+	    return PARSE_SUCCESS;
+	}
+      msgset_abort (term);
     }
-  mh_msgset_free (msgset);
-  msgset->count = msgno;
-  msgset->list = list;
+  else if (mu_isdigit (*term))
+    {
+      char *endp;
+      size_t num = strtoul (term, &endp, 10);
+      if (endp != parser->curp)
+	msgset_abort (term);
+      
+      if (mh_uid_to_msgno (parser->mbox, num, &parser->number))
+	{
+	  parser->validuid = 0;
+	  parser->number = num;
+	}
+      else
+	parser->validuid = 1;
+      parser->sign = 0;
+    }
+  else
+    msgset_abort (term);
+  return PARSE_MORE;
 }
 
-void
-mh_msgset_uids (mu_mailbox_t mbox, mh_msgset_t *msgset)
+static void
+add_messages (struct msgset_parser *parser, size_t start, size_t count,
+	      int sign)
 {
   size_t i;
-  for (i = 0; i < msgset->count; i++)
+
+  if (start == 0)
+    start = 1;
+  mh_msgset_expand (parser->msgset, count);
+  if (sign)
     {
-      mu_message_t msg;
-      mu_mailbox_get_message (mbox, msgset->list[i], &msg);
-      mh_message_number (msg, &msgset->list[i]);
+      if (count > start)
+	count = start;
+      for (i = 0; i < count; i++, start--)
+	parser->msgset->list[parser->msgset->count++] = start;
+    }
+  else
+    {
+      size_t total;
+  
+      mu_mailbox_messages_count (parser->mbox, &total);
+      if (start + count > total)
+	count = total - start + 1;
+      for (i = 0; i < count; i++, start++)
+	parser->msgset->list[parser->msgset->count++] = start;
+    }
+  if (count == 0)
+    emptyrange_abort (parser->argv[-1]);
+}
+
+static void
+add_message_range (struct msgset_parser *parser, size_t start, size_t end)
+{
+  if (end == start)
+    emptyrange_abort (parser->argv[-1]);
+
+  if (end < start)
+    {
+      size_t t = start;
+      start = end;
+      end = t;
+    }
+  mh_msgset_expand (parser->msgset, end - start + 1);
+
+  for (; start <= end; start++)
+    parser->msgset->list[parser->msgset->count++] = start;
+}
+
+/* range: term '-' term
+        | term ':' count
+	;
+   count: NUMBER
+        | '+' NUMBER
+	| '-' NUMBER
+	;
+*/	
+static int
+parse_range (struct msgset_parser *parser)
+{
+  size_t start;
+
+  switch (parse_term (parser, 1))
+    {
+    case PARSE_EOF:
+      return 0;
+
+    case PARSE_SUCCESS:
+      return 1;
+
+    case PARSE_MORE:
+      break;
+    }
+      
+  start = parser->number;
+
+  if (*parser->curp == ':')
+    {
+      int validuid = parser->validuid;
+      parser->curp++;
+      if (parse_count (parser) == 0)
+	return 0;
+      if (!validuid)
+	{
+	  size_t total, lastuid;
+	  msgset_last (parser->mbox, &total);
+	  mh_msgno_to_uid (parser->mbox, total, &lastuid);
+	  if (start > lastuid)
+	    {
+	      if (!parser->sign)
+		emptyrange_abort (parser->argv[-1]);
+	      start = total;
+	    }
+	  else
+	    {
+	      if (parser->sign)
+		emptyrange_abort (parser->argv[-1]);
+	      start = 1;
+	    }
+	}
+      add_messages (parser, start, parser->number, parser->sign);
+      return 1;
+    }
+  else if (*parser->curp == '-')
+    {
+      size_t lastuid = 0;
+      int validuid = parser->validuid;
+      
+      parser->curp++;
+      if (parse_term (parser, 0) == PARSE_EOF)
+	return 0;
+      if (!parser->validuid)
+	{
+	  size_t total;
+
+	  msgset_last (parser->mbox, &total);
+	  mh_msgno_to_uid (parser->mbox, total, &lastuid);
+	  if (parser->number > lastuid)
+	    parser->number = total;
+	  else if (!validuid)
+	    emptyrange_abort (parser->argv[-1]);
+	}
+      if (!validuid)
+	{
+	  if (!lastuid)
+	    {
+	      size_t total;
+	      msgset_last (parser->mbox, &total);
+	      mh_msgno_to_uid (parser->mbox, total, &lastuid);
+	    }
+	  if (start > lastuid && !parser->validuid)
+	    emptyrange_abort (parser->argv[-1]);
+	  start = 1;
+	}
+      add_message_range (parser, start, parser->number);
     }
+  else if (!parser->validuid)
+    {
+      mu_error (_("message %s does not exist"), parser->argv[-1]);
+      exit (1);
+    }
+  else
+    mh_msgset_add (parser->msgset, start);
+  return 1;
+}
+  
+  
+/* Parse a message specification. The composed msgset is
+   not sorted nor optimised */
+static void
+msgset_parser_run (struct msgset_parser *parser)
+{
+  while (parse_range (parser))
+    ;
+}
+
+/* Parse a message specification from (argc;argv). Returned msgset is
+   sorted and optimised (i.e. it does not contain duplicate message
+   numbers) */
+void
+mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset, 
+		 int argc, char **argv, char *def)
+{
+  struct msgset_parser parser;
+  char *xargv[2];
+  
+  if (argc == 0)
+    {
+      argc = 1;
+      argv = xargv;
+      argv[0] = def ? def : "cur";
+      argv[1] = NULL;
+    }
+
+  if (argc == 1 &&
+      (strcmp (argv[0], "all") == 0 || strcmp (argv[0], ".") == 0))
+    {
+      argc = 1;
+      argv = xargv;
+      argv[0] = "first-last";
+      argv[1] = NULL;
+    }
+  
+  mh_msgset_init (msgset);
+  msgset_parser_init (&parser, mbox, msgset, argc, argv);
+  msgset_parser_run (&parser);
+
+  mh_msgset_optimize (msgset);
 }
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 0d8dd61..dee46b5 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -346,18 +346,21 @@ _whatnow (struct mh_whatnow_env *wh, struct action_tab *tab)
   
   do
     {
+      size_t n;
       handler_fp fun;
       
       printf ("%s ", wh->prompt);
       fflush (stdout);
-      rc = mu_stream_getline (in, &line, &size, NULL);
+      rc = mu_stream_getline (in, &line, &size, &n);
       if (rc)
 	{
 	  mu_error (_("cannot read input stream: %s"), mu_strerror (rc));
 	  status = 1;
 	  break;
 	}
-
+      if (n == 0)
+	break;
+      
       ws.ws_comment = "#";
       rc = mu_wordsplit (line, &ws, wsflags);
       if (rc)
@@ -462,7 +465,10 @@ static int
 call_send (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
 {
   if (invoke ("sendproc", MHBINDIR "/send", argc, argv, wh->file, NULL) == 0)
-    annotate (wh);
+    {
+      annotate (wh);
+      return 1;
+    }
   return 0;
 }
 
diff --git a/mh/rmm.c b/mh/mhseq.c
similarity index 66%
copy from mh/rmm.c
copy to mh/mhseq.c
index 6e2f65e..48a7691 100644
--- a/mh/rmm.c
+++ b/mh/mhseq.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2002, 2005, 2007, 2008, 2009, 2010 Free Software
-   Foundation, Inc.
+   Copyright (C) 2010 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,26 +14,32 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-/* MH rmm command */
+/* MH mhparam command */
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH rmm")"\v"
+static char doc[] = N_("GNU MH mhseq")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
-static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
+static char args_doc[] = N_("[SEQUENCE]");
 
-/* GNU options */
 static struct argp_option options[] = {
   {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  { 0 }
+   N_("specify the folder to use")},
+  { "uids",  'u', NULL, 0,
+    N_("show message UIDs (default)")},
+  { "numbers", 'n', NULL, 0,
+    N_("show message numbers") },
+  { NULL }
 };
 
 /* Traditional MH options */
 struct mh_option mh_option[] = {
+  { "uid" },
   { NULL }
 };
 
+static int uid_option = 1;
+
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
 {
@@ -43,29 +48,29 @@ opt_handler (int key, char *arg, struct argp_state *state)
     case ARG_FOLDER: 
       mh_set_current_folder (arg);
       break;
+
+    case 'n':
+      uid_option = 0;
+      break;
       
+    case 'u':
+      uid_option = 1;
+      break;
+
     default:
       return ARGP_ERR_UNKNOWN;
     }
   return 0;
 }
 
-void
-rmm (mu_mailbox_t mbox, mu_message_t msg, size_t num, void *data)
-{
-  mu_attribute_t attr;
-  mu_message_get_attribute (msg, &attr);
-  mu_attribute_set_deleted (attr);
-}
-
 int
 main (int argc, char **argv)
 {
-  int index = 0;
+  int index;
   mu_mailbox_t mbox;
   mh_msgset_t msgset;
-  int status;
-
+  size_t i;
+    
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
@@ -73,16 +78,17 @@ main (int argc, char **argv)
   mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
 		 opt_handler, NULL, &index);
 
+  argc -= index;
+  argv += index;
   mbox = mh_open_folder (mh_current_folder (), 0);
 
-  mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
-
-  status = mh_iterate (mbox, &msgset, rmm, NULL);
+  mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
+  if (uid_option)
+    mh_msgset_uids (mbox, &msgset);
 
-  mu_mailbox_expunge (mbox);
-  mu_mailbox_close (mbox);
-  mu_mailbox_destroy (&mbox);
-  mh_global_save_state ();
-  return status;
+  for (i = 0; i < msgset.count; i++)
+    printf ("%lu\n", (unsigned long) msgset.list[i]);
+  return 0;
 }
 
+  
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 3adf295..00c00ed 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -42,6 +42,7 @@ TESTSUITE_AT = \
  ali.at\
  anno.at\
  burst.at\
+ comp.at\
  folder.at\
  inc.at\
  install-mh.at\
@@ -49,6 +50,7 @@ TESTSUITE_AT = \
  mhl.at\
  mhparam.at\
  mhpath.at\
+ mhseq.at\
  pick.at\
  scan.at\
  refile.at\
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
new file mode 100644
index 0000000..54a61b1
--- /dev/null
+++ b/mh/tests/comp.at
@@ -0,0 +1,148 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([MH_KEYWORDS],[comp])
+m4_pushdef([compcmd],[comp dnl
+-form $abs_top_srcdir/mh/components dnl
+-editor $abs_top_srcdir/mh/tests/mhed])
+
+MH_CHECK([comp -file],[comp00 comp-file],[
+dir=`pwd`
+echo quit | compcmd -file ./infile | sed "s|$dir/*||;s|  *$||"
+cat infile
+],
+[0],
+[-- Editor invocation: ./infile
+-- Input file:
+To:
+cc:
+Subject:
+--------
+-- Input file end
+What now? draft left on "./infile".
+To:
+cc:
+Subject:
+--------
+Seen by mhed
+])
+
+MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
+dir=`pwd`
+echo 'quit -delete' | compcmd -file ./infile | sed "s|$dir/*||;s|  *$||"
+],
+[0],
+[-- Editor invocation: ./infile
+-- Input file:
+To:
+cc:
+Subject:
+--------
+-- Input file end
+What now?])
+
+MH_CHECK([comp file],[comp02 comp_file],[
+echo 'quit' | compcmd file | sed "s|$dir/*||;s|  *$||"
+cat Mail/file 
+],
+[0], 
+[-- Editor invocation: Mail/file
+-- Input file:
+To:
+cc:
+Subject:
+--------
+-- Input file end
+What now? draft left on "Mail/file".
+To:
+cc:
+Subject:
+--------
+Seen by mhed
+])
+
+MH_CHECK([comp -use file],[comp03 comp-use_file],[
+AT_DATA([Mail/file],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+echo 'quit' | compcmd -use file | sed "s|$dir/*||;s|  *$||"
+cat Mail/file 
+],
+[0], 
+[-- Editor invocation: Mail/file
+-- Input file:
+From: gray
+To: root
+Subject: test input
+
+message body
+-- Input file end
+What now? draft left on "Mail/file".
+From: gray
+To: root
+Subject: test input
+
+message body
+Seen by mhed
+])
+
+MH_CHECK([comp +folder msg],[comp04 comp+folder_msg],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+echo 'quit' | compcmd +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo Mail/draft
+cat Mail/draft
+echo Message
+cat Mail/inbox/1
+],
+[0], 
+[-- Editor invocation: Mail/draft
+-- Input file:
+From: gray
+To: root
+Subject: test input
+
+message body
+-- Input file end
+What now? draft left on "Mail/draft".
+Mail/draft
+From: gray
+To: root
+Subject: test input
+
+message body
+Seen by mhed
+Message
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+m4_popdef([compcmd])
+m4_popdef([MH_KEYWORDS])
+
diff --git a/mh/tests/mhed b/mh/tests/mhed
new file mode 100755
index 0000000..986edce
--- /dev/null
+++ b/mh/tests/mhed
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+echo "-- Editor invocation:" $*
+echo "-- Input file: "
+cat $1
+echo "-- Input file end"
+echo "Seen by mhed" >> $1
+exit 0
diff --git a/mh/tests/mhseq.at b/mh/tests/mhseq.at
new file mode 100644
index 0000000..225058a
--- /dev/null
+++ b/mh/tests/mhseq.at
@@ -0,0 +1,386 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([MH_KEYWORDS],[mhseq mh-sequences])
+
+dnl ---------------------------------------------------------------
+
+MH_CHECK([mhseq: existing message number],[mhseq00],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq 1
+],
+[0],
+[1
+])
+
+MH_CHECK([mhseq: not existing message number],[mhseq01],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq 100
+],
+[1],
+[],
+dnl FIXME: See FIXME 3 in mhpath.at
+[mhseq: message 100 does not exist
+])
+
+MH_CHECK([mhseq: contiguous message range],[mhseq02],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq 2-5
+],
+[0],
+[2
+3
+4
+5
+])
+
+MH_CHECK([mhseq: reversed contiguous message range],[mhseq03],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq 5-2
+],
+[0],
+[2
+3
+4
+5
+])
+
+MH_CHECK([mhseq: reversed non-contiguous message range],[mhseq04],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/3 Mail/inbox/4
+mhseq 5-2
+],
+[0],
+[2
+5
+])
+
+MH_CHECK([mhseq: message range (left fixup)],[mhseq05],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2
+mhseq 1-5
+],
+[0],
+[3
+4
+5
+])
+
+MH_CHECK([mhseq: message range (right fixup)],[mhseq06],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/4 Mail/inbox/5
+mhseq 1-5
+],
+[0],
+[1
+2
+3
+])
+
+MH_CHECK([mhseq: message range (both fixups)],[mhseq07],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/5
+mhseq 1-5
+],
+[0],
+[2
+3
+4
+])
+
+MH_CHECK([mhseq: non-existent message range (left)],[mhseq08],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2 Mail/inbox/3
+mhseq 1-2
+],
+[1],
+[],
+[mhseq: no messages in range 1-2
+])
+
+MH_CHECK([mhseq: non-existent message range (right)],[mhseq09],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq 6-10
+],
+[1],
+[],
+[mhseq: no messages in range 6-10
+])
+
+MH_CHECK([mhseq: message set addition],[mhseq10],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+mhseq 5 8-10 15-20
+],
+[0],
+[5
+8
+9
+10
+15
+16
+17
+18
+19
+20
+])
+
+MH_CHECK([mhseq: message set optimization],[mhseq11],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+rm Mail/inbox/17 Mail/inbox/19
+mhseq 5 1-10 15-20
+],
+[0],
+[1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+15
+16
+18
+20
+])
+
+MH_CHECK([mhseq: counted range (positive)],[mhseq12],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+mhseq 10:4
+],
+[0],
+[10
+11
+12
+13
+])
+
+MH_CHECK([mhseq: non-contiguous counted range (positive)],[mhseq13],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+rm Mail/inbox/12 Mail/inbox/14
+mhseq 10:4
+],
+[0],
+[10
+11
+13
+15
+])
+
+MH_CHECK([mhseq: counted range (positive, left fixup)],[mhseq14],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2
+mhseq 1:3
+],
+[0],
+[3
+4
+5
+])
+
+MH_CHECK([mhseq: counted range (positive, right fixup)],[mhseq15],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq 2:10
+],
+[0],
+[2
+3
+4
+5
+])
+
+MH_CHECK([mhseq: invalid counted range (negative)],[mhseq16],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2
+mhseq 10:2
+],
+[1],
+[],
+[mhseq: no messages in range 10:2
+])
+
+MH_CHECK([mhseq: counted range (negative)],[mhseq17],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+mhseq 10:-4
+],
+[0],
+[7
+8
+9
+10
+])
+
+MH_CHECK([mhseq: non-contiguous counted range (negative)],[mhseq18],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+rm Mail/inbox/8 Mail/inbox/6
+mhseq 10:-4
+],
+[0],
+[5
+7
+9
+10
+])
+
+MH_CHECK([mhseq: counted range (negative, left fixup)],[mhseq19],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2
+mhseq 4:-30
+],
+[0],
+[3
+4
+])
+
+MH_CHECK([mhseq: counted range (negative, right fixup)],[mhseq20],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2
+mhseq 4:30
+],
+[0],
+[4
+5
+])
+
+MH_CHECK([mhseq: invalid counted range (negative)],[mhseq21],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1 Mail/inbox/2
+mhseq 1:-30
+],
+[1],
+[],
+[mhseq: no messages in range 1:-30
+])
+
+MH_CHECK([mhseq: cur],[mhseq22 cur],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+mhseq cur
+],
+[0],
+[3
+])
+
+MH_CHECK([mhseq: cur:n -- default direction],[mhseq23 cur:n],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+mhseq cur:2
+],
+[0],
+[3
+4
+])
+
+MH_CHECK([mhseq: cur:n -- explicit dir (negative)],[mhseq24 cur:n cur:n-],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+mhseq cur:-2
+],
+[0],
+[2
+3
+])
+
+MH_CHECK([mhseq: cur:n -- explicit dir (positive)],[mhseq25 cur:n cur:n+],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+mhseq cur:+2
+],
+[0],
+[3
+4
+])
+
+MH_CHECK([mhseq: next],[mhseq26 next],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+rm Mail/inbox/4
+mhseq next
+],
+[0],
+[5
+])
+
+MH_CHECK([mhseq: next:n -- default direction],[mhseq27 next:n],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+mhseq next:2
+],
+[0],
+[4
+5
+])
+
+MH_CHECK([mhseq: prev],[mhseq28 prev],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+rm Mail/inbox/2
+mhseq prev
+],
+[0],
+[1
+])
+
+MH_CHECK([mhseq: prev:n -- default direction],[mhseq29 prev:n],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "cur: 3" > Mail/inbox/.mh_sequences
+mhseq prev:2
+],
+[0],
+[1
+2
+])
+
+MH_CHECK([mhseq: first],[mhseq30 first],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1
+mhseq first
+],
+[0],
+[2
+])
+
+MH_CHECK([mhseq: first:n -- default direction],[mhseq31 first:n],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+rm Mail/inbox/1
+mhseq first:2
+],
+[0],
+[2
+3
+])
+
+MH_CHECK([mhseq: last],[mhseq32 last],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq last
+],
+[0],
+[5
+])
+
+MH_CHECK([mhseq: last:n -- default direction],[mhseq33 last:n],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhseq last:2
+],
+[0],
+[4
+5
+])
+
+m4_popdef([MH_KEYWORDS])
+# End of mhseq.at
\ No newline at end of file
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index 10b8d52..a18976d 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -42,6 +42,7 @@ AT_CLEANUP
 AT_INIT
 
 m4_include([install-mh.at])
+m4_include([mhseq.at])
 m4_include([ali.at])
 m4_include([folder.at])
 m4_include([inc.at])
@@ -56,3 +57,4 @@ m4_include([mhl.at])
 m4_include([anno.at])
 m4_include([pick.at])
 m4_include([burst.at])
+m4_include([comp.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Nov 22 17:17:41 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PKehg-0006U1-VG
	for mharc-commit-mailutils@gnu.org; Mon, 22 Nov 2010 17:17:41 -0500
Received: from [140.186.70.92] (port=40394 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PKehc-0006S0-Fg
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 17:17:38 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKeha-0002ry-Ie
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 17:17:36 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:37704
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKeha-0002ro-Gl
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 17:17:34 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKeha-0004YK-35
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 22:17:34 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKehY-0005zT-L5
	for commit-mailutils@gnu.org; Mon, 22 Nov 2010 22:17:34 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: e34d8c168f9031dbfc2441006e0eb24182ef4389
X-Git-Newrev: 46b844cf0c0623dd370573ce6da21dd8aa6fd907
Message-Id: <E1PKehY-0005zT-L5@vcs-noshell.in.savannah.gnu.org>
Date: Mon, 22 Nov 2010 22:17:32 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-210-g46b844c
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 22 Nov 2010 22:17:38 -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=46b844cf0c0623dd370573ce6da21dd8aa6fd907

The branch, master has been updated
       via  46b844cf0c0623dd370573ce6da21dd8aa6fd907 (commit)
      from  e34d8c168f9031dbfc2441006e0eb24182ef4389 (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 46b844cf0c0623dd370573ce6da21dd8aa6fd907
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Nov 22 22:26:29 2010 +0200

    Provide a library function for translating message UIDs to numbers and vice versa.
    
    * include/mailutils/mailbox.h (MU_MAILBOX_UID_TO_MSGNO)
    (MU_MAILBOX_MSGNO_TO_UID): New defines.
    (mu_mailbox_translate): New proto.
    * include/mailutils/sys/mailbox.h (_mu_mailbox) <_translate>: New
    method.
    * libmailutils/mailbox/mailbox.c (mu_mailbox_translate): New
    function.
    * libproto/mh/mbox.c (mh_translate): New function.  Implements
    the _translate method.
    * mh/mh_msgset.c (mh_uid_to_msgno, mh_msgno_to_uid): Remove.  All
    callers updated to use mu_mailbox_translate instead.
    (mh_search_message): Remove.
    (mh_get_message): Rewrite using mu_mailbox_translate.
    
    * mh/comp.c (copy_message): Check return from mu_mailbox_get_message.
    * mh/mh_init.c (mh_draft_message): Rewrite using mu_url_sget_path.
    * mh/tests/comp.at: Test draftfolder functionality.

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

Summary of changes:
 include/mailutils/mailbox.h     |    6 ++
 include/mailutils/sys/mailbox.h |    2 +
 libmailutils/base/amd.c         |    2 +-
 libmailutils/mailbox/mailbox.c  |  112 +++++++++++++++++++++++++++++++++
 libproto/mh/mbox.c              |   35 ++++++++++
 mh/comp.c                       |    8 ++-
 mh/mh_init.c                    |   32 ++++------
 mh/mh_msgset.c                  |  131 +++++++++++----------------------------
 mh/tests/comp.at                |   55 ++++++++++++++++
 9 files changed, 267 insertions(+), 116 deletions(-)

diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h
index b2149ba..56ee1f2 100644
--- a/include/mailutils/mailbox.h
+++ b/include/mailutils/mailbox.h
@@ -116,6 +116,12 @@ extern int mu_mailbox_unlock (mu_mailbox_t mbox);
 
 extern int mu_mailbox_get_iterator (mu_mailbox_t mbx,
 				    mu_iterator_t *piterator);
+
+/* ID translation */
+#define MU_MAILBOX_UID_TO_MSGNO 0
+#define MU_MAILBOX_MSGNO_TO_UID 1
+
+extern int mu_mailbox_translate (mu_mailbox_t, int, size_t, size_t *);  
   
 #ifdef __cplusplus
 }
diff --git a/include/mailutils/sys/mailbox.h b/include/mailutils/sys/mailbox.h
index 0b57fe0..d9cc2d5 100644
--- a/include/mailutils/sys/mailbox.h
+++ b/include/mailutils/sys/mailbox.h
@@ -74,6 +74,8 @@ struct _mu_mailbox
 
   int  (*_quick_get_message) (mu_mailbox_t, mu_message_qid_t, mu_message_t *);
   int  (*_get_uidls) (mu_mailbox_t, mu_list_t);
+
+  int  (*_translate) (mu_mailbox_t, int cmd, size_t, size_t *);
 };
 
 # ifdef __cplusplus
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index c2f3b34..acbfb29 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -167,7 +167,7 @@ amd_msg_bsearch (struct _amd_data *amd, mu_off_t first, mu_off_t last,
 
 /* Search for message MSG in the message array of AMD.
    If found, return 0 and store index of the located entry in the
-   variable PRET. Otherwise, return 1 and place into PRET index of
+   variable PRET. Otherwise, return 1 and store in PRET the index of
    the array element that is less than MSG (in the sense of
    amd->msg_cmp)
    Index returned in PRET is 1-based, so *PRET == 0 means that MSG
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index 269223c..46a90cc 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -829,4 +829,116 @@ mu_mailbox_get_uidls (mu_mailbox_t mbox, mu_list_t *plist)
   return status;
 }
 
+
+/* Auxiliary function. Performs binary search for a message with the
+   given UID number */
+static int
+_uid_bsearch (mu_mailbox_t mbox, size_t start, size_t stop, size_t uid,
+	      size_t *msgno)
+{
+  mu_message_t mid_msg = NULL;
+  size_t num = 0, middle;
+  int rc;
+  
+  middle = (start + stop) / 2;
+  rc = mu_mailbox_get_message (mbox, middle, &mid_msg);
+  if (rc)
+    return rc;
+  rc = mu_message_get_uid (mid_msg, &num);
+  if (rc)
+    return rc;
+
+  if (num == uid)
+    {
+      *msgno = middle;
+      return 0;
+    }
+      
+  if (start >= stop)
+    return MU_ERR_NOENT;
+
+  if (num > uid)
+    return _uid_bsearch (mbox, start, middle - 1, uid, msgno);
+  else /*if (num < seqno)*/
+    return _uid_bsearch (mbox, middle + 1, stop, uid, msgno);
+}
+
+static int
+_search_message_uid (mu_mailbox_t mbox, size_t uid, size_t *result)
+{
+  int rc;
+  size_t num, count;
+  mu_message_t msg;
+
+  rc = mu_mailbox_get_message (mbox, 1, &msg);
+  if (rc)
+    return rc;
+  rc = mu_message_get_uid (msg, &num);
+  if (rc)
+    return rc;
+  if (uid < num)
+    return MU_ERR_NOENT;
+  else if (uid == num)
+    {
+      *result = 1;
+      return 0;
+    }
+
+  rc = mu_mailbox_messages_count (mbox, &count);
+  if (rc)
+    return rc;
+  rc = mu_mailbox_get_message (mbox, count, &msg);
+  if (rc)
+    return rc;
+  rc = mu_message_get_uid (msg, &num);
+  if (rc)
+    return rc;
+
+  if (uid > num)
+    return MU_ERR_NOENT;
+  else if (uid == num)
+    {
+      *result = count;
+      return 0;
+    }
+  return _uid_bsearch (mbox, 1, count, uid, result);
+}
+
+/* Translat message UIDs to message numbers and vice versa. */
+int
+mu_mailbox_translate (mu_mailbox_t mbox, int cmd, size_t from, size_t *to)
+{
+  int rc = ENOSYS;
+  mu_message_t msg;
+  
+  if (mbox == NULL)
+    return MU_ERR_MBX_NULL;
+  if (to == NULL)
+    return EINVAL;
+  if (mbox->flags & MU_STREAM_QACCESS)
+    return MU_ERR_BADOP;
+
+  if (mbox->_translate)
+    rc = mbox->_translate (mbox, cmd, from, to);
+  if (rc == ENOSYS)
+    {
+      switch (cmd)
+	{
+	case MU_MAILBOX_UID_TO_MSGNO:
+	  rc = _search_message_uid (mbox, from, to);
+	  break;
+	  
+	case MU_MAILBOX_MSGNO_TO_UID:
+	  rc = mu_mailbox_get_message (mbox, from, &msg);
+	  if (rc)
+	    return rc;
+	  rc = mu_message_get_uid (msg, to);
+	  break;
 	  
+	default:
+	  break;
+	}
+    }
+  return rc;
+}
+
diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c
index 9dbcce2..c28aee5 100644
--- a/libproto/mh/mbox.c
+++ b/libproto/mh/mbox.c
@@ -51,6 +51,7 @@
 #include <mailutils/debug.h>
 #include <mailutils/envelope.h>
 #include <mailutils/error.h>
+#include <mailutils/errno.h>
 #include <mailutils/header.h>
 #include <mailutils/locker.h>
 #include <mailutils/message.h>
@@ -380,6 +381,39 @@ mh_get_property (mu_mailbox_t mailbox, mu_property_t *pprop)
   return 0;
 }
 
+
+
+static int
+mh_translate (mu_mailbox_t mbox, int cmd, size_t from, size_t *to)
+{
+  struct _amd_data *amd = mbox->data;
+  struct _mh_message msg, *mp;
+  size_t n;
+
+  /* Make sure the mailbox has been scanned */ 
+  mu_mailbox_messages_count (mbox, &n);
+    
+  switch (cmd)
+    {
+    case MU_MAILBOX_UID_TO_MSGNO:
+      msg.seq_number = from;
+      if (amd_msg_lookup (amd, (struct _amd_message*) &msg, &n))
+	return MU_ERR_NOENT;
+      *to = n;
+      break;
+
+    case MU_MAILBOX_MSGNO_TO_UID:
+      mp = (struct _mh_message *) _amd_get_message (amd, from);
+      if (!mp)
+	return MU_ERR_NOENT;
+      *to = mp->seq_number;
+      break;
+
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
 
 
 
@@ -407,6 +441,7 @@ _mailbox_mh_init (mu_mailbox_t mailbox)
   amd->remove = mh_remove;
 
   mailbox->_get_property = mh_get_property;
+  mailbox->_translate = mh_translate;
   
   return 0;
 }
diff --git a/mh/comp.c b/mh/comp.c
index 964baf4..c604618 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -161,7 +161,13 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
   mu_stream_t out;
   int rc;
   
-  mu_mailbox_get_message (mbox, n, &msg);
+  rc = mu_mailbox_get_message (mbox, n, &msg);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_message", NULL, rc);
+      exit (1);
+    }
+  
   mu_message_get_streamref (msg, &in);
   
   if ((rc = mu_file_stream_create (&out,
diff --git a/mh/mh_init.c b/mh/mh_init.c
index bebfed9..2d2b0f4 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -970,15 +970,14 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
   mu_url_t url;
   size_t uid;
   int rc;
-  const char *urlstr;
   mu_mailbox_t mbox;
-
+  const char *path;
+  
   mbox = mh_open_folder (name, 0);
   if (!mbox)
     return 1;
   
   mu_mailbox_get_url (mbox, &url);
-  urlstr = mu_url_to_string (url);
 
   if (strcmp (msgspec, "new") == 0)
     {
@@ -986,8 +985,11 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
       
       rc = mu_mailbox_uidnext (mbox, &uid);
       if (rc)
-	mu_error (_("cannot obtain sequence number for the new message: %s"),
-		  mu_strerror (rc));
+	{
+	  mu_error (_("cannot obtain sequence number for the new message: %s"),
+		    mu_strerror (rc));
+	  exit (1);
+	}
       mu_mailbox_get_property (mbox, &prop);
       mu_property_set_value (prop, "cur", mu_umaxtostr (0, uid), 1);
     }
@@ -1008,21 +1010,13 @@ mh_draft_message (const char *name, const char *msgspec, char **pname)
 	}
       mh_msgset_free (&msgset);
     }
-  
-  if (rc == 0)
+
+  mu_url_sget_path (url, &path);
+  rc = mu_asprintf (pname, "%s/%lu", path, (unsigned long) uid);
+  if (rc)
     {
-      const char *dir;
-      const char *msg;
-      size_t len;
-      
-      dir = urlstr + 3; /* FIXME */
-      
-      msg = mu_umaxtostr (0, uid);
-      len = strlen (dir) + 1 + strlen (msg) + 1;
-      *pname = xmalloc (len);
-      strcpy (*pname, dir);
-      strcat (*pname, "/");
-      strcat (*pname, msg);
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_asprintf", NULL, rc);
+      exit (1);
     }
   mu_mailbox_close (mbox);
   mu_mailbox_destroy (&mbox);
diff --git a/mh/mh_msgset.c b/mh/mh_msgset.c
index fd0287f..e3e286c 100644
--- a/mh/mh_msgset.c
+++ b/mh/mh_msgset.c
@@ -19,27 +19,6 @@
 
 #include <mh.h>
 
-int
-mh_uid_to_msgno (mu_mailbox_t mbox, size_t uid, size_t *msgno)
-{
-  size_t num = mh_get_message (mbox, uid, NULL);
-  if (num == 0)
-    return MU_ERR_NOENT;
-  *msgno = num;
-  return 0;
-}
-
-int
-mh_msgno_to_uid (mu_mailbox_t mbox, size_t msgno, size_t *uid)
-{
-  mu_message_t msg;
-  int rc = mu_mailbox_get_message (mbox, msgno, &msg);
-  if (rc)
-    return rc;
-  return mu_message_get_uid (msg, uid);
-}
-
-
 void
 mh_msgset_init (mh_msgset_t *msgset)
 {
@@ -196,75 +175,6 @@ mh_msgset_uids (mu_mailbox_t mbox, mh_msgset_t *msgset)
     }
   msgset->flags |= MH_MSGSET_UID;
 }
-
-/* Auxiliary function. Performs binary search for a message with the
-   given sequence number */
-static size_t
-mh_search_message (mu_mailbox_t mbox, size_t start, size_t stop,
-		   size_t seqno, mu_message_t *mesg)
-{
-  mu_message_t mid_msg = NULL;
-  size_t num = 0, middle;
-
-  middle = (start + stop) / 2;
-  if (mu_mailbox_get_message (mbox, middle, &mid_msg)
-      || mh_message_number (mid_msg, &num))
-    return 0;
-
-  if (num == seqno)
-    {
-      if (mesg)
-	*mesg = mid_msg;
-      return middle;
-    }
-      
-  if (start >= stop)
-    return 0;
-
-  if (num > seqno)
-    return mh_search_message (mbox, start, middle-1, seqno, mesg);
-  else /*if (num < seqno)*/
-    return mh_search_message (mbox, middle+1, stop, seqno, mesg);
-}
-
-/* Retrieve the message with the given sequence number.
-   Returns ordinal number of the message in the mailbox if found,
-   zero otherwise. The retrieved message is stored in the location
-   pointed to by mesg, unless it is NULL. */
-   
-size_t
-mh_get_message (mu_mailbox_t mbox, size_t seqno, mu_message_t *mesg)
-{
-  size_t num, count;
-  mu_message_t msg;
-
-  if (mu_mailbox_get_message (mbox, 1, &msg)
-      || mh_message_number (msg, &num))
-    return 0;
-  if (seqno < num)
-    return 0;
-  else if (seqno == num)
-    {
-      if (mesg)
-	*mesg = msg;
-      return 1;
-    }
-
-  if (mu_mailbox_messages_count (mbox, &count)
-      || mu_mailbox_get_message (mbox, count, &msg)
-      || mh_message_number (msg, &num))
-    return 0;
-  if (seqno > num)
-    return 0;
-  else if (seqno == num)
-    {
-      if (mesg)
-	*mesg = msg;
-      return count;
-    }
-
-  return mh_search_message (mbox, 1, count, seqno, mesg);
-}
 
 
 struct msgset_parser
@@ -415,7 +325,7 @@ msgset_cur (mu_mailbox_t mbox, size_t *pnum)
 {
   size_t num;
   mh_mailbox_get_cur (mbox, &num);
-  return mh_uid_to_msgno (mbox, num, pnum);
+  return mu_mailbox_translate (mbox, MU_MAILBOX_UID_TO_MSGNO, num, pnum);
 }
 
 static int
@@ -518,7 +428,8 @@ parse_term (struct msgset_parser *parser, int seq)
       if (endp != parser->curp)
 	msgset_abort (term);
       
-      if (mh_uid_to_msgno (parser->mbox, num, &parser->number))
+      if (mu_mailbox_translate (parser->mbox, MU_MAILBOX_UID_TO_MSGNO,
+				num, &parser->number))
 	{
 	  parser->validuid = 0;
 	  parser->number = num;
@@ -617,7 +528,8 @@ parse_range (struct msgset_parser *parser)
 	{
 	  size_t total, lastuid;
 	  msgset_last (parser->mbox, &total);
-	  mh_msgno_to_uid (parser->mbox, total, &lastuid);
+	  mu_mailbox_translate (parser->mbox, MU_MAILBOX_MSGNO_TO_UID,
+				total, &lastuid);
 	  if (start > lastuid)
 	    {
 	      if (!parser->sign)
@@ -647,7 +559,9 @@ parse_range (struct msgset_parser *parser)
 	  size_t total;
 
 	  msgset_last (parser->mbox, &total);
-	  mh_msgno_to_uid (parser->mbox, total, &lastuid);
+	  mu_mailbox_translate (parser->mbox, MU_MAILBOX_MSGNO_TO_UID,
+				total, &lastuid);
+
 	  if (parser->number > lastuid)
 	    parser->number = total;
 	  else if (!validuid)
@@ -659,7 +573,8 @@ parse_range (struct msgset_parser *parser)
 	    {
 	      size_t total;
 	      msgset_last (parser->mbox, &total);
-	      mh_msgno_to_uid (parser->mbox, total, &lastuid);
+	      mu_mailbox_translate (parser->mbox, MU_MAILBOX_MSGNO_TO_UID,
+				    total, &lastuid);
 	    }
 	  if (start > lastuid && !parser->validuid)
 	    emptyrange_abort (parser->argv[-1]);
@@ -720,3 +635,29 @@ mh_msgset_parse (mu_mailbox_t mbox, mh_msgset_t *msgset,
 
   mh_msgset_optimize (msgset);
 }
+
+
+/* Retrieve the message with the given sequence number.
+   Returns ordinal number of the message in the mailbox if found,
+   zero otherwise. The retrieved message is stored in the location
+   pointed to by mesg, unless it is NULL. */
+   
+size_t
+mh_get_message (mu_mailbox_t mbox, size_t seqno, mu_message_t *mesg)
+{
+  int rc;
+  size_t num;
+
+  if (mu_mailbox_translate (mbox, MU_MAILBOX_UID_TO_MSGNO, seqno, &num))
+    return 0;
+  if (mesg)
+    {
+      rc = mu_mailbox_get_message (mbox, num, mesg);
+      if (rc)
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_message", NULL, rc);
+	  exit (1);
+	}
+    }
+  return num;
+}
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index 54a61b1..b1b53ff 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -143,6 +143,61 @@ Subject: test input
 message body
 ])
 
+MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder],[
+mkdir Mail/drafts
+dir=`pwd`
+echo 'quit' | compcmd -draftfolder drafts | sed "s|$dir/*||;s|  *$||"
+cat Mail/drafts/1
+],
+[0],
+[-- Editor invocation: Mail/drafts/1
+-- Input file:
+To:
+cc:
+Subject:
+--------
+-- Input file end
+What now? draft left on "Mail/drafts/1".
+To:
+cc:
+Subject:
+--------
+Seen by mhed
+])
+
+MH_CHECK([comp +draftfolder -use],[comp06 comp-draftfolder-use],[
+mkdir Mail/drafts
+AT_DATA([Mail/drafts/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+echo "cur: 1" > Mail/drafts/.mh_sequences
+
+dir=`pwd`
+echo 'quit' | compcmd -draftfolder drafts -use| sed "s|$dir/*||;s|  *$||"
+cat Mail/drafts/1
+],
+[0],
+[-- Editor invocation: Mail/drafts/1
+-- Input file:
+From: gray
+To: root
+Subject: test input
+
+message body
+-- Input file end
+What now? draft left on "Mail/drafts/1".
+From: gray
+To: root
+Subject: test input
+
+message body
+Seen by mhed
+])
+
+
 m4_popdef([compcmd])
 m4_popdef([MH_KEYWORDS])
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 23 10:01:07 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PKuMl-0006Ek-GS
	for mharc-commit-mailutils@gnu.org; Tue, 23 Nov 2010 10:01:07 -0500
Received: from [140.186.70.92] (port=42722 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PKuM2-0003Yx-Dc
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 10:01:04 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKuJj-0004A0-3P
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 09:58:41 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:35326
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKuJj-00049k-1Y
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 09:57:59 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKuJi-0007dg-Ch
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 14:57:58 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PKuJV-0007kC-Ub
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 14:57:53 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 46b844cf0c0623dd370573ce6da21dd8aa6fd907
X-Git-Newrev: 39160956df0ea814c08af4d60adb3bac63bd41f7
Message-Id: <E1PKuJV-0007kC-Ub@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 23 Nov 2010 14:57:46 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-211-g3916095
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Nov 2010 15:01:05 -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=39160956df0ea814c08af4d60adb3bac63bd41f7

The branch, master has been updated
       via  39160956df0ea814c08af4d60adb3bac63bd41f7 (commit)
      from  46b844cf0c0623dd370573ce6da21dd8aa6fd907 (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 39160956df0ea814c08af4d60adb3bac63bd41f7
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 23 16:01:01 2010 +0200

    mh: improve forw; add tests.
    
    * mh/forw.c (options): New option --file.
    (input_file): New variable.
    (opt_handler): Handle --file.
    (finish_draft): Remove a leftover path hack.
    Implement raw file forwarding.
    (main): Minor fix.
    * mh/mh_getopt.c (mh_option_init): Limit match_len to the actual
    length of the option string.
    
    * mh/tests/forw.at: New file.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add forw.at.
    * mh/tests/testsuite.at: Include forw.at.
    * mh/tests/comp.at: Add more keywords.

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

Summary of changes:
 mh/forw.c             |  268 ++++++++++++++++++++++++--------------
 mh/mh_getopt.c        |    6 +-
 mh/tests/Makefile.am  |    1 +
 mh/tests/comp.at      |    5 +-
 mh/tests/forw.at      |  348 +++++++++++++++++++++++++++++++++++++++++++++++++
 mh/tests/testsuite.at |    1 +
 6 files changed, 526 insertions(+), 103 deletions(-)
 create mode 100644 mh/tests/forw.at

diff --git a/mh/forw.c b/mh/forw.c
index a41c968..4b12bb3 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -42,6 +42,8 @@ static struct argp_option options[] = {
    N_("set the editor program to use")},
   {"noedit",        ARG_NOEDIT,        0, 0,
    N_("suppress the initial edit")},
+  {"file",          ARG_FILE, N_("FILE"), 0,
+   N_("read message from FILE")},
   {"format",        ARG_FORMAT,        N_("BOOL"), 0, 
    N_("format messages")},
   {"noformat",      ARG_NOFORMAT,      NULL, 0,
@@ -74,26 +76,28 @@ static struct argp_option options[] = {
 struct mh_option mh_option[] = {
   { "annotate",      MH_OPT_BOOL },
   { "build" },
-  { "form",          MH_OPT_ARG, "formatfile"},
-  { "format",        MH_OPT_ARG, "string"},
-  { "draftfolder",   MH_OPT_ARG, "folder"},
+  { "file",          MH_OPT_ARG, "msgfile" },
+  { "form",          MH_OPT_ARG, "formatfile" },
+  { "format",        MH_OPT_ARG, "string" },
+  { "draftfolder",   MH_OPT_ARG, "folder" },
   { "nodraftfolder" },
   { "draftmessage" },
-  { "editor",        MH_OPT_ARG, "program"},
+  { "editor",        MH_OPT_ARG, "program" },
   { "noedit" },
-  { "filter",        MH_OPT_ARG, "program"},
+  { "filter",        MH_OPT_ARG, "program" },
   { "inplace",       MH_OPT_BOOL },
-  { "whatnowproc",   MH_OPT_ARG, "program"},
+  { "whatnowproc",   MH_OPT_ARG, "program" },
   { "nowhatnowproc" },
   { "mime",          MH_OPT_BOOL },
   { NULL }
 };
 
-enum encap_type {
-  encap_clear,
-  encap_mhl,
-  encap_mime
-};
+enum encap_type
+  {
+    encap_clear,
+    encap_mhl,
+    encap_mime
+  };
 
 static char *formfile;
 struct mh_whatnow_env wh_env = { 0 };
@@ -108,6 +112,7 @@ static int use_draft = 0;       /* --use flag */
 static int width = 80;          /* --width flag */
 static char *draftmessage = "new";
 static const char *draftfolder = NULL;
+static char *input_file;        /* input file name (--file option) */
 
 static mh_msgset_t msgset;
 static mu_mailbox_t mbox;
@@ -118,8 +123,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
   switch (key)
     {
     case ARGP_KEY_INIT:
-      draftfolder = mh_global_profile_get ("Draft-Folder",
-					   mu_folder_directory ());
+      draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
       whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
       break;
 
@@ -131,6 +135,10 @@ opt_handler (int key, char *arg, struct argp_state *state)
       build_only = 1;
       break;
 
+    case ARG_FILE:
+      input_file = arg;
+      break;
+      
     case ARG_DRAFTFOLDER:
       draftfolder = arg;
       break;
@@ -218,7 +226,8 @@ opt_handler (int key, char *arg, struct argp_state *state)
   return 0;
 }
 
-struct format_data {
+struct format_data
+{
   int num;
   mu_stream_t stream;
   mu_list_t format;
@@ -286,26 +295,41 @@ msg_copy (mu_message_t msg, mu_stream_t ostream)
 }
 
 void
-format_message (mu_mailbox_t mbox, mu_message_t msg, size_t num, void *data)
+format_message (mu_stream_t outstr, mu_message_t msg, int num,
+		mu_list_t format)
 {
-  struct format_data *fp = data;
-  char *s;
-  int rc;
+  int rc = 0;
   
   if (annotate)
     mu_list_append (wh_env.anno_list, msg);
   
-  if (fp->num)
+  if (num)
+    rc = mu_stream_printf (outstr, "\n------- Message %d\n", num);
+
+  if (rc == 0)
+    {
+      if (format)
+	rc = mhl_format_run (format, width, 0, 0, msg, outstr);
+      else
+	rc = msg_copy (msg, outstr);
+    }
+  
+  if (rc)
     {
-      mu_asprintf (&s, "\n------- Message %d\n", fp->num++);
-      rc = mu_stream_write (fp->stream, s, strlen (s), NULL);
-      free (s);
+      mu_error (_("cannot copy message: %s"), mu_strerror (rc));
+      exit (1);
     }
+}
 
-  if (fp->format)
-    rc = mhl_format_run (fp->format, width, 0, 0, msg, fp->stream);
-  else
-    rc = msg_copy (msg, fp->stream);
+void
+format_message_itr (mu_mailbox_t mbox MU_ARG_UNUSED,
+		    mu_message_t msg, size_t num, void *data)
+{
+  struct format_data *fp = data;
+
+  format_message (fp->stream, msg, fp->num, fp->format);
+  if (fp->num)
+    fp->num++;
 }
 
 void
@@ -317,23 +341,6 @@ finish_draft ()
   struct format_data fd;
   char *str;
   
-  if (!mhl_filter)
-    {
-      char *s = mh_expand_name (MHLIBDIR, "mhl.forward", 0);
-      if (access (s, R_OK) == 0)
-	mhl_filter = "mhl.forward";
-      free (s);
-    }
-
-  if (mhl_filter)
-    {
-      char *s = mh_expand_name (MHLIBDIR, mhl_filter, 0);
-      format = mhl_format_compile (s);
-      if (!format)
-	exit (1);
-      free (s);
-    }
-  
   if ((rc = mu_file_stream_create (&stream,
 				   wh_env.file,
 				   MU_STREAM_WRITE|MU_STREAM_CREAT)))
@@ -345,73 +352,120 @@ finish_draft ()
 
   mu_stream_seek (stream, 0, SEEK_END, NULL);
 
-  if (annotate)
+  if (input_file)
     {
-      wh_env.anno_field = "Forwarded";
-      mu_list_create (&wh_env.anno_list);
-    }
+      mu_stream_t instr;
+      int rc;
   
-  if (encap == encap_mime)
-    {
-      mu_url_t url;
-      const char *mbox_path;
-      const char *p;
-      size_t i;
-      
-      mu_mailbox_get_url (mbox, &url);
+      if ((rc = mu_file_stream_create (&stream,
+				       wh_env.file,
+				       MU_STREAM_WRITE|MU_STREAM_CREAT)))
+	{
+	  mu_error (_("cannot open output file `%s': %s"),
+		    wh_env.file, mu_strerror (rc));
+	  exit (1);
+	}
+
+      mu_stream_seek (stream, 0, SEEK_END, NULL);
       
-      mbox_path = mu_url_to_string (url);
-      if (memcmp (mbox_path, "mh:", 3) == 0)
-	mbox_path += 3;
-      mu_asprintf (&str, "#forw [] +%s", mbox_path);
-      rc = mu_stream_write (stream, str, strlen (str), NULL);
-      free (str);
-      for (i = 0; rc == 0 && i < msgset.count; i++)
+      rc = mu_file_stream_create (&instr, input_file, MU_STREAM_READ);
+      if (rc)
 	{
-          mu_message_t msg;
-	  size_t num;
-		  
-	  mu_mailbox_get_message (mbox, msgset.list[i], &msg);
-	  if (annotate)
-	    mu_list_append (wh_env.anno_list, msg);
-	  mh_message_number (msg, &num);
-          p = mu_umaxtostr (0, num);
-          rc = mu_stream_write (stream, p, strlen (p), NULL);
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_file_stream_create",
+			   input_file, rc);
+	  exit (1);
 	}
+      
+      rc = mu_stream_copy (stream, instr, 0, NULL);
+      mu_stream_unref (instr);
     }
   else
     {
-      str = "\n------- ";
-      rc = mu_stream_write (stream, str, strlen (str), NULL);
-
-      if (msgset.count == 1)
+      if (!mhl_filter)
 	{
-	  fd.num = 0;
-	  str = (char*) _("Forwarded message\n");
+	  char *s = mh_expand_name (MHLIBDIR, "mhl.forward", 0);
+	  if (access (s, R_OK) == 0)
+	    mhl_filter = "mhl.forward";
+	  free (s);
 	}
-      else
+      
+      if (mhl_filter)
 	{
-	  fd.num = 1;
-	  str = (char*) _("Forwarded messages\n");
+	  char *s = mh_expand_name (MHLIBDIR, mhl_filter, 0);
+	  format = mhl_format_compile (s);
+	  if (!format)
+	    exit (1);
+	  free (s);
 	}
   
-      rc = mu_stream_write (stream, str, strlen (str), NULL);
-      fd.stream = stream;
-      fd.format = format;
-      rc = mh_iterate (mbox, &msgset, format_message, &fd);
+      if (annotate)
+	{
+	  wh_env.anno_field = "Forwarded";
+	  mu_list_create (&wh_env.anno_list);
+	}
       
-      str = "\n------- ";
-      rc = mu_stream_write (stream, str, strlen (str), NULL);
+      if (encap == encap_mime)
+	{
+	  mu_url_t url;
+	  const char *mbox_path;
+	  const char *p;
+	  size_t i;
       
-      if (msgset.count == 1)
-	str = (char*) _("End of Forwarded message");
+	  mu_mailbox_get_url (mbox, &url);
+	  mu_url_sget_path (url, &mbox_path);
+	  mu_asprintf (&str, "#forw [] +%s", mbox_path);
+	  rc = mu_stream_write (stream, str, strlen (str), NULL);
+	  free (str);
+	  for (i = 0; rc == 0 && i < msgset.count; i++)
+	    {
+	      mu_message_t msg;
+	      size_t num;
+	      
+	      mu_mailbox_get_message (mbox, msgset.list[i], &msg);
+	      if (annotate)
+		mu_list_append (wh_env.anno_list, msg);
+	      mh_message_number (msg, &num);
+	      p = mu_umaxtostr (0, num);
+	      rc = mu_stream_write (stream, " ", 1, NULL);
+	      if (rc)
+		break;
+	      rc = mu_stream_write (stream, p, strlen (p), NULL);
+	    }
+	}
       else
-	str = (char*) _("End of Forwarded messages");
+	{
+	  str = "\n------- ";
+	  rc = mu_stream_write (stream, str, strlen (str), NULL);
+	  
+	  if (msgset.count == 1)
+	    {
+	      fd.num = 0;
+	      str = (char*) _("Forwarded message\n");
+	    }
+	  else
+	    {
+	      fd.num = 1;
+	      str = (char*) _("Forwarded messages\n");
+	    }
+	  
+	  rc = mu_stream_write (stream, str, strlen (str), NULL);
+	  fd.stream = stream;
+	  fd.format = format;
+	  rc = mh_iterate (mbox, &msgset, format_message_itr, &fd);
+      
+	  str = "\n------- ";
+	  rc = mu_stream_write (stream, str, strlen (str), NULL);
+	  
+	  if (msgset.count == 1)
+	    str = (char*) _("End of Forwarded message");
+	  else
+	    str = (char*) _("End of Forwarded messages");
+	  
+	  rc = mu_stream_write (stream, str, strlen (str), NULL);
+	}
       
-      rc = mu_stream_write (stream, str, strlen (str), NULL);
+      rc = mu_stream_write (stream, "\n\n", 2, NULL);
     }
-  
-  rc = mu_stream_write (stream, "\n\n", 2, NULL);
   mu_stream_close (stream);
   mu_stream_destroy (&stream);
 }
@@ -431,27 +485,43 @@ main (int argc, char **argv)
   argc -= index;
   argv += index;
 
-  mbox = mh_open_folder (mh_current_folder (), 0);
-  mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
+  if (input_file)
+    {
+      if (encap == encap_mime)
+	{
+	  mu_error (_("--build disables --mime"));
+	  encap = encap_clear;
+	}
+      if (argc)
+	{
+	  mu_error (_("can't mix files and folders/msgs"));
+	  exit (1);
+	}
+    }
+  else
+    {
+      mbox = mh_open_folder (mh_current_folder (), 0);
+      mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
+    }
   
   if (build_only || !draftfolder)
     wh_env.file = mh_expand_name (NULL, "draft", 0);
-  else 
+  else if (draftfolder)
     {
-      if (mh_draft_message (NULL, draftmessage, &wh_env.file))
+      if (mh_draft_message (draftfolder, draftmessage, &wh_env.file))
 	return 1;
     }
   wh_env.draftfile = wh_env.file;
 
   switch (build_only ?
-	    DISP_REPLACE : check_draft_disposition (&wh_env, use_draft))
+	  DISP_REPLACE : check_draft_disposition (&wh_env, use_draft))
     {
     case DISP_QUIT:
       exit (0);
-
+      
     case DISP_USE:
       break;
-	  
+      
     case DISP_REPLACE:
       unlink (wh_env.draftfile);
       mh_comp_draft (formfile, "forwcomps", wh_env.file);
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 748db10..88211c1 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -187,7 +187,8 @@ mh_option_init (struct mh_option *opt)
 	    do
 	      {
 		minlen++;
-		opt[j].match_len = minlen;
+		if (minlen <= strlen (opt[j].opt))
+		  opt[j].match_len = minlen;
 		if (minlen == sample_len)
 		  break;
 	      }
@@ -197,7 +198,8 @@ mh_option_init (struct mh_option *opt)
 	  else
 	    break;
 	}
-      opt[i].match_len = minlen;
+      if (minlen <= sample_len)
+	opt[i].match_len = minlen;
     }
 }
 
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 00c00ed..72f470f 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -44,6 +44,7 @@ TESTSUITE_AT = \
  burst.at\
  comp.at\
  folder.at\
+ forw.at\
  inc.at\
  install-mh.at\
  mark.at\
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index b1b53ff..ced3de9 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -143,7 +143,7 @@ Subject: test input
 message body
 ])
 
-MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder],[
+MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
 mkdir Mail/drafts
 dir=`pwd`
 echo 'quit' | compcmd -draftfolder drafts | sed "s|$dir/*||;s|  *$||"
@@ -165,7 +165,7 @@ Subject:
 Seen by mhed
 ])
 
-MH_CHECK([comp +draftfolder -use],[comp06 comp-draftfolder-use],[
+MH_CHECK([comp +draftfolder -use],[comp06 comp-draftfolder-use draftfolder],[
 mkdir Mail/drafts
 AT_DATA([Mail/drafts/1],[From: gray
 To: root
@@ -201,3 +201,4 @@ Seen by mhed
 m4_popdef([compcmd])
 m4_popdef([MH_KEYWORDS])
 
+# End of comp.at
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
new file mode 100644
index 0000000..9d4b31d
--- /dev/null
+++ b/mh/tests/forw.at
@@ -0,0 +1,348 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([MH_KEYWORDS],[forw])
+m4_pushdef([forwcmd],[forw dnl
+-form $abs_top_srcdir/mh/components dnl
+-editor $abs_top_srcdir/mh/tests/mhed])
+
+MH_CHECK([forw msg],[forw00 forw-msg],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+dir=`pwd`
+echo quit | forwcmd +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/draft ==
+cat Mail/draft
+echo == Message ==
+# FIXME: AMD adds this header to the first message.  Find a better way.
+# See also the same sed hacks below.
+sed '/^X-IMAPbase/d' Mail/inbox/1
+],
+[0],
+[-- Editor invocation: Mail/draft
+-- Input file:
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+-- Input file end
+What now? draft left on "Mail/draft".
+== Mail/draft ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+Seen by mhed
+== Message ==
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+MH_CHECK([forw msgs],[forw01 forw-msgs],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+AT_DATA([Mail/inbox/2],[From: gray
+To: marlow
+Subject: 2nd message
+
+2nd message body
+])
+
+dir=`pwd`
+echo quit | forwcmd +inbox 1 2 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/draft ==
+cat Mail/draft
+echo == Message 1 ==
+sed '/^X-IMAPbase/d' Mail/inbox/1
+echo == Message 2 ==
+cat Mail/inbox/2
+],
+[0],
+[-- Editor invocation: Mail/draft
+-- Input file:
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded messages
+
+------- Message 1
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- Message 2
+From: gray
+To: marlow
+Subject: 2nd message
+
+2nd message body
+
+------- End of Forwarded messages
+
+-- Input file end
+What now? draft left on "Mail/draft".
+== Mail/draft ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded messages
+
+------- Message 1
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- Message 2
+From: gray
+To: marlow
+Subject: 2nd message
+
+2nd message body
+
+------- End of Forwarded messages
+
+Seen by mhed
+== Message 1 ==
+From: gray
+To: root
+Subject: test input
+
+message body
+== Message 2 ==
+From: gray
+To: marlow
+Subject: 2nd message
+
+2nd message body
+])
+
+MH_CHECK([forw -build msg],[forw02 forw-build-msg],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+dir=`pwd`
+forwcmd -build +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/draft ==
+cat Mail/draft
+echo == Message ==
+sed '/^X-IMAPbase/d' Mail/inbox/1
+],
+[0],
+[== Mail/draft ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+== Message ==
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+MH_CHECK([forw -build -mime msgs],[forw03 forw-build-mime-msg],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+AT_DATA([Mail/inbox/2],[From: gray
+To: marlow
+Subject: 2nd message
+
+2nd message body
+])
+
+dir=`pwd`
+forwcmd -build -mime +inbox 1 2 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/draft ==
+sed "s|$dir/*||;s|  *$||" Mail/draft
+echo == Message 1 ==
+sed '/^X-IMAPbase/d' Mail/inbox/1
+echo == Message 2 ==
+cat Mail/inbox/2
+],
+[0],
+[== Mail/draft ==
+To:
+cc:
+Subject:
+--------
+#forw [] +Mail/inbox 1 2
+
+== Message 1 ==
+From: gray
+To: root
+Subject: test input
+
+message body
+== Message 2 ==
+From: gray
+To: marlow
+Subject: 2nd message
+
+2nd message body
+])
+
+MH_CHECK([forw -draftfolder],[forw04 forw-draftfolder draftfolder],[
+mkdir Mail/inbox
+mkdir Mail/drafts
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+echo "quit" | forwcmd -draftfolder drafts 1 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/drafts/1 ==
+cat Mail/drafts/1
+echo == Message ==
+sed '/^X-IMAPbase/d' Mail/inbox/1
+],
+[0],
+[-- Editor invocation: Mail/drafts/1
+-- Input file:
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+-- Input file end
+What now? draft left on "Mail/drafts/1".
+== Mail/drafts/1 ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From: gray
+To: root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+Seen by mhed
+== Message ==
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+MH_CHECK([forw -file],[forw05 forw-file],[
+AT_DATA([infile],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+echo "quit" | forwcmd -file infile | sed "s|$dir/*||;s|  *$||"
+],
+[0],
+[-- Editor invocation: Mail/draft
+-- Input file:
+To:
+cc:
+Subject:
+--------
+From: gray
+To: root
+Subject: test input
+
+message body
+-- Input file end
+What now? draft left on "Mail/draft".
+])
+
+m4_popdef([forwcmd])
+m4_popdef([MH_KEYWORDS])
+
+# End of forw.at
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index a18976d..1e07c4a 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -58,3 +58,4 @@ m4_include([anno.at])
 m4_include([pick.at])
 m4_include([burst.at])
 m4_include([comp.at])
+m4_include([forw.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Nov 23 18:36:06 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PL2P8-0005jp-R8
	for mharc-commit-mailutils@gnu.org; Tue, 23 Nov 2010 18:36:06 -0500
Received: from [140.186.70.92] (port=48040 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PL2Ox-0005iO-3e
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 18:36:05 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PL2Or-0007bn-6A
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 18:35:55 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:36155
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PL2Or-0007bf-4H
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 18:35:49 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PL2Oq-0005If-Rh
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 23:35:48 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PL2Oj-0007Qg-DN
	for commit-mailutils@gnu.org; Tue, 23 Nov 2010 23:35:48 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 39160956df0ea814c08af4d60adb3bac63bd41f7
X-Git-Newrev: 27f9a867f4fcfaf29a22349043eaddcb60c2694e
Message-Id: <E1PL2Oj-0007Qg-DN@vcs-noshell.in.savannah.gnu.org>
Date: Tue, 23 Nov 2010 23:35:41 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-214-g27f9a86
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 23 Nov 2010 23:36:05 -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=27f9a867f4fcfaf29a22349043eaddcb60c2694e

The branch, master has been updated
       via  27f9a867f4fcfaf29a22349043eaddcb60c2694e (commit)
       via  43853ce85b785d36b44b6850ceac7136c54f54f0 (commit)
       via  764ebfd7f22dd2634413f1d427ab0f51b0b7797b (commit)
      from  39160956df0ea814c08af4d60adb3bac63bd41f7 (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 27f9a867f4fcfaf29a22349043eaddcb60c2694e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 01:32:55 2010 +0200

    Fix body start calculation in message_stream. Fix compose parser in mhn.
    
    * libmailutils/stream/message_stream.c (scan_stream): Merge
    with _message_open.
    * mh/mhn.c (edit_forw): Do not set ws_delim.
    Fix message addressing.
    (mhn_edit): Remove the trailing newline.

commit 43853ce85b785d36b44b6850ceac7136c54f54f0
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 00:13:41 2010 +0200

    mh: implement rmmproc.
    
    * include/mailutils/sys/amd.h (_amd_data) <delete_msg>: New method.
    * libmailutils/base/amd.c (amd_expunge): If delete_msg is defined,
    use it.
    * libproto/mh/mbox.c (_mh_msg_delete): New method.
    (_mailbox_mh_init): Set delete_msg if "rmmproc" component is
    defined.
    
    * mh/tests/movemsg: New file.
    * mh/tests/Makefile.am (EXTRA_DIST): Add movemsg.
    * mh/tests/rmm.at: Test rmmproc effects.
    * mh/tests/rmf.at (MH_KEYWORDS): Fix copy-n-paste error.
    
    * doc/texinfo/mu-mh.texi: Document rmmproc.
    * mh/TODO: Update.

commit 764ebfd7f22dd2634413f1d427ab0f51b0b7797b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Nov 23 20:40:09 2010 +0200

    mh: add repl tests.
    
    * mh/repl.c: Minor changes.
    * tests/repl.at: New file.
    * tests/Makefile.am (TESTSUITE_AT): Add repl.at
    * mh/tests/testsuite.at: Include repl.at.
    * mh/TODO: Update.

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

Summary of changes:
 doc/texinfo/mu-mh.texi               |    7 ++-
 include/mailutils/sys/amd.h          |    3 +-
 libmailutils/base/amd.c              |   61 ++++++++++--------
 libmailutils/stream/message_stream.c |  115 +++++++++++++--------------------
 libproto/mh/mbox.c                   |   36 +++++++++++
 mh/TODO                              |    6 +-
 mh/mhn.c                             |   20 +++++-
 mh/repl.c                            |    6 +-
 mh/tests/Makefile.am                 |    3 +-
 mh/tests/repl.at                     |   82 ++++++++++++++++++++++++
 mh/tests/rmf.at                      |    2 +-
 mh/tests/rmm.at                      |   31 +++++++++
 mh/tests/testsuite.at                |    1 +
 13 files changed, 263 insertions(+), 110 deletions(-)
 create mode 100644 mh/tests/repl.at

diff --git a/doc/texinfo/mu-mh.texi b/doc/texinfo/mu-mh.texi
index 99ebaeb..f231a69 100644
--- a/doc/texinfo/mu-mh.texi
+++ b/doc/texinfo/mu-mh.texi
@@ -427,7 +427,12 @@ Mailutils @command{rmm} does not delete any messages. Standard
 non-existent one. 
 
 @item
-The @code{rmmproc} profile component is not used.
+The @command{rmm} utility will unlink messages, if the @code{rmmproc}
+profile component has empty value, e.g.:
+
+@example
+rmmproc:
+@end example
 @end enumerate
 
 @item sortm
diff --git a/include/mailutils/sys/amd.h b/include/mailutils/sys/amd.h
index 2f921a3..fde26da 100644
--- a/include/mailutils/sys/amd.h
+++ b/include/mailutils/sys/amd.h
@@ -82,7 +82,8 @@ struct _amd_data
   int (*message_uid) (mu_message_t msg, size_t *puid);
   size_t (*next_uid) (struct _amd_data *mhd);
   int (*remove) (struct _amd_data *);
-  
+  int (*delete_msg) (struct _amd_data *, struct _amd_message *);
+		     
   /* List of messages: */
   size_t msg_count; /* number of messages in the list */
   size_t msg_max;   /* maximum message buffer capacity */
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index acbfb29..d51f941 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -1166,37 +1166,46 @@ amd_expunge (mu_mailbox_t mailbox)
       if (mhm->attr_flags & MU_ATTRIBUTE_DELETED)
 	{
 	  int rc;
-	  char *old_name;
-	  char *new_name;
 
-	  rc = amd->cur_msg_file_name (mhm, &old_name);
-	  if (rc)
-	    return rc;
-	  rc = amd->new_msg_file_name (mhm, mhm->attr_flags, 1,
-				       &new_name);
-	  if (rc)
+	  if (amd->delete_msg)
 	    {
-	      free (old_name);
-	      return rc;
-	    }
-
-	  if (new_name)
-	    {
-	      /* FIXME: It may be a good idea to have a capability flag
-		 in struct _amd_data indicating that no actual removal
-		 is needed (e.g. for traditional MH). It will allow to
-		 bypass lots of no-op code here. */
-	      if (strcmp (old_name, new_name))
-		/* Rename original message */
-		rename (old_name, new_name);
+	      rc = amd->delete_msg (amd, mhm);
+	      if (rc)
+		return rc;
 	    }
 	  else
-	    /* Unlink original file */
-	    unlink (old_name);
-	  
-	  free (old_name);
-	  free (new_name);
+	    {
+	      char *old_name;
+	      char *new_name;
+
+	      rc = amd->cur_msg_file_name (mhm, &old_name);
+	      if (rc)
+		return rc;
+	      rc = amd->new_msg_file_name (mhm, mhm->attr_flags, 1,
+					   &new_name);
+	      if (rc)
+		{
+		  free (old_name);
+		  return rc;
+		}
 
+	      if (new_name)
+		{
+		  /* FIXME: It may be a good idea to have a capability flag
+		     in struct _amd_data indicating that no actual removal
+		     is needed (e.g. for traditional MH). It will allow to
+		     bypass lots of no-op code here. */
+		  if (strcmp (old_name, new_name))
+		    /* Rename original message */
+		    rename (old_name, new_name);
+		}
+	      else
+		/* Unlink original file */
+		unlink (old_name);
+	      
+	      free (old_name);
+	      free (new_name);
+	    }
 	  _amd_message_delete (amd, mhm);
 	  updated = 1;
 	  /* Do not increase i! */
diff --git a/libmailutils/stream/message_stream.c b/libmailutils/stream/message_stream.c
index 189eb0f..b4f728e 100644
--- a/libmailutils/stream/message_stream.c
+++ b/libmailutils/stream/message_stream.c
@@ -145,51 +145,62 @@ copy_trimmed_value (const char *str)
 }
   
 static int
-scan_stream (struct _mu_message_stream *str)
+_message_open (mu_stream_t stream)
 {
+  struct _mu_message_stream *str = (struct _mu_message_stream*) stream;
   char *from = NULL;
   char *env_from = NULL;
   char *env_date = NULL;
   int rc;
   char *buffer = NULL;
   size_t bufsize = 0;
-  size_t len;
+  size_t offset, len;
   mu_off_t body_start, body_end;
-  mu_stream_t stream = str->transport;
-
-  if (str->envelope)
+  mu_stream_t transport = str->transport;
+  
+  rc = mu_stream_seek (transport, 0, MU_SEEK_SET, NULL);
+  if (rc)
+    return rc;
+  offset = 0;
+  while ((rc = mu_stream_getline (transport, &buffer, &bufsize, &len)) == 0
+	 && len > 0)
     {
-      char *s = str->envelope + 5;
-      char *p = strchr (s, ' ');
-      size_t len;
-
-      if (p)
+      if (offset == 0 && memcmp (buffer, "From ", 5) == 0)
 	{
-	  len = p - s;
-	  env_from = mu_alloc (len + 1);
-	  if (!env_from)
+	  char *s, *p;
+	  
+	  str->envelope_length = len;
+	  str->envelope = mu_strdup (buffer);
+	  if (!str->envelope)
 	    return ENOMEM;
-	  memcpy (env_from, s, len);
-	  env_from[len] = 0;
-	  env_date = mu_strdup (p + 1);
-	  if (!env_date)
+	  str->envelope[len - 1] = 0;
+
+	  s = str->envelope + 5;
+	  p = strchr (s, ' ');
+
+	  if (p)
 	    {
-	      free (env_from);
-	      return ENOMEM;
+	      len = p - s;
+	      env_from = mu_alloc (len + 1);
+	      if (!env_from)
+		return ENOMEM;
+	      memcpy (env_from, s, len);
+	      env_from[len] = 0;
+	      env_date = mu_strdup (p + 1);
+	      if (!env_date)
+		{
+		  free (env_from);
+		  return ENOMEM;
+		}
 	    }
 	}
-    }
-
-  rc = mu_stream_seek (stream, 0, MU_SEEK_SET, NULL);
-  if (rc)
-    return rc;
-  while ((rc = mu_stream_getline (stream, &buffer, &bufsize, &len)) == 0
-	 && len > 0)
-    {
-      if (buffer[0] == '\n')
-	break;
-
-      if (!env_from || !env_date)
+      else if (mu_mh_delim (buffer))
+	{
+	  str->mark_offset = offset;
+	  str->mark_length = len - 1; /* do not count the terminating newline */
+	  break;
+	}
+      else if (!env_from || !env_date)
 	{
       	  if (!from && mu_c_strncasecmp (buffer, MU_HEADER_FROM,
 				         sizeof (MU_HEADER_FROM) - 1) == 0)
@@ -206,14 +217,15 @@ scan_stream (struct _mu_message_stream *str)
 	    env_date = copy_trimmed_value (buffer +
 					   sizeof (MU_HEADER_ENV_DATE));
 	}
+      offset += len;
     }
 
   free (buffer);
 
-  rc = mu_stream_seek (stream, 0, MU_SEEK_CUR, &body_start);
+  rc = mu_stream_seek (transport, 0, MU_SEEK_CUR, &body_start);
   if (rc)
     return rc;
-  rc = mu_stream_size (stream, &body_end);
+  rc = mu_stream_size (transport, &body_end);
   if (rc)
     return rc;
   
@@ -256,43 +268,6 @@ scan_stream (struct _mu_message_stream *str)
 }
 
 static int
-_message_open (mu_stream_t stream)
-{
-  struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
-  size_t offset, len;
-  char *buffer = NULL;
-  size_t bufsize = 0;
-  int rc;
-
-  offset = 0;
-  mu_stream_seek (s->transport, 0, MU_SEEK_SET, NULL);
-  while ((rc = mu_stream_getline (s->transport, &buffer, &bufsize,
-				  &len)) == 0
-	 && len > 0)
-    {
-      if (offset == 0 && memcmp (buffer, "From ", 5) == 0)
-	{
-	  s->envelope_length = len;
-	  s->envelope = mu_strdup (buffer);
-	  if (!s->envelope)
-	    return ENOMEM;
-	  s->envelope[len - 1] = 0;
-	}
-      else if (mu_mh_delim (buffer))
-	{
-	  s->mark_offset = offset;
-	  s->mark_length = len - 1; /* do not count the terminating newline */
-	  break;
-	}
-
-      offset += len;
-    }
-  free (buffer);
-
-  return scan_stream (s);
-}
-
-static int
 _message_close (mu_stream_t stream)
 {
   struct _mu_message_stream *s = (struct _mu_message_stream*) stream;
diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c
index c28aee5..82d0283 100644
--- a/libproto/mh/mbox.c
+++ b/libproto/mh/mbox.c
@@ -351,6 +351,38 @@ _mh_msg_init (struct _amd_data *amd, struct _amd_message *amm)
   return 0;
 }
 
+static int
+_mh_msg_delete (struct _amd_data *amd, struct _amd_message *amm)
+{
+  int rc, status;
+  char *name;
+  char *argv[3];
+  /* FIXME: Cache this value */
+  const char *proc = mu_mhprop_get_value (mu_mh_profile, "rmmproc", NULL);
+  if (!proc)
+    return ENOSYS;
+
+  rc = amd->cur_msg_file_name (amm, &name);
+  if (rc)
+    return rc;
+  
+  if (proc[0] == 0)
+    {
+      rc = unlink (name);
+      if (rc)
+	rc = errno;
+    }
+  else
+    {
+      argv[0] = (char*) proc;
+      argv[1] = name;
+      argv[2] = NULL;
+      rc = mu_spawnvp (proc, argv, &status);
+    }
+  free (name);
+  return rc;
+}
+
 
 static int
 mh_remove (struct _amd_data *amd)
@@ -442,6 +474,10 @@ _mailbox_mh_init (mu_mailbox_t mailbox)
 
   mailbox->_get_property = mh_get_property;
   mailbox->_translate = mh_translate;
+
+  if (mu_mhprop_get_value (mu_mh_profile, "rmmproc", NULL))
+    amd->delete_msg = _mh_msg_delete;
+    
   
   return 0;
 }
diff --git a/mh/TODO b/mh/TODO
index 7bc3a40..34724d1 100644
--- a/mh/TODO
+++ b/mh/TODO
@@ -19,13 +19,13 @@ State	Nice	Utility		Comments
 -------------------------------------------
 +	-20	scan
 +	-20	inc
-*	-20	repl		--inplace
+*	-20	repl		--inplace,--query
 +	-20	comp		
 *	-20	forw		--inplace
 *	-20	send		--alias,--filter,--format,--forward,--mime,
 				--width
-*	-20	refile		--link copies messages; rmmproc ignored.
-*	-20	rmm		rmproc:	
+*	-20	refile		--link copies messages
++	-20	rmm		
 +	-15	folder(s)	
 +	-15	mhn		
 +	-10	rmf
diff --git a/mh/mhn.c b/mh/mhn.c
index d66ef9b..5ddfece 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -2083,9 +2083,7 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level)
   if (status)
     return status;
 
-  ws.ws_delim = "\n";
-  if (mu_wordsplit (cmd, &ws,
-		    MU_WRDSF_DEFFLAGS | MU_WRDSF_DELIM | MU_WRDSF_WS))
+  if (mu_wordsplit (cmd, &ws, MU_WRDSF_DEFFLAGS))
     {
       mu_error (_("%s:%lu: cannot split line: %s"),
 		input_file,
@@ -2100,7 +2098,19 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level)
   for (i = 1; i < ws.ws_wordc; i++)
     {
       mu_message_t input_msg;
-      if (mh_get_message (mbox, i, &input_msg) == 0)
+      char *endp;
+      size_t n = strtoul (ws.ws_wordv[i], &endp, 10);
+
+      if (*endp)
+	{
+	  mu_error (_("%s:%lu: malformed directive near %s"),
+		    input_file,
+		    (unsigned long) mhn_error_loc (env),
+		    endp);
+	  return 1;
+	}
+		    
+      if (mh_get_message (mbox, n, &input_msg) == 0)
 	{
 	  mu_error (_("%s:%lu: no such message: %lu"),
 		    input_file,
@@ -2326,6 +2336,8 @@ mhn_edit (struct compose_env *env, int level)
 	      if (line_count)
 		/* Close and append the previous part */
 		finish_text_msg (env, &msg, ascii_buf);
+
+	      mu_rtrim_cset (buf, "\n");
 	      
 	      /* Execute the directive */
 	      tok = buf;
diff --git a/mh/repl.c b/mh/repl.c
index 09c85a7..8629d61 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -58,7 +58,7 @@ static struct argp_option options[] = {
   {"inplace", ARG_INPLACE, N_("BOOL"), OPTION_ARG_OPTIONAL,
    N_("* annotate the message in place")},
   {"query", ARG_QUERY, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("query for addresses to place in To: and Cc: lists")},
+   N_("* query for addresses to place in To: and Cc: lists")},
   {"width", ARG_WIDTH, N_("NUMBER"), 0, N_("set output width")},
   {"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
    N_("set the replacement for whatnow program")},
@@ -143,8 +143,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
   switch (key)
     {
     case ARGP_KEY_INIT:
-      draftfolder = mh_global_profile_get ("Draft-Folder",
-					   mu_folder_directory ());
+      draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
       whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
       break;
       
@@ -225,6 +224,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_QUERY:
+      mh_opt_notimpl_warning ("-inplace");
       query_mode = is_true (arg);
       break;
       
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 72f470f..7e76c33 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 
+EXTRA_DIST = $(TESTSUITE_AT) testsuite package.m4 mhed movemsg
 DISTCLEANFILES       = atconfig $(check_SCRIPTS)
 MAINTAINERCLEANFILES = Makefile.in $(TESTSUITE)
 
@@ -55,6 +55,7 @@ TESTSUITE_AT = \
  pick.at\
  scan.at\
  refile.at\
+ repl.at\
  rmf.at\
  rmm.at\
  testsuite.at
diff --git a/mh/tests/repl.at b/mh/tests/repl.at
new file mode 100644
index 0000000..2df8e6b
--- /dev/null
+++ b/mh/tests/repl.at
@@ -0,0 +1,82 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([MH_KEYWORDS],[repl])
+m4_pushdef([replcmd],[repl dnl
+-editor $abs_top_srcdir/mh/tests/mhed])
+
+MH_CHECK([repl msg],[repl00 repl-msg],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray@example.com
+To: root@example.com
+Subject: test input
+
+message body
+])
+echo "quit" | replcmd +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/draft ==
+cat Mail/draft
+],
+[0],
+[-- Editor invocation: Mail/draft
+-- Input file:
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+-- Input file end
+What now? draft left on "Mail/draft".
+== Mail/draft ==
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+Seen by mhed
+])
+
+MH_CHECK([repl -draftfolder],[repl01 repl-draftfolder],[
+mkdir Mail/inbox
+mkdir Mail/drafts
+AT_DATA([Mail/inbox/1],[From: gray@example.com
+To: root@example.com
+Subject: test input
+
+message body
+])
+echo "quit" | replcmd -draftfolder drafts +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/drafts/1 ==
+cat Mail/drafts/1
+],
+[0],
+[-- Editor invocation: Mail/drafts/1
+-- Input file:
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+-- Input file end
+What now? draft left on "Mail/drafts/1".
+== Mail/drafts/1 ==
+To: <gray@example.com>
+Subject: Re: test input
+X-Mailer: MH (AT_PACKAGE_NAME AT_PACKAGE_VERSION)
+--------
+Seen by mhed
+])
+
+m4_popdef([replcmd])
+m4_popdef([MH_KEYWORDS])
+# End of repl.at
\ No newline at end of file
diff --git a/mh/tests/rmf.at b/mh/tests/rmf.at
index 9f93647..49db7fd 100644
--- a/mh/tests/rmf.at
+++ b/mh/tests/rmf.at
@@ -14,7 +14,7 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-m4_pushdef([MH_KEYWORDS],[rmm])
+m4_pushdef([MH_KEYWORDS],[rmf])
 
 MH_CHECK([rmf +folder],[rmf00 rmf+folder],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
diff --git a/mh/tests/rmm.at b/mh/tests/rmm.at
index 850fd7a..1e34d0c 100644
--- a/mh/tests/rmm.at
+++ b/mh/tests/rmm.at
@@ -47,5 +47,36 @@ test: 2 3 5
 cur: 1
 ])
 
+MH_CHECK([rmm rmmproc],[rmm02 rmmproc],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "rmmproc: $abs_top_srcdir/mh/tests/movemsg" >> $MH
+rmm 1 4 || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+find Mail/removed -name '[[0-9]]' | sort
+],
+[0],
+[Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/5
+Mail/removed/1
+Mail/removed/4
+])
+
+MH_CHECK([rmm -- null rmmproc],[rmm03 null-rmmproc],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+echo "rmmproc:" >> $MH
+rmm 1 4 || exit $?
+find Mail/inbox -name '[[0-9]]' | sort
+test -f Mail/inbox/,1 || echo OK
+test -f Mail/inbox/,4 || echo OK
+],
+[0],
+[Mail/inbox/2
+Mail/inbox/3
+Mail/inbox/5
+OK
+OK
+])
+
 m4_popdef[MH_KEYWORDS])
 # End of rmm.at
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index 1e07c4a..f06f082 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -59,3 +59,4 @@ m4_include([pick.at])
 m4_include([burst.at])
 m4_include([comp.at])
 m4_include([forw.at])
+m4_include([repl.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 24 15:41:38 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLM9q-0001Pj-9F
	for mharc-commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:41:38 -0500
Received: from [140.186.70.92] (port=60956 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLM9k-0001Os-M9
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:41:36 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLM9h-0005aI-Ab
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:41:32 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:60966
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLM9h-0005aD-2K
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:41:29 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLM9g-00030C-Kq
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 20:41:28 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLM9b-00030m-17
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 20:41:28 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 27f9a867f4fcfaf29a22349043eaddcb60c2694e
X-Git-Newrev: e53b55870dd3c4166ea6658ea679d608e500172a
Message-Id: <E1PLM9b-00030m-17@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 24 Nov 2010 20:41:23 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-219-ge53b558
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Nov 2010 20:41:36 -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=e53b55870dd3c4166ea6658ea679d608e500172a

The branch, master has been updated
       via  e53b55870dd3c4166ea6658ea679d608e500172a (commit)
       via  bd228fc3d1f40f0f230db1d066fb5a330a0c35a9 (commit)
       via  3f323ca9cee9fdb3a04f2f7269998fdc1f941f5e (commit)
       via  36e8269d52475b4e4e5869873c835ead51d82ccb (commit)
       via  2ef58f17e48b99f5c95c2c90e8ba9a4190663dd8 (commit)
      from  27f9a867f4fcfaf29a22349043eaddcb60c2694e (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 e53b55870dd3c4166ea6658ea679d608e500172a
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 21:38:19 2010 +0200

    mh: move format files to a separate directory.
    
    * mh/etc: New directory.
    * mh/Makefile.am: New file.
    * mh/components: Move to mh/etc.
    * mh/mailutils-mh.eli: Move to mh/etc.
    * mh/mhl.format: Move to mh/etc.
    * mh/mhl.forward: Move to mh/etc.
    * mh/mhl.repl: Move to mh/etc.
    * mh/mhl.usenet: Move to mh/etc.
    * mh/replcomps: Move to mh/etc.
    * mh/replgroupcomps: Move to mh/etc.
    * configure.ac (AC_CONFIG_FILES): Add mh/etc/Makefile.
    * mh/Makefile.am (SUBDIRS): Add etc.
    Move mhlib_DATA and related statements to mh/etc/Makefile.am
    * mh/comp.c (formfile): Remove const qualifier.
    (opt_handler): Use mh_find_file to set formfile.
    * mh/forw.c: Likewise.
    * mh/mh_init.c (mh_find_file): Make sure *resolved_name is always
    set to the last tried name.
    
    * mh/tests/comp.at: Remove directory components from the -from argument.
    * mh/tests/forw.at: Likewise.
    * mh/tests/mhl.at: Likewise.
    * mh/tests/testsuite.at (MH_SETUP): Change mhetcdir value.

commit bd228fc3d1f40f0f230db1d066fb5a330a0c35a9
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 20:36:56 2010 +0200

    mh: set a compatible search path for format files; other minor fixes.
    
    * mh/mh_format.c (builtin_friendly): If personal part is present,
    return it.  Otherwise, leave the address untouched.
    (builtin_pers): Do not quote the return.
    * mh/tests/inc.at: Reflect the above changes.
    * mh/tests/scan.at: Likewise.
    
    * mh/mh_list.c (eval_body): Offset each line.
    * mh/tests/mhl.at: Test this change.
    
    * mh/mhl.c: Use mh_find_file to resolve the argument to -form.
    * mh/repl.c: Likewise.
    Same for replgroupcomps, mhl.repl and -filter.
    
    * mh/mhl.repl: New file.
    * mh/mhl.usenet: New file.
    * mh/Makefile.am (mhlib_DATA, EXTRA_DIST): Add new files.

commit 3f323ca9cee9fdb3a04f2f7269998fdc1f941f5e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 20:35:34 2010 +0200

    wordsplit: fix whitespace trimming.
    
    * libmailutils/string/wordsplit.c (mu_wordsplit_trimws): Do not
    touch quoted nodes.
    * libmailutils/tests/wordsplit.at: Test the above change.

commit 36e8269d52475b4e4e5869873c835ead51d82ccb
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 18:34:36 2010 +0200

    mh: fix the use of mhl.forward in forw.
    
    * mh/mhl.forward: New file.
    * mh/forw.c (mh_option): the -format option is boolean.
    (mhl_filter): Rename to mhl_filter_file.
    (opt_handler) <ARG_FORMAT>: Use default mhl.filter.
    <ARG_NOFORMAT>: Set encap_clear.
    <ARG_FILTER>: Use mh_find_file to determine filter file name.
    (finish_draft): Use MHL filter file if encap == encap_mhl.
    * mh/mh.h (mh_find_file): New prototype.
    * mh/mh_init.c (mh_find_file): New file.
    (mh_read_formfile): Use mh_find_file to locate the file.
    * mh/tests/forw.at: Test forw -format.
    * mh/tests/mhparam.at: Update the -all test.
    * tests/testsuite.at (MH_SETUP): Set the "mhetcdir" component.
    * mh/scan.c (opt_handler): Exit if mh_read_formfile failed.

commit 2ef58f17e48b99f5c95c2c90e8ba9a4190663dd8
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 16:53:34 2010 +0200

    New type of stream: static memory stream.
    
    Static memory stream is a read-only stream whose transport is
    an arbitrary area of memory.  Such streams allow the programmer
    to access C strings using streams interface.
    
    * include/mailutils/stream.h (mu_static_memory_stream_create): New
    proto.
    * libmailutils/stream/memory_stream.c (mu_static_memory_stream_create): New
    function.
    * imap4d/append.c (imap4d_append0): Use static memory stream to
    create a temporary message.
    * imap4d/preauth.c (decode64_buf): Use static memory stream.
    * libmailutils/base/rfc2047.c (mu_rfc2047_decode): Likewise.
    * libmailutils/mime/mimehdr.c (mu_mimehdr_decode_param): Likewise.
    * libmu_auth/ldap.c (chk_md5, chk_sha, chk_ssha): Likewise.
    * libmu_sieve/extensions/vacation.c (build_mime): Likewise.

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

Summary of changes:
 configure.ac                        |    1 +
 imap4d/append.c                     |   16 +++----
 imap4d/preauth.c                    |    3 +-
 include/mailutils/stream.h          |    3 +
 libmailutils/base/rfc2047.c         |    8 +---
 libmailutils/mime/mimehdr.c         |    6 +--
 libmailutils/stream/memory_stream.c |   30 ++++++++++++
 libmailutils/string/wordsplit.c     |    3 +
 libmailutils/tests/wordsplit.at     |   10 ++++
 libmu_auth/ldap.c                   |   16 +++----
 libmu_sieve/extensions/vacation.c   |    4 +-
 mh/Makefile.am                      |   19 +-------
 mh/comp.c                           |    4 +-
 mh/{ => etc}/components             |    0
 mh/{ => etc}/mailutils-mh.eli       |    0
 mh/{ => etc}/mhl.format             |    0
 mh/etc/mhl.forward                  |   15 ++++++
 mh/etc/mhl.repl                     |    8 +++
 mh/etc/mhl.usenet                   |   10 ++++
 mh/{ => etc}/replcomps              |    0
 mh/{ => etc}/replgroupcomps         |    0
 mh/forw.c                           |   42 ++++++++---------
 mh/mh.h                             |    2 +
 mh/mh_format.c                      |   22 ++++++---
 mh/mh_init.c                        |   84 ++++++++++++++++++++++++++++++++---
 mh/mh_list.c                        |    4 +-
 mh/mhl.c                            |    2 +-
 mh/repl.c                           |   22 +++++-----
 mh/scan.c                           |    3 +-
 mh/tests/comp.at                    |    2 +-
 mh/tests/forw.at                    |   73 ++++++++++++++++++++++++++++---
 mh/tests/inc.at                     |   20 ++++----
 mh/tests/mhl.at                     |   25 ++++++++++-
 mh/tests/mhparam.at                 |    3 +-
 mh/tests/scan.at                    |   24 +++++-----
 mh/tests/testsuite.at               |    5 ++-
 36 files changed, 354 insertions(+), 135 deletions(-)
 rename mh/{ => etc}/components (100%)
 rename mh/{ => etc}/mailutils-mh.eli (100%)
 rename mh/{ => etc}/mhl.format (100%)
 create mode 100644 mh/etc/mhl.forward
 create mode 100644 mh/etc/mhl.repl
 create mode 100644 mh/etc/mhl.usenet
 rename mh/{ => etc}/replcomps (100%)
 rename mh/{ => etc}/replgroupcomps (100%)

diff --git a/configure.ac b/configure.ac
index 10d1e6a..4412729 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1397,6 +1397,7 @@ AC_CONFIG_FILES([
  libmailutils/Makefile
  messages/Makefile
  mh/Makefile
+ mh/etc/Makefile
  mimeview/Makefile
  movemail/Makefile
  po/Makefile.in
diff --git a/imap4d/append.c b/imap4d/append.c
index f610cff..8999b73 100644
--- a/imap4d/append.c
+++ b/imap4d/append.c
@@ -74,12 +74,6 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
   if (mu_message_create (&msg, &tm))
     return 1;
 
-  if (mu_memory_stream_create (&stream, MU_STREAM_RDWR))
-    {
-      mu_message_destroy (&msg, &tm);
-      return 1;
-    }
-
   /* If a date_time is specified, the internal date SHOULD be set in the
      resulting message; otherwise, the internal date of the resulting
      message is set to the current date and time by default. */
@@ -96,10 +90,14 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
   
   tm = gmtime (&t);
 
-  while (*text && mu_isblank (*text))
-    text++;
+  text = mu_str_skip_class (text, MU_CTYPE_BLANK);
+
+  if (mu_static_memory_stream_create (&stream, text, strlen (text)))
+    {
+      mu_message_destroy (&msg, &tm);
+      return 1;
+    }
 
-  mu_stream_write (stream, text, strlen (text), NULL);
   mu_message_set_stream (msg, stream, &tm);
   mu_message_set_size (msg, _append_size, &tm);
 
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index 014da68..ef36e72 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -192,10 +192,9 @@ decode64_buf (const char *name, unsigned char **pbuf, size_t *psize)
   
   name++;
   namelen = strlen (name) - 1;
-  mu_memory_stream_create (&str, 0);
+  mu_static_memory_stream_create (&str, name, namelen);
   mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
 		    MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
-  mu_stream_write (str, name, namelen, NULL);
   mu_stream_read (flt, buf, sizeof buf, &size);
   mu_stream_destroy (&flt);
   *pbuf = malloc (size);
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index 444733e..ba8c9bc 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -205,6 +205,9 @@ int mu_prog_stream_create (mu_stream_t *pstream, const char *progname, int flags
 int mu_filter_prog_stream_create (mu_stream_t *pstream, const char *progname,
 				  mu_stream_t input);
 int mu_memory_stream_create (mu_stream_t *pstream, int flags);
+int mu_static_memory_stream_create (mu_stream_t *pstream, const void *mem,
+				    size_t size);
+
 int mu_mapfile_stream_create (mu_stream_t *pstream, const char *filename,
 			      int flags);
 int mu_socket_stream_create (mu_stream_t *pstream, const char *filename,
diff --git a/libmailutils/base/rfc2047.c b/libmailutils/base/rfc2047.c
index 29b3c4c..d634960 100644
--- a/libmailutils/base/rfc2047.c
+++ b/libmailutils/base/rfc2047.c
@@ -160,8 +160,7 @@ mu_rfc2047_decode (const char *tocode, const char *input, char **ptostr)
 	  if (status != 0)
 	    break;
 
-	  mu_memory_stream_create (&in_stream, 0);
-	  mu_stream_write (in_stream, encoded_text, size, NULL);
+	  mu_static_memory_stream_create (&in_stream, encoded_text, size);
 	  mu_stream_seek (in_stream, 0, MU_SEEK_SET, NULL);
 	  status = mu_decode_filter (&filter, in_stream, filter_type, fromcode,
 				     tocode);
@@ -266,12 +265,9 @@ mu_rfc2047_encode (const char *charset, const char *encoding,
   else if (encoding[1] || !strchr ("BQ", encoding[0]))
     return MU_ERR_BAD_2047_ENCODING;
 
-  rc = mu_memory_stream_create (&input_stream, 0);
+  rc = mu_static_memory_stream_create (&input_stream, text, strlen (text));
   if (rc)
     return rc;
-  
-  mu_stream_write (input_stream, text, strlen (text), NULL);
-  mu_stream_seek (input_stream, 0, MU_SEEK_SET, NULL);
   rc = mu_filter_create (&output_stream, input_stream,
 			 encoding, MU_FILTER_ENCODE,
 			 MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
diff --git a/libmailutils/mime/mimehdr.c b/libmailutils/mime/mimehdr.c
index 863566c..21da8a8 100644
--- a/libmailutils/mime/mimehdr.c
+++ b/libmailutils/mime/mimehdr.c
@@ -506,10 +506,8 @@ mu_mimehdr_decode_param (const char *value, int flags,
 		  size_t total = 0, pos;
 		  size_t nbytes;
 
-		  rc = mu_memory_stream_create (&instr, 0);
-		  if (rc)
-		    break;
-		  rc = mu_stream_write (instr, data, strlen (data), NULL);
+		  rc = mu_static_memory_stream_create (&instr, data,
+						       strlen (data));
 		  if (rc)
 		    break;
 
diff --git a/libmailutils/stream/memory_stream.c b/libmailutils/stream/memory_stream.c
index ed599dc..84aa534 100644
--- a/libmailutils/stream/memory_stream.c
+++ b/libmailutils/stream/memory_stream.c
@@ -224,3 +224,33 @@ mu_memory_stream_create (mu_stream_t *pstream, int flags)
   return rc;
 }
   
+int
+mu_static_memory_stream_create (mu_stream_t *pstream, const void *mem,
+				size_t size)
+{
+  mu_stream_t stream;
+  struct _mu_memory_stream *str;
+
+  str = (struct _mu_memory_stream *)
+    _mu_stream_create (sizeof (*str), MU_STREAM_READ | MU_STREAM_SEEK);
+  
+  if (!str)
+    return ENOMEM;
+
+  str->ptr = (void*) mem;
+  str->size = size;
+  str->offset = 0;
+  str->capacity = size;
+
+  str->stream.flags |= _MU_STR_OPEN;
+  str->stream.read = _memory_read;
+  str->stream.size = _memory_size;
+  str->stream.ctl = _memory_ioctl;
+  str->stream.seek = _memory_seek;
+  
+  stream = (mu_stream_t) str;
+  *pstream = stream;
+
+  return 0;
+}
+  
diff --git a/libmailutils/string/wordsplit.c b/libmailutils/string/wordsplit.c
index b5397ee..5792393 100644
--- a/libmailutils/string/wordsplit.c
+++ b/libmailutils/string/wordsplit.c
@@ -946,6 +946,9 @@ mu_wordsplit_trimws (struct mu_wordsplit *wsp)
   for (p = wsp->ws_head; p; p = p->next)
     {
       size_t n;
+
+      if (p->flags & _WSNF_QUOTE)
+	continue;
       
       /* Skip leading whitespace: */
       for (n = p->v.segm.beg; n < p->v.segm.end && ISWS (wsp->ws_input[n]);
diff --git a/libmailutils/tests/wordsplit.at b/libmailutils/tests/wordsplit.at
index 8bcd1bb..1131a51 100644
--- a/libmailutils/tests/wordsplit.at
+++ b/libmailutils/tests/wordsplit.at
@@ -324,5 +324,15 @@ TESTWSP([delimiter following empty quotes],[],[delim : ws return_delims],
 2: r
 ])
 
+TESTWSP([suppress ws trimming within quotes],[],
+[default delim , ws return_delims],
+[nocomponent,nonewline, formatfield="In message %{text}, "],
+[NF: 5
+0: nocomponent
+1: ,
+2: nonewline
+3: ,
+4: "formatfield=In message %{text}, "
+])
 
 m4_popdef([TESTWSP])
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 5de7834..6a763aa 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -598,10 +598,9 @@ chk_md5 (const char *db_pass, const char *pass)
   mu_md5_process_bytes (pass, strlen (pass), &md5context);
   mu_md5_finish_ctx (&md5context, md5digest);
 
-  mu_memory_stream_create (&str, 0);
+  mu_static_memory_stream_create (&str, db_pass, strlen (db_pass));
   mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
 		    MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
-  mu_stream_write (str, db_pass, strlen (db_pass), NULL);
 
   mu_stream_read (flt, (char*) d1, sizeof d1, NULL);
   mu_stream_destroy (&flt);
@@ -620,11 +619,10 @@ chk_smd5 (const char *db_pass, const char *pass)
   mu_stream_t str = NULL, flt = NULL;
   size_t size;
   
-  mu_memory_stream_create (&str, 0);
+  size = strlen (db_pass);
+  mu_static_memory_stream_create (&str, db_pass, size);
   mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
 		    MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
-  size = strlen (db_pass);
-  mu_stream_write (str, db_pass, size, NULL);
 
   d1 = malloc (size);
   if (!d1)
@@ -665,10 +663,9 @@ chk_sha (const char *db_pass, const char *pass)
   mu_sha1_process_bytes (pass, strlen (pass), &sha1context);
   mu_sha1_finish_ctx (&sha1context, sha1digest);
 
-  mu_memory_stream_create (&str, 0);
+  mu_static_memory_stream_create (&str, db_pass, strlen (db_pass));
   mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
 		    MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
-  mu_stream_write (str, db_pass, strlen (db_pass), NULL);
 
   mu_stream_read (flt, (char*) d1, sizeof d1, NULL);
   mu_stream_destroy (&flt);
@@ -687,11 +684,10 @@ chk_ssha (const char *db_pass, const char *pass)
   mu_stream_t str = NULL, flt = NULL;
   size_t size;
   
-  mu_memory_stream_create (&str, 0);
+  size = strlen (db_pass);
+  mu_static_memory_stream_create (&str, db_pass, size);
   mu_filter_create (&flt, str, "base64", MU_FILTER_DECODE,
 		    MU_STREAM_READ | MU_STREAM_AUTOCLOSE);
-  size = strlen (db_pass);
-  mu_stream_write (str, db_pass, size, NULL);
 
   d1 = malloc (size);
   if (!d1)
diff --git a/libmu_sieve/extensions/vacation.c b/libmu_sieve/extensions/vacation.c
index 3e3b595..a4613a7 100644
--- a/libmu_sieve/extensions/vacation.c
+++ b/libmu_sieve/extensions/vacation.c
@@ -60,7 +60,7 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
   mu_message_create (&newmsg, NULL);
   mu_message_get_body (newmsg, &body);
 
-  if ((rc = mu_memory_stream_create (&input, MU_STREAM_RDWR)))
+  if ((rc = mu_static_memory_stream_create (&input, text, strlen (text))))
     {
       mu_sieve_error (mach,
 		      _("cannot create temporary stream: %s"),
@@ -70,8 +70,6 @@ build_mime (mu_sieve_machine_t mach, mu_list_t tags, mu_mime_t *pmime,
       return 1;
     }
 
-  mu_stream_write (input, text, strlen (text), NULL);
-
   if (mu_sieve_tag_lookup (tags, "mime", NULL))
     {
       mu_stream_t fstr;
diff --git a/mh/Makefile.am b/mh/Makefile.am
index a78eb65..3e951f8 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -15,9 +15,9 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
-SUBDIRS = . tests
+SUBDIRS = . etc tests
 bindir = @MH_BIN_DIR@
-mhlibdir = $(pkgdatadir)/mh
+
 bin_PROGRAMS = \
  ali\
  anno\
@@ -83,10 +83,6 @@ libmh_a_SOURCES= \
  whatnowenv.c
 noinst_HEADERS = mh.h mh_alias.h mh_format.h mh_getopt.h
 
-LISPSRC = mailutils-mh.el
-lisp_LISP=@lisp_LISP@
-EXTRA_LISP = mailutils-mh.el
-
 BUILT_SOURCES= \
 	mh_fmtgram.c \
         pick-gram.c \
@@ -97,16 +93,7 @@ BUILT_SOURCES= \
 
 MAINTAINERCLEANFILES=$(BUILT_SOURCES)
 
-mhlib_DATA = components replcomps replgroupcomps mhl.format $(LISPSRC)
-EXTRA_DIST = components replcomps replgroupcomps mhl.format\
- mailutils-mh.eli mh_fmtgram.y pick.y mh_alias.y mh_alias.l
-DISTCLEANFILES = mailutils-mh.el
-
-SUFFIXES = .eli .el
-mailutils-mh.el: mailutils-mh.eli
-
-.eli.el:
-	sed "s,BINDIR,$(bindir),g;s,MHLIBDIR,$(mhlibdir),g" $< > $@
+EXTRA_DIST = mailutils-mh.eli mh_fmtgram.y pick.y mh_alias.y mh_alias.l
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ 
 AM_CPPFLAGS = -D_GNU_SOURCE -DMHLIBDIR=\"$(mhlibdir)\" -DMHBINDIR=\"$(bindir)\"
diff --git a/mh/comp.c b/mh/comp.c
index c604618..7b62b95 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -75,7 +75,7 @@ struct mh_option mh_option[] = {
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
 static const char *whatnowproc;
-const char *formfile;
+char *formfile;
 static int build_only = 0; /* --build flag */
 static int use_draft = 0;  /* --use flag */
 static char *draftmessage = "new";
@@ -110,7 +110,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 
     case ARG_FORM:
-      formfile = mh_expand_name (MHLIBDIR, arg, 0);
+      mh_find_file (arg, &formfile);
       break;
 
     case ARG_DRAFTMESSAGE:
diff --git a/mh/components b/mh/etc/components
similarity index 100%
rename from mh/components
rename to mh/etc/components
diff --git a/mh/mailutils-mh.eli b/mh/etc/mailutils-mh.eli
similarity index 100%
rename from mh/mailutils-mh.eli
rename to mh/etc/mailutils-mh.eli
diff --git a/mh/mhl.format b/mh/etc/mhl.format
similarity index 100%
rename from mh/mhl.format
rename to mh/etc/mhl.format
diff --git a/mh/etc/mhl.forward b/mh/etc/mhl.forward
new file mode 100644
index 0000000..3baed14
--- /dev/null
+++ b/mh/etc/mhl.forward
@@ -0,0 +1,15 @@
+; This is the default mhl.format file for Mailutils MH.
+;
+; GNU Mailutils -- a suite of utilities for electronic mail
+; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+;
+width=80,overflowtext=,overflowoffset=10
+leftadjust,compress,compwidth=9
+Date:formatfield="%<(nodate{text})%{text}%|%(tws{text})%>"
+From:
+To:
+cc:
+Subject:
+:
+body:nocomponent,overflowoffset=0,noleftadjust,nocompress
diff --git a/mh/etc/mhl.repl b/mh/etc/mhl.repl
new file mode 100644
index 0000000..007617b
--- /dev/null
+++ b/mh/etc/mhl.repl
@@ -0,0 +1,8 @@
+; Default format file for GNU repl
+;
+; GNU Mailutils -- a suite of utilities for electronic mail
+; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+;
+:
+body:nocomponent,offset=9
diff --git a/mh/etc/mhl.usenet b/mh/etc/mhl.usenet
new file mode 100644
index 0000000..e669d1c
--- /dev/null
+++ b/mh/etc/mhl.usenet
@@ -0,0 +1,10 @@
+; USENET-style format file for GNU repl
+;
+; GNU Mailutils -- a suite of utilities for electronic mail
+; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+;
+:
+message-id:nocomponent,nonewline,formatfield="In message %{text}, "
+from:nocomponent,formatfield="%(friendly{text}) writes:"
+body:component=">",overflowtext=">",overflowoffset=0
diff --git a/mh/replcomps b/mh/etc/replcomps
similarity index 100%
rename from mh/replcomps
rename to mh/etc/replcomps
diff --git a/mh/replgroupcomps b/mh/etc/replgroupcomps
similarity index 100%
rename from mh/replgroupcomps
rename to mh/etc/replgroupcomps
diff --git a/mh/forw.c b/mh/forw.c
index 4b12bb3..60baaaf 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -78,7 +78,7 @@ struct mh_option mh_option[] = {
   { "build" },
   { "file",          MH_OPT_ARG, "msgfile" },
   { "form",          MH_OPT_ARG, "formatfile" },
-  { "format",        MH_OPT_ARG, "string" },
+  { "format",        MH_OPT_BOOL },
   { "draftfolder",   MH_OPT_ARG, "folder" },
   { "nodraftfolder" },
   { "draftmessage" },
@@ -99,11 +99,13 @@ enum encap_type
     encap_mime
   };
 
-static char *formfile;
+char *formfile;
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
 static const char *whatnowproc;
-static char *mhl_filter = NULL; /* --filter flag */
+
+static char *mhl_filter_file = NULL; /* --filter flag */
+
 static int build_only = 0;      /* --build flag */
 static int annotate = 0;        /* --annotate flag */
 static enum encap_type encap = encap_clear; /* controlled by --format, --form
@@ -177,22 +179,25 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 
     case ARG_FORM:
-      formfile = arg;
+      mh_find_file (arg, &formfile);
       break;
 
     case ARG_FORMAT:
       if (is_true (arg))
 	{
 	  encap = encap_mhl;
-	  break;
+	  mh_find_file ("mhl.forward", &mhl_filter_file);
 	}
-      /*FALLTHRU*/
-    case ARG_NOFORMAT:
-      if (encap == encap_mhl)
+      else
 	encap = encap_clear;
       break;
+      
+    case ARG_NOFORMAT:
+      encap = encap_clear;
+      break;
 
     case ARG_FILTER:
+      mh_find_file (arg, &mhl_filter_file);
       encap = encap_mhl;
       break;
 	
@@ -381,23 +386,16 @@ finish_draft ()
     }
   else
     {
-      if (!mhl_filter)
+      if (encap == encap_mhl)
 	{
-	  char *s = mh_expand_name (MHLIBDIR, "mhl.forward", 0);
-	  if (access (s, R_OK) == 0)
-	    mhl_filter = "mhl.forward";
-	  free (s);
+	  if (mhl_filter_file)
+	    {
+	      format = mhl_format_compile (mhl_filter_file);
+	      if (!format)
+		exit (1);
+	    }
 	}
       
-      if (mhl_filter)
-	{
-	  char *s = mh_expand_name (MHLIBDIR, mhl_filter, 0);
-	  format = mhl_format_compile (s);
-	  if (!format)
-	    exit (1);
-	  free (s);
-	}
-  
       if (annotate)
 	{
 	  wh_env.anno_field = "Forwarded";
diff --git a/mh/mh.h b/mh/mh.h
index a4c66cf..21be165 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -314,6 +314,7 @@ void mh_msgset_free (mh_msgset_t *msgset);
 void mh_msgset_uids (mu_mailbox_t mbox, mh_msgset_t *msgset);
 
 char *mh_get_dir (void);
+int mh_find_file (const char *name, char **resolved_name);
 char *mh_expand_name (const char *base, const char *name, int is_folder);
 void mh_quote (const char *in, char **out);
 void mh_expand_aliases (mu_message_t msg, mu_address_t *addr_to,
@@ -366,6 +367,7 @@ void mh_annotate (mu_message_t msg, char *field, char *text, int date);
 #define MHL_DISABLE_BODY 8
 
 mu_list_t mhl_format_compile (char *name);
+
 int mhl_format_run (mu_list_t fmt, int width, int length, int flags,
 		    mu_message_t msg, mu_stream_t output);
 void mhl_format_destroy (mu_list_t *fmt);
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 523d943..a92fa5c 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -1583,7 +1583,20 @@ builtin_proper (struct mh_machine *mach)
 static void
 builtin_friendly (struct mh_machine *mach)
 {
-  /*FIXME: noop*/
+  mu_address_t addr;
+  const char *str;
+  int rc;
+  
+  rc = mu_address_create (&addr, strobj_ptr (&mach->arg_str));
+  if (rc)
+    return;
+
+  if (mu_address_sget_personal (addr, 1, &str) == 0 && str)
+    {
+      strobj_free (&mach->arg_str);
+      strobj_create (&mach->arg_str, str);
+    }
+  mu_address_destroy (&addr);
 }
 
 /*     addr       addr     string   mbox@host or host!mbox rendering*/
@@ -1618,12 +1631,7 @@ builtin_pers (struct mh_machine *mach)
     return;
 
   if (mu_address_sget_personal (addr, 1, &str) == 0 && str)
-    {
-      char *p;
-      mu_asprintf (&p, "\"%s\"", str);
-      strobj_create (&mach->arg_str, p);
-      free (p);
-    }
+    strobj_create (&mach->arg_str, str);
   mu_address_destroy (&addr);
 }
 
diff --git a/mh/mh_init.c b/mh/mh_init.c
index 2d2b0f4..45d725f 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -77,20 +77,34 @@ mh_read_formfile (char *name, char **pformat)
   char *ptr;
   size_t off = 0;
   char *format_str;
-
-  if (stat (name, &st))
+  char *file_name;
+  int rc;
+  
+  rc = mh_find_file (name, &file_name);
+  if (rc)
+    {
+      mu_error (_("cannot access format file %s: %s"), name, strerror (rc));
+      return -1;
+    }
+  
+  if (stat (file_name, &st))
     {
-      mu_error (_("cannot stat format file %s: %s"), name, strerror (errno));
+      mu_error (_("cannot stat format file %s: %s"), file_name,
+		strerror (errno));
+      free (file_name);
       return -1;
     }
   
-  fp = fopen (name, "r");
+  fp = fopen (file_name, "r");
   if (!fp)
     {
-      mu_error (_("cannot open format file %s: %s"), name, strerror (errno));
+      mu_error (_("cannot open format file %s: %s"), file_name,
+		strerror (errno));
+      free (file_name);
       return -1;
     }
-
+  free (file_name);
+  
   format_str = xmalloc (st.st_size+1);
   while ((ptr = fgets (format_str + off, st.st_size - off + 1, fp)) != NULL)
     {
@@ -520,6 +534,64 @@ mh_expand_name (const char *base, const char *name, int is_folder)
 }
 
 int
+mh_find_file (const char *name, char **resolved_name)
+{
+  char *s;
+  int rc;
+  
+  if (name[0] == '/' ||
+      (name[0] == '.' && name[1] == '/') ||
+      (name[0] == '.' && name[1] == '.' && name[2] == '/'))
+    {
+      *resolved_name = xstrdup (name);
+      if (access (name, R_OK) == 0)
+	return 0;
+      return errno;
+    }
+
+  if (name[0] == '~')
+    {
+      s = mu_tilde_expansion (name, "/", NULL);
+      *resolved_name = s;
+      if (access (s, R_OK) == 0)
+	return 0;
+      return errno;
+    }
+  
+  s = mh_expand_name (NULL, name, 0);
+  if (access (s, R_OK) == 0)
+    {
+      *resolved_name = s;
+      return 0;
+    }
+  if (errno != ENOENT)
+    mu_diag_output (MU_DIAG_WARNING,
+		    _("cannot access %s: %s"), s, mu_strerror (errno));
+  free (s);
+
+  s = mh_expand_name (mh_global_profile_get ("mhetcdir", MHLIBDIR), name, 0);
+  if (access (s, R_OK) == 0)
+    {
+      *resolved_name = s;
+      return 0;
+    }
+  if (errno != ENOENT)
+    mu_diag_output (MU_DIAG_WARNING,
+		    _("cannot access %s: %s"), s, mu_strerror (errno));
+  free (s);
+
+  *resolved_name = xstrdup (name);
+  if (access (name, R_OK) == 0)
+    return 0;
+  rc = errno;
+  if (rc != ENOENT)
+    mu_diag_output (MU_DIAG_WARNING,
+		    _("cannot access %s: %s"), s, mu_strerror (rc));
+
+  return rc;
+}
+
+int
 mh_iterate (mu_mailbox_t mbox, mh_msgset_t *msgset,
 	    mh_iterator_fp itr, void *data)
 {
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 4761ace..4bc9583 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -700,8 +700,6 @@ eval_body (struct eval_env *env)
   if (env->bvar[B_DISABLE_BODY])
     return 0;
 
-  print_component_name (env);
-  
   env->prefix = env->svar[S_COMPONENT];
 
   mu_message_get_body (env->msg, &body);
@@ -728,7 +726,7 @@ eval_body (struct eval_env *env)
   while (mu_stream_readline (input, buf, sizeof buf, &n) == 0
 	 && n > 0)
     {
-      buf[n] = 0;
+      goto_offset (env, env->ivar[I_OFFSET]);
       print (env, buf, 0);
       nl = buf[n-1] == '\n';
     }
diff --git a/mh/mhl.c b/mh/mhl.c
index 1d6635f..e81933d 100644
--- a/mh/mhl.c
+++ b/mh/mhl.c
@@ -99,7 +99,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_FORM:
-      formfile = arg;
+      mh_find_file (arg, &formfile);
       break;
       
     case ARG_WIDTH:
diff --git a/mh/repl.c b/mh/repl.c
index 8629d61..c7ca5b3 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -55,6 +55,7 @@ static struct argp_option options[] = {
   {"form",   ARG_FORM, N_("FILE"), 0, N_("read format from given file")},
   {"format", ARG_FORMAT, N_("BOOL"), OPTION_ARG_OPTIONAL,
    N_("include a copy of the message being replied; the message will be processed using either the default filter \"mhl.reply\", or the filter specified by --filter option") },
+  {"noformat", ARG_NOFORMAT, 0,          OPTION_HIDDEN, "" },
   {"inplace", ARG_INPLACE, N_("BOOL"), OPTION_ARG_OPTIONAL,
    N_("* annotate the message in place")},
   {"query", ARG_QUERY, N_("BOOL"), OPTION_ARG_OPTIONAL,
@@ -178,17 +179,15 @@ opt_handler (int key, char *arg, struct argp_state *state)
     case ARG_FORM:
       free (format_str);
       format_str = NULL;
-      s = mh_expand_name (MHLIBDIR, arg, 0);
-      mh_read_formfile (s, &format_str);
-      free (s);
+      if (mh_read_formfile (arg, &format_str))
+	exit (1);
       break;
 
     case ARG_GROUP:
       if (is_true (arg))
 	{
-	  s = mh_expand_name (MHLIBDIR, "replgroupcomps", 0);
-	  mh_read_formfile (s, &format_str);
-	  free (s);
+	  if (mh_read_formfile ("replgroupcomps", &format_str))
+	    exit (1);
 	  rcpt_mask |= RCPT_ALL;
 	}
       else
@@ -229,18 +228,19 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_FILTER:
-      mhl_filter = arg;
+      mh_find_file (arg, &mhl_filter);
       break;
 
     case ARG_FORMAT:
       if (is_true (arg))
-	{
-	  if (!mhl_filter)
-	    mhl_filter = mh_expand_name (MHLIBDIR, "mhl.repl", 0);
-	}
+	mh_find_file ("mhl.repl", &mhl_filter);
       else
 	mhl_filter = NULL;
       break;
+
+    case ARG_NOFORMAT:
+      mhl_filter = NULL;
+      break;
       
     case ARG_FCC:
       if (!has_fcc)
diff --git a/mh/scan.c b/mh/scan.c
index 05ec180..07908de 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -99,7 +99,8 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
       
     case ARG_FORM:
-      mh_read_formfile (arg, &format_str);
+      if (mh_read_formfile (arg, &format_str))
+	exit (1);
       break;
       
     case ARG_FORMAT:
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index ced3de9..4ffa81b 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -16,7 +16,7 @@
 
 m4_pushdef([MH_KEYWORDS],[comp])
 m4_pushdef([compcmd],[comp dnl
--form $abs_top_srcdir/mh/components dnl
+-form components dnl
 -editor $abs_top_srcdir/mh/tests/mhed])
 
 MH_CHECK([comp -file],[comp00 comp-file],[
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
index 9d4b31d..16c83da 100644
--- a/mh/tests/forw.at
+++ b/mh/tests/forw.at
@@ -16,7 +16,7 @@
 
 m4_pushdef([MH_KEYWORDS],[forw])
 m4_pushdef([forwcmd],[forw dnl
--form $abs_top_srcdir/mh/components dnl
+-form components dnl
 -editor $abs_top_srcdir/mh/tests/mhed])
 
 MH_CHECK([forw msg],[forw00 forw-msg],[
@@ -80,7 +80,68 @@ Subject: test input
 message body
 ])
 
-MH_CHECK([forw msgs],[forw01 forw-msgs],[
+MH_CHECK([forw -format msg],[forw01 forw-format-msg],[
+mkdir Mail/inbox
+AT_DATA([Mail/inbox/1],[From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+dir=`pwd`
+echo quit | forwcmd -format +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo == Mail/draft ==
+cat Mail/draft
+echo == Message ==
+# FIXME: AMD adds this header to the first message.  Find a better way.
+# See also the same sed hacks below.
+sed '/^X-IMAPbase/d' Mail/inbox/1
+],
+[0],
+[-- Editor invocation: Mail/draft
+-- Input file:
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From:    gray
+To:      root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+-- Input file end
+What now? draft left on "Mail/draft".
+== Mail/draft ==
+To:
+cc:
+Subject:
+--------
+
+------- Forwarded message
+From:    gray
+To:      root
+Subject: test input
+
+message body
+
+------- End of Forwarded message
+
+Seen by mhed
+== Message ==
+From: gray
+To: root
+Subject: test input
+
+message body
+])
+
+MH_CHECK([forw msgs],[forw02 forw-msgs],[
 mkdir Mail/inbox
 AT_DATA([Mail/inbox/1],[From: gray
 To: root
@@ -171,7 +232,7 @@ Subject: 2nd message
 2nd message body
 ])
 
-MH_CHECK([forw -build msg],[forw02 forw-build-msg],[
+MH_CHECK([forw -build msg],[forw03 forw-build-msg],[
 mkdir Mail/inbox
 AT_DATA([Mail/inbox/1],[From: gray
 To: root
@@ -211,7 +272,7 @@ Subject: test input
 message body
 ])
 
-MH_CHECK([forw -build -mime msgs],[forw03 forw-build-mime-msg],[
+MH_CHECK([forw -build -mime msgs],[forw04 forw-build-mime-msg],[
 mkdir Mail/inbox
 AT_DATA([Mail/inbox/1],[From: gray
 To: root
@@ -257,7 +318,7 @@ Subject: 2nd message
 2nd message body
 ])
 
-MH_CHECK([forw -draftfolder],[forw04 forw-draftfolder draftfolder],[
+MH_CHECK([forw -draftfolder],[forw05 forw-draftfolder draftfolder],[
 mkdir Mail/inbox
 mkdir Mail/drafts
 AT_DATA([Mail/inbox/1],[From: gray
@@ -316,7 +377,7 @@ Subject: test input
 message body
 ])
 
-MH_CHECK([forw -file],[forw05 forw-file],[
+MH_CHECK([forw -file],[forw06 forw-file],[
 AT_DATA([infile],[From: gray
 To: root
 Subject: test input
diff --git a/mh/tests/inc.at b/mh/tests/inc.at
index e2150c8..22d17c6 100644
--- a/mh/tests/inc.at
+++ b/mh/tests/inc.at
@@ -22,8 +22,8 @@ inc -notruncate -file ./mbox1 | sed 's/ *$//'
 cmp $abs_top_srcdir/testsuite/spool/mbox1 mbox1
 ],
 [0],
-[   1+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   1+ 12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
@@ -36,8 +36,8 @@ echo "Next"
 inc -truncate -file ./mbox1 | sed 's/ *$//'
 ],
 [0],
-[   1+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   1+ 12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
@@ -50,8 +50,8 @@ mkdir Mail/new
 inc +new -file ./mbox1 | sed 's/ *$//'
 ],
 [0],
-[   1+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   1+ 12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
@@ -63,8 +63,8 @@ MUT_MBCOPY([$abs_top_srcdir/testsuite/spool/mbox1])
 inc -changecur -file ./mbox1 | sed 's/ *$//'
 ],
 [0],
-[   6+ 12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   7  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   6+ 12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   7  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    8  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    9  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
   10  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
@@ -78,8 +78,8 @@ inc -nochangecur -file ./mbox1 | sed 's/ *$//'
 grep ^cur: Mail/inbox/.mh_sequences
 ],
 [0],
-[   6  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   7  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   6  12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   7  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    8  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    9  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
   10  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
diff --git a/mh/tests/mhl.at b/mh/tests/mhl.at
index c9c99da..a498e2d 100644
--- a/mh/tests/mhl.at
+++ b/mh/tests/mhl.at
@@ -18,7 +18,7 @@ m4_pushdef([MH_KEYWORDS],[mhl])
 
 MH_CHECK([mhl],[mhl00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
-mhl -form $abs_top_srcdir/mh/mhl.format Mail/inbox/2
+mhl -form mhl.format Mail/inbox/2
 ],
 [0],
 [ -- using template mhl.format --
@@ -34,5 +34,28 @@ X-Envelope-Sender: alice@wonder.land
 I don't see any wine
 ]) 
 
+MH_CHECK([mhl repl],[mhl01 mhl.repl],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+mhl -form mhl.repl Mail/inbox/15
+],
+[0],
+[
+         Not the same thing a bit! You might just
+         as well say that "I see what I eat" is the same thing as "I eat
+         what I see"!
+])		  
+
+MH_CHECK([mhl usenet],[mhl02 mhl.usenet],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+mhl -form mhl.usenet Mail/inbox/15
+],
+[0],
+[
+In message <200207292200.3315@wonder.land>, Hatter writes:
+>Not the same thing a bit! You might just
+>as well say that "I see what I eat" is the same thing as "I eat
+>what I see"!
+])		  
+
 m4_popdef[MH_KEYWORDS])
 # End of mhl.at
diff --git a/mh/tests/mhparam.at b/mh/tests/mhparam.at
index 7d602d5..a363c46 100644
--- a/mh/tests/mhparam.at
+++ b/mh/tests/mhparam.at
@@ -22,10 +22,11 @@ Sequence-Negation: not
 Draft-Folder: Mail/drafts
 Aliasfile: .mh_aliases
 EOT
-mhparam -all | tr '\t' ' ' | sed 's/^Path:.*/Path: Mail/;s/  */ /g'
+mhparam -all | tr '\t' ' ' | sed 's/^Path:.*/Path: Mail/;s/^mhetcdir:.*/mhetcdir: dir/;s/  */ /g'
 ],
 [0],
 [Path: Mail
+mhetcdir: dir
 Sequence-Negation: not
 Draft-Folder: Mail/drafts
 Aliasfile: .mh_aliases
diff --git a/mh/tests/scan.at b/mh/tests/scan.at
index 9436742..9bd9888 100644
--- a/mh/tests/scan.at
+++ b/mh/tests/scan.at
@@ -22,8 +22,8 @@ echo "Current-Folder: inbox" > Mail/context
 scan | sed 's/ *$//'
 ],
 [0],
-[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   1  12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
@@ -34,8 +34,8 @@ MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 scan +inbox | sed 's/ *$//'
 ],
 [0],
-[   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
-   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
+[   1  12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
@@ -43,7 +43,7 @@ scan +inbox | sed 's/ *$//'
 
 MH_CHECK([scan -format],[scan02 scan-format],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
-scan +mbox1 -format '%4(msg) %(decode(friendly{from})) - %(decode(friendly{to}))'
+scan +mbox1 -format '%4(msg) %{from} - %{to}'
 ],
 [0],
 [   1 Foo Bar <foobar@nonexistent.net> - Bar <bar@dontmailme.org>
@@ -59,11 +59,11 @@ echo '%4(msg) %(decode(friendly{from})) - %(decode(friendly{to}))' > formfile
 scan +mbox1 -form formfile
 ],
 [0],
-[   1 Foo Bar <foobar@nonexistent.net> - Bar <bar@dontmailme.org>
-   2 Bar <bar@dontmailme.org> - Foo Bar <foobar@nonexistent.net>
-   3 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
-   4 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
-   5 Sergey Poznyakoff <gray@example.net> - Foo Bar <foobar@nonexistent.net>
+[   1 Foo Bar - Bar
+   2 Bar - Foo Bar
+   3 Sergey Poznyakoff - Foo Bar
+   4 Sergey Poznyakoff - Foo Bar
+   5 Sergey Poznyakoff - Foo Bar
 ])
 
 MH_CHECK([scan -reverse],[scan04 scan-reverse],[
@@ -74,8 +74,8 @@ scan +mbox1 -reverse | sed 's/ *$//'
 [   5  07/13 Sergey Poznyakoff  Empty MIME Parts<<------- =_aaaaaaaaaa0 Content-
    4  07/13 Sergey Poznyakoff  Nested MIME<<------- =_aaaaaaaaaa0 Content-Type:
    3  07/13 Sergey Poznyakoff  Simple MIME<<------- =_aaaaaaaaaa0 Content-Type:
-   2  12/28 Bar <bar@dontmail  Re: Jabberwocky<<It seems very pretty, but it's
-   1  12/28 Foo Bar <foobar@n  Jabberwocky<<`Twas brillig, and the slithy toves
+   2  12/28 Bar                Re: Jabberwocky<<It seems very pretty, but it's
+   1  12/28 Foo Bar            Jabberwocky<<`Twas brillig, and the slithy toves
 ])
 
 m4_popdef[MH_KEYWORDS])
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index f06f082..0b708f6 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -21,7 +21,10 @@ test -d Mail || mkdir Mail
 dir=`pwd`
 MH=$dir/mh_profile
 export MH
-echo "Path: $dir/Mail" > $MH
+cat > $MH <<EOT
+Path: $dir/Mail
+mhetcdir: $abs_top_srcdir/mh/etc
+EOT
 exec <&-
 ])
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 24 15:50:29 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLMIP-0003pY-Ib
	for mharc-commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:50:29 -0500
Received: from [140.186.70.92] (port=43200 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLMIN-0003pP-CR
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:50:29 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMIL-0007LV-CH
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:50:27 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:33658
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMIL-0007LK-5x
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 15:50:25 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMIK-000376-LZ
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 20:50:24 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMIK-0003lH-D1
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 20:50:24 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: e53b55870dd3c4166ea6658ea679d608e500172a
X-Git-Newrev: c3b9cfe405a73936906f5c81d83a1fa190c932f8
Message-Id: <E1PLMIK-0003lH-D1@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 24 Nov 2010 20:50:24 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-220-gc3b9cfe
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Nov 2010 20:50:29 -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=c3b9cfe405a73936906f5c81d83a1fa190c932f8

The branch, master has been updated
       via  c3b9cfe405a73936906f5c81d83a1fa190c932f8 (commit)
      from  e53b55870dd3c4166ea6658ea679d608e500172a (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 c3b9cfe405a73936906f5c81d83a1fa190c932f8
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 22:45:47 2010 +0200

    mh: minor changes in forw and repl; provide a set of traditional scan formats.
    
    * mh/.gitignore: Update.
    * mh/compcommon.c (mh_comp_draft): Rewrite using mh_find_file and
    simplify.  All callers changed.
    * mh/mh.h (mh_comp_draft): Change signature.
    * mh/comp.c (opt_handler) <ARGP_KEY_FINI>: Make sure formfile is
    initialized.
    * mh/forw.c: Likewise.
    * mh/repl.c (opt_handler): Remove unused variable.
    * mh/tests/comp.at (compcmd): Remove -form.
    * mh/tests/forw.at (forwcmd): Likewise.
    
    * mh/etc/.gitignore: New file.
    * mh/etc/Makefile.am: New file.
    * mh/etc/forwcomps: New file.
    * mh/etc/scan.default: New file.
    * mh/etc/scan.mailx: New file.
    * mh/etc/scan.size: New file.
    * mh/etc/scan.time: New file.
    * mh/etc/scan.timely: New file.

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

Summary of changes:
 mh/.gitignore                                  |    3 -
 mh/comp.c                                      |    7 ++-
 mh/compcommon.c                                |   61 ++++++++++--------------
 mh/etc/.gitignore                              |    3 +
 {libmu_sieve/extensions => mh/etc}/Makefile.am |   45 ++++++++++-------
 mh/etc/{components => forwcomps}               |    2 +-
 mh/etc/scan.default                            |   18 +++++++
 mh/etc/scan.mailx                              |   17 +++++++
 mh/etc/scan.size                               |   19 +++++++
 mh/etc/scan.time                               |   19 +++++++
 mh/etc/scan.timely                             |   22 +++++++++
 mh/forw.c                                      |    7 ++-
 mh/mh.h                                        |    3 +-
 mh/repl.c                                      |    2 -
 mh/tests/comp.at                               |    4 +-
 mh/tests/forw.at                               |    4 +-
 16 files changed, 166 insertions(+), 70 deletions(-)
 create mode 100644 mh/etc/.gitignore
 copy {libmu_sieve/extensions => mh/etc}/Makefile.am (54%)
 copy mh/etc/{components => forwcomps} (68%)
 create mode 100644 mh/etc/scan.default
 create mode 100644 mh/etc/scan.mailx
 create mode 100644 mh/etc/scan.size
 create mode 100644 mh/etc/scan.time
 create mode 100644 mh/etc/scan.timely

diff --git a/mh/.gitignore b/mh/.gitignore
index fecc9d2..0d106bb 100644
--- a/mh/.gitignore
+++ b/mh/.gitignore
@@ -8,14 +8,11 @@ ali
 anno
 burst
 comp
-elc-stamp
 fmtcheck
 folder
 forw
 inc
 install-mh
-mailutils-mh.el
-mailutils-mh.elc
 mark
 mh_alias.h
 mh_alias_gram.c
diff --git a/mh/comp.c b/mh/comp.c
index 7b62b95..cdb5c5a 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -146,6 +146,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       whatnowproc = NULL;
       break;
 
+    case ARGP_KEY_FINI:
+      if (!formfile)
+	mh_find_file ("components", &formfile);
+      break;
+	  
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -294,7 +299,7 @@ main (int argc, char **argv)
 	  
 	case DISP_REPLACE:
 	  unlink (wh_env.draftfile);
-	  mh_comp_draft (formfile, "components", wh_env.file);
+	  mh_comp_draft (formfile, wh_env.file);
 	}
     }
   
diff --git a/mh/compcommon.c b/mh/compcommon.c
index 83890c6..95facea 100644
--- a/mh/compcommon.c
+++ b/mh/compcommon.c
@@ -27,53 +27,44 @@ static char *default_format_str =
 "--------\n";
 
 void
-mh_comp_draft (const char *formfile, const char *defformfile,
-	       const char *draftfile)
+mh_comp_draft (const char *formfile, const char *draftfile)
 {
-  char *s = NULL;
-  if (formfile)
+  char *s;
+
+  if (mh_find_file (formfile, &s) == 0)
     {
-      s = mh_expand_name (MHLIBDIR, formfile, 0);
       if (mh_file_copy (s, draftfile))
 	exit (1);
+      free (s);
     }
   else
     {
-      s = mh_expand_name (MHLIBDIR, defformfile, 0);
-      if (access (s, R_OK) == 0)
+      /* I doubt if we need that: */
+      int rc;
+      mu_stream_t stream;
+      
+      if ((rc = mu_file_stream_create (&stream,
+				       draftfile,
+				       MU_STREAM_WRITE|MU_STREAM_CREAT)))
 	{
-	  if (mh_file_copy (s, draftfile))
-	    exit (1);
+	  mu_error (_("cannot open output file \"%s\": %s"),
+		    draftfile, mu_strerror (rc));
+	  exit (1);
 	}
-      else
+      
+      rc = mu_stream_write (stream, 
+			    default_format_str,
+			    strlen (default_format_str), NULL);
+      mu_stream_close (stream);
+      mu_stream_destroy (&stream);
+      
+      if (rc)
 	{
-	  int rc;
-	  mu_stream_t stream;
-	  
-	  if ((rc = mu_file_stream_create (&stream,
-					draftfile,
-					MU_STREAM_WRITE|MU_STREAM_CREAT)))
-	    {
-	      mu_error (_("cannot open output file \"%s\": %s"),
-			draftfile, mu_strerror (rc));
-	      exit (1);
-	    }
-	  
-	  rc = mu_stream_write (stream, 
-				default_format_str,
-				strlen (default_format_str), NULL);
-	  mu_stream_close (stream);
-	  mu_stream_destroy (&stream);
-
-	  if (rc)
-	    {
-	      mu_error (_("error writing to \"%s\": %s"),
-			draftfile, mu_strerror (rc));
-	      exit (1);
-	    }
+	  mu_error (_("error writing to \"%s\": %s"),
+		    draftfile, mu_strerror (rc));
+	  exit (1);
 	}
     }
-  free (s);
 }
 
 int 
diff --git a/mh/etc/.gitignore b/mh/etc/.gitignore
new file mode 100644
index 0000000..b250ab2
--- /dev/null
+++ b/mh/etc/.gitignore
@@ -0,0 +1,3 @@
+elc-stamp
+mailutils-mh.el
+mailutils-mh.elc
diff --git a/libmu_sieve/extensions/Makefile.am b/mh/etc/Makefile.am
similarity index 54%
copy from libmu_sieve/extensions/Makefile.am
copy to mh/etc/Makefile.am
index 391d191..f8c0f3c 100644
--- a/libmu_sieve/extensions/Makefile.am
+++ b/mh/etc/Makefile.am
@@ -1,5 +1,5 @@
 ## This file is part of GNU Mailutils.
-## Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 Free Software
+## Copyright (C) 2001, 2002, 2003, 2007, 2009, 2010 Free Software
 ## Foundation, Inc.
 ##
 ## GNU Mailutils is free software; you can redistribute it and/or
@@ -15,28 +15,35 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
 
-moddir=@MU_SIEVE_MODDIR@
-mod_LTLIBRARIES = \
- list.la\
- moderator.la\
- pipe.la\
- spamd.la\
- timestamp.la\
- vacation.la
+mhlibdir   = $(pkgdatadir)/mh
 
-INCLUDES = @MU_APP_COMMON_INCLUDES@ 
+LISPSRC    = mailutils-mh.el
+lisp_LISP  = @lisp_LISP@
+EXTRA_LISP = mailutils-mh.el
 
-AM_LDFLAGS = -module -avoid-version -no-undefined -rpath '$(moddir)' 
+MH_FILES   = \
+ components\
+ forwcomps\
+ mhl.format\
+ mhl.forward\
+ mhl.repl\
+ mhl.usenet\
+ replcomps\
+ replgroupcomps\
+ scan.default\
+ scan.mailx\
+ scan.size\
+ scan.time\
+ scan.timely
 
-list_la_SOURCES = list.c
-LIBS = ../libmu_sieve.la 
+mhlib_DATA = $(MH_FILES) $(LISPSRC)
 
-moderator_la_SOURCES = moderator.c
+EXTRA_DIST = $(MH_FILES) mailutils-mh.eli
+DISTCLEANFILES = mailutils-mh.el
 
-spamd_la_SOURCES = spamd.c
+SUFFIXES = .eli .el
+mailutils-mh.el: mailutils-mh.eli
 
-timestamp_la_SOURCES = timestamp.c
+.eli.el:
+	sed "s,BINDIR,$(bindir),g;s,MHLIBDIR,$(mhlibdir),g" $< > $@
 
-vacation_la_SOURCES = vacation.c
-
-pipe_la_SOURCES = pipe.c
diff --git a/mh/etc/components b/mh/etc/forwcomps
similarity index 68%
copy from mh/etc/components
copy to mh/etc/forwcomps
index 512352e..7926e6f 100644
--- a/mh/etc/components
+++ b/mh/etc/forwcomps
@@ -1,4 +1,4 @@
-;; Default components file for GNU MH.
+;; Default forward components file for GNU MH.
 ;; Lines beginning with ; are ignored.  Rest of lines is copied verbatim.
 To:
 cc:
diff --git a/mh/etc/scan.default b/mh/etc/scan.default
new file mode 100644
index 0000000..c0fbf8a
--- /dev/null
+++ b/mh/etc/scan.default
@@ -0,0 +1,18 @@
+%; Default scan format GNU MH.
+%;
+%; GNU Mailutils -- a suite of utilities for electronic mail
+%; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+%; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+%;
+%; NOTE: This file is not actually used and is supplied for your reference
+%;       only.  It shows the default format string, which is compiled into
+%;       "scan".
+%4(msg)\
+%<(cur)+%| %>\
+%<{replied}-%?{encrypted}E%| %>\
+%02(mon{date})/%02(mday{date})\
+%<{date} %|*%>\
+%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\
+%<(zero)%17(decode(friendly{from}))%>\
+  %(decode{subject})%<{body}<<%{body}>>%>
+%; End of scan.default
diff --git a/mh/etc/scan.mailx b/mh/etc/scan.mailx
new file mode 100644
index 0000000..dd92509
--- /dev/null
+++ b/mh/etc/scan.mailx
@@ -0,0 +1,17 @@
+%; Mimic the mailx(1) output.
+%;
+%; GNU Mailutils -- a suite of utilities for electronic mail
+%; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+%; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+%;
+%<(cur)>%| %>\
+%<{status} %|N%>\
+%<{replied}R%?{encrypted}E%| %>\
+%4(msg) \
+%<(mymbox{from})%<{to}To: %13(decode(friendly{to}))%>%>\
+%<(zero)%17(decode(friendly{from}))%> \
+%3(day{date}) %3(month{date}) %02(mday{date}) \
+%02(hour{date}):%02(min{date}) \
+%(decode{subject})
+%; End of scan.mailx
+
diff --git a/mh/etc/scan.size b/mh/etc/scan.size
new file mode 100644
index 0000000..097567e
--- /dev/null
+++ b/mh/etc/scan.size
@@ -0,0 +1,19 @@
+%; "Size"-format for GNU MH scan.
+%;
+%; GNU Mailutils -- a suite of utilities for electronic mail
+%; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+%; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+%;
+%; This format is similar to scan.default, except that it prints the
+%; size of the message before the sender name column.
+%;
+%4(msg)\
+%<(cur)+%| %>\
+%<{replied}-%?{encrypted}E%| %>\
+%02(mon{date})/%02(mday{date})\
+%<{date} %|*%>\
+%5(size) \
+%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\
+%<(zero)%17(decode(friendly{from}))%>\
+  %(decode{subject})%<{body}<<%{body}%>
+%; End of scan.size
diff --git a/mh/etc/scan.time b/mh/etc/scan.time
new file mode 100644
index 0000000..83863ad
--- /dev/null
+++ b/mh/etc/scan.time
@@ -0,0 +1,19 @@
+%; "Time"-format for GNU MH scan.
+%;
+%; GNU Mailutils -- a suite of utilities for electronic mail
+%; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+%; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+%;
+%; This format is similar to scan.default, except that it prints the
+%; date in 1-minute resolution and adds a timezone.
+%;
+%4(msg)\
+%<(cur)+%| %>\
+%<{replied}-%?{encrypted}E%| %>\
+%02(mon{date})/%02(mday{date})\
+ %02(hour{date}):%02(min{date})%3(tzone{date})\
+%<{date} %|*%>\
+%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\
+%<(zero)%17(decode(friendly{from}))%>\
+  %(decode{subject})%<{body}<<%{body}%>
+%; End of scan.time
diff --git a/mh/etc/scan.timely b/mh/etc/scan.timely
new file mode 100644
index 0000000..5256565
--- /dev/null
+++ b/mh/etc/scan.timely
@@ -0,0 +1,22 @@
+%; "Timely"-format for GNU MH scan.
+%;
+%; GNU Mailutils -- a suite of utilities for electronic mail
+%; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+%; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
+%;
+%; The time output in this format depends on the time difference between
+%; the current time and the time being printed.
+%;
+%4(msg)\
+%<(cur)+%| %>\
+%<{replied}-%?{encrypted}E%| %>\
+%(void(rclock{date}))\
+%<(gt 15768000)%03(month{date})%(void(year{date}))%02(modulo 100)\
+%?(gt 604800)%02(mday{date})%03(month{date})\
+%?(gt 86400) %(day{date}) %|\
+%02(hour{date}):%02(min{date})%>\
+%<{date} %|*%>\
+%<(mymbox{from})%<{to}To:%14(decode(friendly{to}))%>%>\
+%<(zero)%17(decode(friendly{from}))%>\
+  %(decode{subject})%<{body}<<%{body}%>
+%; End of scan.timely
\ No newline at end of file
diff --git a/mh/forw.c b/mh/forw.c
index 60baaaf..7539176 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -225,6 +225,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       whatnowproc = NULL;
       break;
 
+    case ARGP_KEY_FINI:
+      if (!formfile)
+	mh_find_file ("forwcomps", &formfile);
+      break;
+      
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -522,7 +527,7 @@ main (int argc, char **argv)
       
     case DISP_REPLACE:
       unlink (wh_env.draftfile);
-      mh_comp_draft (formfile, "forwcomps", wh_env.file);
+      mh_comp_draft (formfile, wh_env.file);
       finish_draft ();
     }
   
diff --git a/mh/mh.h b/mh/mh.h
index 21be165..07cb096 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -378,8 +378,7 @@ int mh_seq_delete (mu_mailbox_t mbox, const char *name, mh_msgset_t *mset,
 		   int flags);
 const char *mh_seq_read (mu_mailbox_t mbox, const char *name, int flags);
 
-void mh_comp_draft (const char *formfile, const char *defformfile,
-		    const char *draftfile);
+void mh_comp_draft (const char *formfile, const char *draftfile);
 int check_draft_disposition (struct mh_whatnow_env *wh, int use_draft);
 
 void ali_parse_error (const char *fmt, ...) MU_PRINTFLIKE(1,2); 
diff --git a/mh/repl.c b/mh/repl.c
index c7ca5b3..ca76f1b 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -139,8 +139,6 @@ decode_cc_flag (const char *opt, const char *arg)
 static error_t
 opt_handler (int key, char *arg, struct argp_state *state)
 {
-  char *s;
-  
   switch (key)
     {
     case ARGP_KEY_INIT:
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index 4ffa81b..fee2040 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -15,9 +15,7 @@
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 m4_pushdef([MH_KEYWORDS],[comp])
-m4_pushdef([compcmd],[comp dnl
--form components dnl
--editor $abs_top_srcdir/mh/tests/mhed])
+m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
 
 MH_CHECK([comp -file],[comp00 comp-file],[
 dir=`pwd`
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
index 16c83da..0b68122 100644
--- a/mh/tests/forw.at
+++ b/mh/tests/forw.at
@@ -15,9 +15,7 @@
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 m4_pushdef([MH_KEYWORDS],[forw])
-m4_pushdef([forwcmd],[forw dnl
--form components dnl
--editor $abs_top_srcdir/mh/tests/mhed])
+m4_pushdef([forwcmd],[forw -editor $abs_top_srcdir/mh/tests/mhed])
 
 MH_CHECK([forw msg],[forw00 forw-msg],[
 mkdir Mail/inbox


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 24 16:34:26 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLMyw-0001se-QC
	for mharc-commit-mailutils@gnu.org; Wed, 24 Nov 2010 16:34:26 -0500
Received: from [140.186.70.92] (port=40300 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLMyu-0001qe-L7
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 16:34:25 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMyt-0008JP-Cd
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 16:34:24 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:35613
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMyt-0008JG-9v
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 16:34:23 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMys-0003Zx-Ue
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 21:34:22 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLMys-0006wx-MA
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 21:34:22 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: c3b9cfe405a73936906f5c81d83a1fa190c932f8
X-Git-Newrev: 08ee8ee88d79d84ddc12b8bed8a4e297580a2887
Message-Id: <E1PLMys-0006wx-MA@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 24 Nov 2010 21:34:22 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-221-g08ee8ee
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Nov 2010 21:34:25 -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=08ee8ee88d79d84ddc12b8bed8a4e297580a2887

The branch, master has been updated
       via  08ee8ee88d79d84ddc12b8bed8a4e297580a2887 (commit)
      from  c3b9cfe405a73936906f5c81d83a1fa190c932f8 (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 08ee8ee88d79d84ddc12b8bed8a4e297580a2887
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Nov 24 23:33:59 2010 +0200

    mh: add a forgotten file.
    
    * mh/tests/movemsg: add to the repository.

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

Summary of changes:
 mh/tests/movemsg |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
 create mode 100755 mh/tests/movemsg

diff --git a/mh/tests/movemsg b/mh/tests/movemsg
new file mode 100755
index 0000000..bce34c1
--- /dev/null
+++ b/mh/tests/movemsg
@@ -0,0 +1,5 @@
+#! /bin/sh
+set -e
+dir=`mhpath +`/removed
+test -d $dir || mkdir $dir
+mv $* $dir


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Nov 24 17:32:50 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLNtR-0001eI-TS
	for mharc-commit-mailutils@gnu.org; Wed, 24 Nov 2010 17:32:49 -0500
Received: from [140.186.70.92] (port=55902 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLNtP-0001eB-HA
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 17:32:48 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLNtO-0004Cr-Ak
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 17:32:47 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:42742
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLNtO-0004Cn-80
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 17:32:46 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLNtO-0004I2-2q
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 22:32:46 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLNtI-00032n-FR
	for commit-mailutils@gnu.org; Wed, 24 Nov 2010 22:32:46 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 08ee8ee88d79d84ddc12b8bed8a4e297580a2887
X-Git-Newrev: 80bb8b2fc30ba04dda9eb652519c65897542437e
Message-Id: <E1PLNtI-00032n-FR@vcs-noshell.in.savannah.gnu.org>
Date: Wed, 24 Nov 2010 22:32:41 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-222-g80bb8b2
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Wed, 24 Nov 2010 22:32:48 -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=80bb8b2fc30ba04dda9eb652519c65897542437e

The branch, master has been updated
       via  80bb8b2fc30ba04dda9eb652519c65897542437e (commit)
      from  08ee8ee88d79d84ddc12b8bed8a4e297580a2887 (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 80bb8b2fc30ba04dda9eb652519c65897542437e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 25 00:30:29 2010 +0200

    mhn: minor changes.
    
    * mh/etc/mhl.headers: New file.
    * mh/etc/Makefile.am (MH_FILES): Add mhl.headers.
    * mh/mhn.c (opt_handler): Use mh_find_file to
    resolve format file name.
    (mhn_show): Always open the formfile.
    (copy_header_to_stream): Rewrite using mu_stream_copy + HEADER filter.

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

Summary of changes:
 mh/etc/Makefile.am                 |    1 +
 mh/etc/{mhl.format => mhl.headers} |   17 +++++------
 mh/mhn.c                           |   54 ++++++++++++++++-------------------
 3 files changed, 34 insertions(+), 38 deletions(-)
 copy mh/etc/{mhl.format => mhl.headers} (50%)

diff --git a/mh/etc/Makefile.am b/mh/etc/Makefile.am
index f8c0f3c..b4d4397 100644
--- a/mh/etc/Makefile.am
+++ b/mh/etc/Makefile.am
@@ -26,6 +26,7 @@ MH_FILES   = \
  forwcomps\
  mhl.format\
  mhl.forward\
+ mhl.headers\
  mhl.repl\
  mhl.usenet\
  replcomps\
diff --git a/mh/etc/mhl.format b/mh/etc/mhl.headers
similarity index 50%
copy from mh/etc/mhl.format
copy to mh/etc/mhl.headers
index 4b6b7cb..7ae5943 100644
--- a/mh/etc/mhl.format
+++ b/mh/etc/mhl.headers
@@ -1,21 +1,20 @@
-; This is the default mhl.format file for Mailutils MH.
+; mhl.headers
 ;
 ; GNU Mailutils -- a suite of utilities for electronic mail
-; Copyright (C) 2003, 2010 Free Software Foundation, Inc.
+; Copyright (C) 2010 Free Software Foundation, Inc.
 ; Distributed under GPLv3+.  See <http://gnu.org/licenses/gpl.html>.
 ;
-: -- using template mhl.format --
+; Mhn uses this format file for displaying headers in MIME messages. 
+;
 overflowtext="***",overflowoffset=5
 leftadjust,compwidth=9
-ignores=msgid,message-id,received
+ignores=msgid,message-id,received,content-type,content-transfer-encoding,content-id
 Date:formatfield="%<(nodate{text})%{text}%|%(pretty{text})%>"
 To:
 cc:
-: 
-From:
-Subject:
+From:decode
+Subject:decode
 :
 extras:nocomponent
 :
-body:nocomponent,overflowtext=,overflowoffset=0,noleftadjust
-; End of mhl.format
\ No newline at end of file
+; End of mhl.headers
diff --git a/mh/mhn.c b/mh/mhn.c
index 5ddfece..69aa832 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -96,6 +96,7 @@ static struct argp_option options[] = {
 /* Traditional MH options */
 struct mh_option mh_option[] = {
   { "file",          MH_OPT_ARG, "filename" },
+  { "compose" },
   { "list",          MH_OPT_BOOL },
   { "headers",       MH_OPT_BOOL },
   { "realsize",      MH_OPT_BOOL },
@@ -357,7 +358,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
       break;
 
     case ARG_FORM:
-      formfile = arg;
+      mh_find_file (arg, &formfile);
       break;
 
       /* Common options */
@@ -390,6 +391,11 @@ opt_handler (int key, char *arg, struct argp_state *state)
       charset = arg;
       break;
       
+    case ARGP_KEY_FINI:
+      if (!formfile)
+	mh_find_file ("mhl.headers", &formfile);
+      break;
+      
     default:
       return ARGP_ERR_UNKNOWN;
     }
@@ -1444,22 +1450,7 @@ mhn_show ()
       exit (1);
     }
   
-  if (formfile)
-    {
-      char *s = mh_expand_name (MHLIBDIR, "mhl.headers", 0);
-      if (access (s, R_OK) == 0)
-	formfile = "mhl.headers";
-      free (s);
-    }
-
-  if (formfile)
-    {
-      char *s = mh_expand_name (MHLIBDIR, formfile, 0);
-      mhl_format = mhl_format_compile (s);
-      if (!mhl_format)
-	exit (1);
-      free (s);
-    }
+  mhl_format = mhl_format_compile (formfile);
     
   if (message)
     rc = show_message (message, 0, ostr);
@@ -1895,22 +1886,27 @@ copy_header (mu_message_t msg, mu_header_t out)
 void
 copy_header_to_stream (mu_message_t msg, mu_stream_t stream)
 {
+  int rc;
   mu_header_t hdr;
-  mu_stream_t in;
-  char *buf = NULL;
-  size_t bufsize = 0, n = 0;
-  
+  mu_stream_t flt, str;
+
   mu_message_get_header (msg, &hdr);
-  mu_header_get_streamref (hdr, &in);
-  /* FIXME: Use mu_stream_copy */
-  while (mu_stream_getline (in, &buf, &bufsize, &n) == 0 && n > 0)
+  mu_header_get_streamref (hdr, &str);
+  rc = mu_filter_create (&flt, str, "HEADER",
+			 MU_FILTER_DECODE, MU_STREAM_READ);
+  mu_stream_unref (str);
+  if (rc)
     {
-      if (n == 1 && buf[0] == '\n')
-	break;
-      mu_stream_write (stream, buf, n, NULL);
+      mu_error (_("cannot open filter stream: %s"), mu_strerror (rc));
+      exit (1);
     }
-  mu_stream_destroy (&in);
-  free (buf);
+  rc = mu_stream_copy (stream, flt, 0, NULL);
+  if (rc)
+    {
+      mu_error (_("error reading headers: %s"), mu_strerror (rc));
+      exit (1);
+    }
+  mu_stream_destroy (&flt);
 }
 
 void


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 25 13:37:36 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLghM-00030T-7X
	for mharc-commit-mailutils@gnu.org; Thu, 25 Nov 2010 13:37:36 -0500
Received: from [140.186.70.92] (port=39450 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLghH-0002tX-QF
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 13:37:34 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLghF-0004PL-4I
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 13:37:31 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:42313
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLghE-0004PG-VI
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 13:37:29 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLghE-0001OH-Jt
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 18:37:28 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLgh4-0008SK-Kw
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 18:37:28 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 80bb8b2fc30ba04dda9eb652519c65897542437e
X-Git-Newrev: 9df638667be69868851e0882eb172b1476ff962d
Message-Id: <E1PLgh4-0008SK-Kw@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 25 Nov 2010 18:37:19 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-225-g9df6386
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Nov 2010 18:37:34 -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=9df638667be69868851e0882eb172b1476ff962d

The branch, master has been updated
       via  9df638667be69868851e0882eb172b1476ff962d (commit)
       via  bf613ed8c4661faa1e9c1de7f28a7e03c5652ec0 (commit)
       via  8acde412feee7235b342196182c69d0ed25fe1fc (commit)
      from  80bb8b2fc30ba04dda9eb652519c65897542437e (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 9df638667be69868851e0882eb172b1476ff962d
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 25 20:16:38 2010 +0200

    Remove obsolete function.
    
    * include/mailutils/body.h (mu_body_get_filename): Remove proto.
    * include/mailutils/sys/body.h (_mu_body) <filename>: Remove.
    * libmailutils/mailbox/body.c (mu_body_get_filename): Remove
    obsolete function.
    (_body_get_stream): Use mu_temp_file_stream_create.
    * libmailutils/stream/temp_file_stream.c (mu_temp_file_stream_create):
    Return EINVAL if flags is set, but hints is NULL.
    * libmu_scm/mu_body.c (mu_scm_body_print): Don't use mu_body_get_filename.

commit bf613ed8c4661faa1e9c1de7f28a7e03c5652ec0
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 25 19:32:07 2010 +0200

    temp_file_stream: Use mu_tempfile_hints to control how the file name is created.
    
    * include/mailutils/stream.h (mu_temp_file_stream_create): Change signature.
    * include/mailutils/sys/Makefile.am (sysinclude_HEADERS): Add temp_file_stream.h
    * include/mailutils/util.h (mu_tempfile_hints): Remove const qualifiers.
    * libmailutils/stream/temp_file_stream.c: Include sys/temp_file_stream.h.
    (fd_temp_open): Use data from struct _mu_temp_file_stream.
    (fd_temp_done): New function.
    (mu_temp_file_stream_create): Take hints and flags as arguments.
    
    * examples/mta.c: Update calls to mu_temp_file_stream_create.
    * libproto/mbox/mbox.c: Likewise.
    * libproto/pop/mbox.c: Likewise.
    * maidag/deliver.c: Likewise.
    * maidag/lmtp.c: Likewise.
    * mh/burst.c: Likewise.
    * mh/prompter.c: Likewise.

commit 8acde412feee7235b342196182c69d0ed25fe1fc
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 25 17:12:32 2010 +0200

    Rewrite temporary file handling.
    
    * include/mailutils/util.h (mu_make_file_name_suf): New proto.
    (mu_make_file_name): Replace with a macro.
    (MU_TEMPFILE_TMPDIR,MU_TEMPFILE_SUFFIX)
    (MU_TEMPFILE_MKDIR): New flags.
    (mu_tempfile_hints): New struct.
    (mu_tempfile): Change signature.
    * libmailutils/base/tempfile.c (mu_create_temp_file): New function.
    (mu_tempfile): Rewrite from scratch.  Change signature.  All callers
    changed.
    * libmailutils/string/mkfilename.c (mu_make_file_name): Remove.
    (mu_make_file_name_suf): New function.
    
    * libmailutils/stream/streamcpy.c (mu_stream_copy): Don't return EIO
    on EOF.
    * libmailutils/stream/file_stream.c (mu_fd_stream_create): If
    MU_STREAM_SEEK is set, position fd to 0.
    
    * guimb/collect.c: Update calls to mu_tempfile.
    * lib/mailcap.c: Likewise.
    * libmailutils/base/amd.c (_amd_tempfile): Rewrite using mu_tempfile.
    
    * libmailutils/tests/tempfile.c: New file.
    * libmailutils/tests/Makefile.am (noinst_PROGRAMS): Add tempfile.

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

Summary of changes:
 examples/mta.c                                     |    2 +-
 guimb/collect.c                                    |    3 +-
 include/mailutils/body.h                           |    2 -
 include/mailutils/stream.h                         |    4 +-
 include/mailutils/sys/Makefile.am                  |    1 +
 include/mailutils/sys/body.h                       |    1 -
 .../sys/{prog_stream.h => temp_file_stream.h}      |   26 ++--
 include/mailutils/util.h                           |   22 ++-
 lib/mailcap.c                                      |    5 +-
 libmailutils/base/amd.c                            |   23 ++-
 libmailutils/base/tempfile.c                       |  204 ++++++++++++++++----
 libmailutils/mailbox/body.c                        |   32 +---
 libmailutils/stream/file_stream.c                  |   14 +-
 libmailutils/stream/streamcpy.c                    |    9 +-
 libmailutils/stream/temp_file_stream.c             |   54 ++++--
 libmailutils/string/mkfilename.c                   |   11 +-
 libmailutils/tests/Makefile.am                     |    1 +
 libmailutils/tests/tempfile.c                      |  169 ++++++++++++++++
 libmu_scm/mu_body.c                                |    9 +-
 libproto/mbox/mbox.c                               |    2 +-
 libproto/pop/mbox.c                                |    2 +-
 maidag/deliver.c                                   |    2 +-
 maidag/lmtp.c                                      |    2 +-
 mail/escape.c                                      |   15 +-
 mail/send.c                                        |   22 ++-
 mh/burst.c                                         |    2 +-
 mh/prompter.c                                      |    2 +-
 27 files changed, 491 insertions(+), 150 deletions(-)
 copy include/mailutils/sys/{prog_stream.h => temp_file_stream.h} (68%)
 create mode 100644 libmailutils/tests/tempfile.c

diff --git a/examples/mta.c b/examples/mta.c
index bff83d5..15a0de7 100644
--- a/examples/mta.c
+++ b/examples/mta.c
@@ -198,7 +198,7 @@ make_tmp (mu_stream_t in)
   size_t size = 0, n;
   mu_message_t mesg;
   
-  rc = mu_temp_file_stream_create (&out, NULL);
+  rc = mu_temp_file_stream_create (&out, NULL, 0);
   if (rc)
     {
       mu_error (_("unable to open temporary file: %s"), mu_strerror (rc));
diff --git a/guimb/collect.c b/guimb/collect.c
index 342e593..8530095 100644
--- a/guimb/collect.c
+++ b/guimb/collect.c
@@ -55,8 +55,7 @@ collect_open_mailbox_file ()
   int fd;
 
   /* Create input mailbox */
-  fd = mu_tempfile (NULL, &temp_filename);
-  if (fd == -1)
+  if (mu_tempfile (NULL, 0, &fd, &temp_filename))
     exit (1);
 
   temp_file = fdopen (fd, "w");
diff --git a/include/mailutils/body.h b/include/mailutils/body.h
index 2a116e8..3256765 100644
--- a/include/mailutils/body.h
+++ b/include/mailutils/body.h
@@ -39,8 +39,6 @@ extern int mu_body_set_get_stream (mu_body_t,
 				   int (*) (mu_body_t, mu_stream_t *),
 				   void *owner);
   
-extern int mu_body_get_filename   (mu_body_t, char *, size_t, size_t *);
-
 extern int mu_body_size           (mu_body_t, size_t *);
 extern int mu_body_set_size       (mu_body_t,
 				int (*_size) (mu_body_t, size_t*), void *owner);
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index ba8c9bc..de980d3 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -192,7 +192,9 @@ int mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
 
 
 int mu_file_stream_create (mu_stream_t *pstream, const char *filename, int flags);
-int mu_temp_file_stream_create (mu_stream_t *pstream, const char *dir);
+struct mu_tempfile_hints;  
+int mu_temp_file_stream_create (mu_stream_t *pstream,
+				struct mu_tempfile_hints *hints, int flags);
 int mu_fd_stream_create (mu_stream_t *pstream, char *filename, int fd,
 			 int flags);
 
diff --git a/include/mailutils/sys/Makefile.am b/include/mailutils/sys/Makefile.am
index 0ef9f33..7904561 100644
--- a/include/mailutils/sys/Makefile.am
+++ b/include/mailutils/sys/Makefile.am
@@ -53,6 +53,7 @@ sysinclude_HEADERS = \
  streamref.h\
  streamtrans.h\
  stream.h\
+ temp_file_stream.h\
  tls-stream.h\
  url.h\
  xscript-stream.h
diff --git a/include/mailutils/sys/body.h b/include/mailutils/sys/body.h
index a7be7eb..5de5e56 100644
--- a/include/mailutils/sys/body.h
+++ b/include/mailutils/sys/body.h
@@ -32,7 +32,6 @@ extern "C" {
 struct _mu_body
 {
   void *owner;
-  char *filename;
   mu_stream_t stream;
   mu_stream_t fstream;
   int flags;
diff --git a/include/mailutils/sys/prog_stream.h b/include/mailutils/sys/temp_file_stream.h
similarity index 68%
copy from include/mailutils/sys/prog_stream.h
copy to include/mailutils/sys/temp_file_stream.h
index fa042f2..fdb1725 100644
--- a/include/mailutils/sys/prog_stream.h
+++ b/include/mailutils/sys/temp_file_stream.h
@@ -14,22 +14,22 @@
    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/>. */
 
-#ifndef _MAILUTILS_SYS_PROG_STREAM_H
-#define _MAILUTILS_SYS_PROG_STREAM_H
+#ifndef _MAILUTILS_SYS_TEMP_FILE_STREAM_H
+#define _MAILUTILS_SYS_TEMP_FILE_STREAM_H
 
-#include <mailutils/sys/stream.h>
+#include <mailutils/types.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/file_stream.h>
+#include <mailutils/util.h>
 
-struct _mu_prog_stream
+struct _mu_temp_file_stream
 {
-  struct _mu_stream stream;
-  pid_t pid;
-  int status;
-  pid_t writer_pid;
-  int argc;
-  char **argv;
-  mu_stream_t in, out;
-
-  mu_stream_t input;
+  struct _mu_file_stream stream;
+  struct mu_tempfile_hints hints;
+  int hflags;
+  void (*file_done) (struct _mu_stream *str);
 };
 
 #endif
+
+  
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index 9d3fff4..0df84a8 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -82,9 +82,27 @@ char *mu_tilde_expansion (const char *ref, const char *delim,
 int mu_readlink (const char *name, char **pbuf, size_t *psize, size_t *plen);
 int mu_unroll_symlink (const char *name, char **pout);
 char *mu_getcwd (void);
-int mu_tempfile (const char *tmpdir, char **namep);
+char *mu_make_file_name_suf (const char *dir, const char *file,
+			     const char *suf);
+#define mu_make_file_name(dir, file) mu_make_file_name_suf (dir, file, NULL)
+
+  /* ------------------------ */
+  /* Temporary file creation. */
+  /* ------------------------ */
+#define MU_TEMPFILE_TMPDIR  0x01   /* tmpdir is set */
+#define MU_TEMPFILE_SUFFIX  0x02   /* suffix is set */  
+#define MU_TEMPFILE_MKDIR   0x04   /* create a directory, not a file */
+  
+struct mu_tempfile_hints
+{
+  char *tmpdir;
+  char *suffix;
+};
+
+  /*int mu_tempfile (const char *tmpdir, char **namep);*/
+int mu_tempfile (struct mu_tempfile_hints *hints, int flags,
+		 int *pfd, char **namep);
 char *mu_tempname (const char *tmpdir);
-char *mu_make_file_name (const char *dir, const char *file);
   
   /* ----------------------- */
   /* Current user email.     */
diff --git a/lib/mailcap.c b/lib/mailcap.c
index c0396d2..cbe9e1e 100644
--- a/lib/mailcap.c
+++ b/lib/mailcap.c
@@ -197,6 +197,7 @@ mime_context_get_content_type_value (struct mime_context *ctx,
   return rc;
 }
 
+/* FIXME: Rewrite via mu_stream_copy */
 static void
 mime_context_write_input (struct mime_context *ctx, int fd)
 {
@@ -219,8 +220,8 @@ mime_context_get_temp_file (struct mime_context *ctx, char **ptr)
 {
   if (!ctx->temp_file)
     {
-      int fd = mu_tempfile (NULL, &ctx->temp_file);
-      if (fd == -1)
+      int fd;
+      if (mu_tempfile (NULL, 0, &fd, &ctx->temp_file))
 	return -1;
       mime_context_write_input (ctx, fd);
       close (fd);
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index d51f941..db665b4 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -597,13 +597,18 @@ amd_quick_get_message (mu_mailbox_t mailbox, mu_message_qid_t qid,
   return ENOSYS;
 }
 
-static FILE *
-_amd_tempfile(struct _amd_data *amd, char **namep)
+static int
+_amd_tempfile (struct _amd_data *amd, FILE **pfile, char **namep)
 {
-  int fd = mu_tempfile (amd->name, namep);
-  if (fd == -1)
-      return NULL;
-  return fdopen (fd, "w");
+  struct mu_tempfile_hints hints;
+  int fd, rc;
+
+  hints.tmpdir = amd->name;
+  rc = mu_tempfile (&hints, MU_TEMPFILE_TMPDIR, &fd, namep);
+  if (rc == 0)
+    if ((*pfile = fdopen (fd, "w")) == NULL)
+      rc = errno;
+  return rc;
 }
 
 static int
@@ -658,11 +663,11 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
       return status;
     }      
     
-  fp = _amd_tempfile (mhm->amd, &name);
-  if (!fp)
+  status = _amd_tempfile (mhm->amd, &fp, &name);
+  if (status)
     {
       free (msg_name);
-      return errno;
+      return status;
     }
 
   /* Try to allocate large buffer */
diff --git a/libmailutils/base/tempfile.c b/libmailutils/base/tempfile.c
index 951e039..f494a3a 100644
--- a/libmailutils/base/tempfile.c
+++ b/libmailutils/base/tempfile.c
@@ -22,6 +22,8 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/time.h>
+#include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -33,62 +35,177 @@
 #include <mailutils/errno.h>
 #include <mailutils/util.h>
 
-/* Create and open a temporary file. Be very careful about it, since we
-   may be running with extra privilege i.e setgid().
-   Returns file descriptor of the open file.
-   If namep is not NULL, the pointer to the malloced file name will
-   be stored there. Otherwise, the file is unlinked right after open,
-   i.e. it will disappear after close(fd). */
-
 #ifndef P_tmpdir
 # define P_tmpdir "/tmp"
 #endif
 
+/* Lower level call.
+
+   Create a temporary file with the name according to the pattern FILENAME.
+   FILENAME must end with any amount of Xs, optionally followed by
+   SUFLEN other characters.
+
+   If ISDIR is not 0, create a directory (privileges 0700), otherwise
+   create a file (privileges 0600).
+
+   On success, return 0.  If pfd is not NULL (and ISDIR is 0), open the
+   created file and store the descriptor in *PFD.  Return actual file
+   name in FILENAME.
+
+   On error, return error code.
+*/   
 int
-mu_tempfile (const char *tmpdir, char **namep)
+mu_create_temp_file (char *filename, size_t suflen, int *pfd, int isdir)
 {
-  char *filename;
-  int fd;
+  int rc;
+  size_t len;
+  char *carrybuf;
+  char *p, *cp, *start, *end;
+  struct stat st;
+  static int first_call;
+  static char randstate[256];
+  static const unsigned char alphabet[] =
+    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+  if (!first_call)
+    {
+      /* Initialize random number generator */
+      struct timeval tv;
+      gettimeofday (&tv, NULL);
+      initstate (((unsigned long) tv.tv_usec << 16) ^ tv.tv_sec,
+		 randstate, sizeof (randstate));
+      first_call = 1;
+    }
+  setstate (randstate);
   
-  if (!tmpdir)
-    tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : P_tmpdir;
-
-  filename = mu_make_file_name (tmpdir, "muXXXXXX");
-  if (!filename)
+  /* Start with the last filename character before suffix */
+  end = filename + strlen (filename) - suflen - 1;
+  /* Fill X's with random characters */
+  for (p = end; p >= filename && *p == 'X'; p--)
+    *p = alphabet[random () % (sizeof (alphabet) - 1)];
+  len = end - p;
+  if (len == 0)
+    return EINVAL;
+  start = p + 1;
+
+  carrybuf = malloc (len);
+  if (!carrybuf)
+    return ENOMEM;
+
+  /* Fill in the carry buffer */
+  memcpy (carrybuf, start, len);
+
+  for (;;)
     {
-      mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
-      return -1;
+      if (isdir)
+	{
+	  if (mkdir (filename, 0700) == 0)
+	    {
+	      rc = 0;
+	      break;
+	    }
+	}
+      else if (pfd)
+	{
+	  if ((*pfd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0)
+	    {
+	      rc = 0;
+	      break;
+	    }
+	}
+      else if (lstat (filename, &st) && errno == ENOENT)
+	{
+	  rc = 0;
+	  break;
+	}
+      
+      if (errno != EEXIST)
+	{
+	  rc = errno;
+	  break;
+	}
+
+      for (p = start, cp = carrybuf;; p++, cp++)
+	{
+	  char *q;
+	  
+	  if (p == end)
+	    /* All permutation exhausted */
+	    return EEXIST;
+	  q = strchr ((char*)alphabet, *p);
+	  if (!q)
+	    abort (); /* should not happen */
+	  *p = (q[1] == 0) ? alphabet[0] : q[1];
+	  if (*p != *cp)
+	    break;
+	}
     }
+  free (carrybuf);
+  return rc;
+}
 
-#ifdef HAVE_MKSTEMP
-  {
-    int save_mask = umask (077);
-    fd = mkstemp (filename);
-    umask (save_mask);
-  }
-#else
-  if (mktemp (filename))
-    fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600);
-  else
-    fd = -1;
-#endif
+/* Create a temporary file according to HINTS.
+
+   If MU_TEMPFILE_MKDIR flag is set, create a directory instead of file.
+
+   On success, return 0.  If PFD is not NULL (and MU_TEMPFILE_MKDIR flag
+   is not set), open the file and store its descriptor in *PFD.  If
+   NAMEP is not NULL, store there a pointer to the allocated file name.
+   At least one of PFD and NAMEP must be set, otherwise EINVAL is returned.
 
-  if (fd == -1)
+   On error, returns error code describing the problem.
+
+   If hints is NULL, any flags except MU_TEMPFILE_MKDIR are ignored.
+   Otherwise:
+   
+   * If MU_TEMPFILE_TMPDIR is set, hints->tmpdir points to the name of
+     a directory where to create the temporary.
+   * If MU_TEMPFILE_SUFFIX is set, hints->suffix defines a suffix to
+     append to the created file name.
+ */
+int
+mu_tempfile (struct mu_tempfile_hints *hints, int flags,
+	     int *pfd, char **namep)
+{
+  char *filename;
+  const char *tmpdir = getenv ("TMPDIR");
+  const char *suf = NULL;
+  int create_dir = 0;
+  int rc;
+  struct stat st;
+
+  if (pfd == NULL && namep == NULL)
+    return EINVAL;
+  if (hints)
     {
-      mu_error (_("cannot open temporary file: %s"), mu_strerror (errno));
-      free (filename);
-      return -1;
+      if (flags & MU_TEMPFILE_TMPDIR)
+	tmpdir = hints->tmpdir;
+      if (flags & MU_TEMPFILE_SUFFIX)
+	suf = hints->suffix;
+      create_dir = flags & MU_TEMPFILE_MKDIR;
     }
+      
+  if (!tmpdir)
+    tmpdir = P_tmpdir;
+
+  /* First, see if tmpdir exists */
+  if (stat (tmpdir, &st))
+    return errno;
 
-  if (namep)
-    *namep = filename;
-  else
+  /* Create a name template */
+  filename = mu_make_file_name_suf (tmpdir, "muXXXXXX", suf);
+  rc = mu_create_temp_file (filename, suf ? strlen (suf) : 0, pfd, create_dir);
+  if (rc == 0)
     {
-      unlink (filename);
-      free (filename);
+      if (namep)
+	*namep = filename;
+      else
+	{
+	  unlink (filename);
+	  free (filename);
+	}
     }
-
-  return fd;
+  return rc;
 }
 
 /* Create a unique temporary file name in tmpdir. The function
@@ -100,10 +217,13 @@ mu_tempfile (const char *tmpdir, char **namep)
 char *
 mu_tempname (const char *tmpdir)
 {
+  struct mu_tempfile_hints hints;
   char *filename = NULL;
-  int fd = mu_tempfile (tmpdir, &filename);
+  int fd;
+  hints.tmpdir = tmpdir;
+  if (mu_tempfile (&hints, MU_TEMPFILE_TMPDIR, &fd, &filename))
+    return NULL;
   close (fd);
   return filename;
 }
 
-
diff --git a/libmailutils/mailbox/body.c b/libmailutils/mailbox/body.c
index e2c2bcd..5db2216 100644
--- a/libmailutils/mailbox/body.c
+++ b/libmailutils/mailbox/body.c
@@ -79,13 +79,6 @@ mu_body_destroy (mu_body_t *pbody, void *owner)
       mu_body_t body = *pbody;
       if (body->owner == owner)
 	{
-	  if (body->filename)
-	    {
-	      /* FIXME: should we do this?  */
-	      remove (body->filename);
-	      free (body->filename);
-	    }
-
 	  if (body->stream)
 	    mu_stream_destroy (&body->stream);
 
@@ -123,26 +116,6 @@ mu_body_clear_modified (mu_body_t body)
   return 0;
 }
 
-int
-mu_body_get_filename (mu_body_t body, char *filename, size_t len, size_t *pn)
-{
-  int n = 0;
-  if (body == NULL)
-    return EINVAL;
-  if (body->filename)
-    {
-      n = strlen (body->filename);
-      if (filename && len > 0)
-	{
-	  len--; /* Space for the null.  */
-	  strncpy (filename, body->filename, len)[len] = '\0';
-	}
-    }
-  if (pn)
-    *pn = n;
-  return 0;
-}
-
 
 struct _mu_body_stream
 {
@@ -177,9 +150,8 @@ _body_get_stream (mu_body_t body, mu_stream_t *pstream, int ref)
 	    return ENOMEM;
 	  
 	  /* Create the temporary file.  */
-	  body->filename = mu_tempname (NULL);
-	  status = mu_file_stream_create (&body->fstream, 
-					  body->filename, MU_STREAM_RDWR);
+
+	  status = mu_temp_file_stream_create (&body->fstream, NULL, 0);
 	  if (status != 0)
 	    return status;
 	  mu_stream_set_buffer (body->fstream, mu_buffer_full, 0);
diff --git a/libmailutils/stream/file_stream.c b/libmailutils/stream/file_stream.c
index 6f9723a..73a2990 100644
--- a/libmailutils/stream/file_stream.c
+++ b/libmailutils/stream/file_stream.c
@@ -388,9 +388,17 @@ int
 mu_fd_stream_create (mu_stream_t *pstream, char *filename, int fd, int flags)
 {
   struct _mu_file_stream *fstr;
-  int rc = _mu_file_stream_create (&fstr,
-				   sizeof (struct _mu_file_stream),
-				   filename, fd, flags|_MU_STR_OPEN);
+  int rc;
+
+  if (flags & MU_STREAM_SEEK)
+    {
+      if (lseek (fd, 0, SEEK_SET))
+	return errno;
+    }
+
+  rc = _mu_file_stream_create (&fstr,
+			       sizeof (struct _mu_file_stream),
+			       filename, fd, flags|_MU_STR_OPEN);
   if (rc == 0)
     {
       mu_stream_t stream = (mu_stream_t) fstr;
diff --git a/libmailutils/stream/streamcpy.c b/libmailutils/stream/streamcpy.c
index 2020fad..38d3c90 100644
--- a/libmailutils/stream/streamcpy.c
+++ b/libmailutils/stream/streamcpy.c
@@ -98,10 +98,7 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
 	if (status)
 	  break;
 	if (n == 0)
-	  {
-	    status = EIO;
-	    break;
-	  }
+	  break;
 	status = mu_stream_write (dst, buf, n, NULL);
 	if (status)
 	  break;
@@ -120,6 +117,10 @@ mu_stream_copy (mu_stream_t dst, mu_stream_t src, mu_off_t size,
 
   if (pcsz)
     *pcsz = total;
+  /* FIXME: When EOF error code is implemented:
+  else if (total == 0)
+    status = EOF;
+  */
   free (buf);
   return status;
 }
diff --git a/libmailutils/stream/temp_file_stream.c b/libmailutils/stream/temp_file_stream.c
index 29ca359..c1dfacd 100644
--- a/libmailutils/stream/temp_file_stream.c
+++ b/libmailutils/stream/temp_file_stream.c
@@ -29,37 +29,67 @@
 #include <mailutils/nls.h>
 #include <mailutils/stream.h>
 #include <mailutils/sys/stream.h>
-#include <mailutils/sys/file_stream.h>
+#include <mailutils/sys/temp_file_stream.h>
 #include <mailutils/util.h>
 
 
 static int
 fd_temp_open (struct _mu_stream *str)
 {
-  struct _mu_file_stream *fstr = (struct _mu_file_stream *) str;
-  int fd = mu_tempfile (fstr->filename, NULL);
-  if (fd == -1)
-    return errno;
-  fstr->fd = fd;
-  return 0;
+  struct _mu_temp_file_stream *fstr = (struct _mu_temp_file_stream *) str;
+  return mu_tempfile (&fstr->hints, fstr->hflags, &fstr->stream.fd, NULL);
+}
+
+static void
+fd_temp_done (struct _mu_stream *str)
+{
+  struct _mu_temp_file_stream *fstr = (struct _mu_temp_file_stream *) str;
+  if (fstr->hflags & MU_TEMPFILE_TMPDIR)
+    free (fstr->hints.tmpdir);
+  if (fstr->hflags & MU_TEMPFILE_SUFFIX)
+    free (fstr->hints.suffix);
+  if (fstr->file_done)
+    fstr->file_done (&fstr->stream.stream);
 }
-  
+
 int
-mu_temp_file_stream_create (mu_stream_t *pstream, const char *dir)
+mu_temp_file_stream_create (mu_stream_t *pstream,
+			    struct mu_tempfile_hints *hints, int flags)
 {
   int rc;
   struct _mu_file_stream *str;
   mu_stream_t stream;
+
+  if (flags && !hints)
+    return EINVAL;
   rc = _mu_file_stream_create (&str,
-			       sizeof (struct _mu_file_stream),
-			       dir,
+			       sizeof (struct _mu_temp_file_stream),
+			       NULL,
 			       -1,
 			       MU_STREAM_RDWR | MU_STREAM_SEEK |
 			       MU_STREAM_CREAT | 
 			       MU_STREAM_AUTOCLOSE);
   if (rc == 0)
     {
-      str->stream.open = fd_temp_open;
+      struct _mu_temp_file_stream *tstr = (struct _mu_temp_file_stream *)str;
+      tstr->stream.stream.open = fd_temp_open;
+      tstr->file_done = tstr->stream.stream.done;
+      tstr->stream.stream.done = fd_temp_done;
+
+      if ((flags & MU_TEMPFILE_TMPDIR) &&
+	  (tstr->hints.tmpdir = strdup (hints->tmpdir)) == NULL)
+	{
+	  mu_stream_unref ((mu_stream_t) str);
+	  return ENOMEM;
+	}
+      if ((flags & MU_TEMPFILE_SUFFIX) &&
+	  (tstr->hints.suffix = strdup (hints->suffix)) == NULL)
+	{
+	  mu_stream_unref ((mu_stream_t) str);
+	  return ENOMEM;
+	}
+      tstr->hflags = flags & ~MU_TEMPFILE_MKDIR;
+      
       str->flags = _MU_FILE_STREAM_TEMP;
       stream = (mu_stream_t) str;
       rc = mu_stream_open (stream);
diff --git a/libmailutils/string/mkfilename.c b/libmailutils/string/mkfilename.c
index 7bf0665..d815e0b 100644
--- a/libmailutils/string/mkfilename.c
+++ b/libmailutils/string/mkfilename.c
@@ -25,22 +25,27 @@
 #include <mailutils/util.h>
 
 char *
-mu_make_file_name (const char *dir, const char *file)
+mu_make_file_name_suf (const char *dir, const char *file, const char *suf)
 {
   char *tmp;
   size_t dirlen = strlen (dir);
+  size_t suflen = suf ? strlen (suf) : 0;
+  size_t fillen = strlen (file);
   size_t len;
 
   while (dirlen > 0 && dir[dirlen-1] == '/')
     dirlen--;
   
-  len = dirlen + 1 + strlen (file);
+  len = dirlen + 1 + fillen + suflen;
   tmp = mu_alloc (len + 1);
   if (tmp)
     {
       memcpy (tmp, dir, dirlen);
       tmp[dirlen++] = '/';
-      strcpy (tmp + dirlen, file);
+      memcpy (tmp + dirlen, file, fillen);
+      if (suf)
+	memcpy (tmp + dirlen + fillen, suf, suflen);
+      tmp[len] = 0;
     }
   return tmp;
 }
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 67b62fc..cfcea39 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -48,6 +48,7 @@ noinst_PROGRAMS = \
  listop\
  mailcap\
  prop\
+ tempfile\
  url-parse\
  wicket\
  wsp
diff --git a/libmailutils/tests/tempfile.c b/libmailutils/tests/tempfile.c
new file mode 100644
index 0000000..0df762f
--- /dev/null
+++ b/libmailutils/tests/tempfile.c
@@ -0,0 +1,169 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <mailutils/util.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/stream.h>
+
+char *progname;
+
+void
+usage (FILE *fp, int code)
+{
+  fprintf (fp,
+	   "usage: %s [-tmpdir=DIR] [-suffix=SUF] [-dry-run | -unlink] { file | dir }\n",
+	   progname);
+  exit (code);
+}
+
+int
+main (int argc, char **argv)
+{
+  struct mu_tempfile_hints hints, *phints;
+  int flags = 0;
+  int fd;
+  int *pfd = &fd;
+  char *filename;
+  char **pname = &filename;
+  char *infile = NULL;
+  int verify = 0;
+  int verbose = 0;
+
+  progname = argv[0];
+  
+  if (argc == 1)
+    usage (stdout, 0);
+  
+  while (--argc)
+    {
+      char *arg = *++argv;
+
+      if (strncmp (arg, "-tmpdir=", 8) == 0)
+	{
+	  hints.tmpdir = arg + 8;
+	  flags |= MU_TEMPFILE_TMPDIR;
+	}
+      else if (strncmp (arg, "-suffix=", 8) == 0)
+	{
+	  hints.suffix = arg + 8;
+	  flags |= MU_TEMPFILE_SUFFIX;
+	}
+      else if (strcmp (arg, "-dry-run") == 0)
+	pfd = NULL;
+      else if (strcmp (arg, "-unlink") == 0)
+	pname = NULL;
+      else if (strncmp (arg, "-infile=", 8) == 0)
+	infile = arg + 8;
+      else if (strncmp (arg, "-verify", 7) == 0)
+	verify = 1;
+      else if (strncmp (arg, "-verbose", 8) == 0)
+	verbose = 1;
+      else
+	break;
+    }
+
+  if (argv[0] == NULL)
+    usage (stderr, 1);
+  if (strcmp (argv[0], "file") == 0)
+    /* nothing */;
+  else if (strcmp (argv[0], "dir") == 0)
+    flags |= MU_TEMPFILE_MKDIR;
+  else
+    usage (stderr, 1);
+
+  if (pname == NULL && pfd == NULL)
+    {
+      mu_error ("both -unlink and -dry-run given");
+      exit (1);
+    }
+
+  if (infile)
+    {
+      if (flags & MU_TEMPFILE_MKDIR)
+	{
+	  mu_error ("-infile is useless with dir");
+	  exit (1);
+	}
+      else if (pfd == NULL)
+	{
+	  mu_error ("-infile is useless with -dry-run");
+	  exit (1);
+	}
+    }
+
+  if (verify && pfd == NULL)
+    {
+      mu_error ("-verify is useless with -dry-run");
+      exit (1);
+    }
+  
+  phints = flags ? &hints : NULL;
+  
+  MU_ASSERT (mu_tempfile (phints, flags, pfd, pname));
+
+  if (filename)
+    printf ("created file name %s\n", filename);
+    
+  if (!pfd)
+    return 0;
+  
+  if (infile)
+    {
+      mu_stream_t in, out;
+      mu_off_t size;
+      
+      if (strcmp (infile, "-") == 0)
+	MU_ASSERT (mu_stdio_stream_create (&in, MU_STDIN_FD, 0));
+      else
+	MU_ASSERT (mu_file_stream_create (&in, infile, MU_STREAM_READ));
+
+      MU_ASSERT (mu_fd_stream_create (&out, filename, fd, MU_STREAM_WRITE));
+      MU_ASSERT (mu_stream_copy (out, in, 0, &size));
+      if (verbose)
+	printf ("copied %lu bytes to the temporary\n", (unsigned long) size);
+      mu_stream_unref (out);
+      mu_stream_unref (in);
+    }
+
+  if (verify)
+    {
+      mu_stream_t in, out;
+      mu_off_t size;
+
+      MU_ASSERT (mu_stdio_stream_create (&out, MU_STDOUT_FD, 0));
+      MU_ASSERT (mu_fd_stream_create (&in, filename, fd,
+				      MU_STREAM_READ|MU_STREAM_SEEK));
+      MU_ASSERT (mu_stream_copy (out, in, 0, &size));
+      if (verbose)
+	printf ("dumped %lu bytes\n", (unsigned long) size);
+      mu_stream_unref (out);
+      mu_stream_unref (in);
+    }
+
+  close (fd);
+  
+  return 0;
+}
+
+	  
diff --git a/libmu_scm/mu_body.c b/libmu_scm/mu_body.c
index 7f3d85c..4d56f73 100644
--- a/libmu_scm/mu_body.c
+++ b/libmu_scm/mu_body.c
@@ -55,18 +55,13 @@ static int
 mu_scm_body_print (SCM body_smob, SCM port, scm_print_state * pstate)
 {
   struct mu_body *mbp = (struct mu_body *) SCM_CDR (body_smob);
-  size_t b_size = 0, b_lines = 0, len = 0;
+  size_t b_size = 0, b_lines = 0;
   char buffer[512];
 
   mu_body_size (mbp->body, &b_size);
   mu_body_lines (mbp->body, &b_lines);
-  buffer[0] = 0;
-  mu_body_get_filename (mbp->body, buffer, sizeof (buffer), &len);
-
-  scm_puts ("#<body \"", port);
-  scm_puts (buffer, port);
-  scm_puts ("\" ", port);
 
+  scm_puts ("#<body ", port);
   snprintf (buffer, sizeof (buffer), "%3lu %-5lu",
 	    (unsigned long) b_lines, (unsigned long) b_size);
   scm_puts (buffer, port);
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index 5c0dd1b..b4f2935 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -1391,7 +1391,7 @@ mbox_expunge0 (mu_mailbox_t mailbox, int remove_deleted)
       (status = mu_locker_lock (mailbox->locker)) != 0)
     return status;
 
-  status = mu_temp_file_stream_create (&tempstr, NULL);
+  status = mu_temp_file_stream_create (&tempstr, NULL, 0);
   if (status == 0)
     {
       sigset_t signalset;
diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c
index 9b658bc..dd44816 100644
--- a/libproto/pop/mbox.c
+++ b/libproto/pop/mbox.c
@@ -361,7 +361,7 @@ _pop_message_get_stream (struct _pop3_message *mpm, mu_stream_t *pstr)
 	  
 	  if (!mpd->cache)
 	    {
-	      status = mu_temp_file_stream_create (&mpd->cache, NULL);
+	      status = mu_temp_file_stream_create (&mpd->cache, NULL, 0);
 	      if (status)
 		/* FIXME: Try to recover first */
 		break;
diff --git a/maidag/deliver.c b/maidag/deliver.c
index 47d9a54..568ec51 100644
--- a/maidag/deliver.c
+++ b/maidag/deliver.c
@@ -34,7 +34,7 @@ make_tmp (const char *from)
       exit (EX_TEMPFAIL);
     } 
 
-  rc = mu_temp_file_stream_create (&out, NULL);
+  rc = mu_temp_file_stream_create (&out, NULL, 0);
   if (rc)
     {
       maidag_error (_("unable to open temporary file: %s"), mu_strerror (rc));
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index 77a54a4..4360e9f 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -366,7 +366,7 @@ cfun_data (mu_stream_t iostr, char *arg)
       return 1;
     }
 
-  rc = mu_temp_file_stream_create (&tempstr, NULL);
+  rc = mu_temp_file_stream_create (&tempstr, NULL, 0);
   if (rc)
     {
       maidag_error (_("unable to open temporary file: %s"), mu_strerror (rc));
diff --git a/mail/escape.c b/mail/escape.c
index efa2d79..27d8c2f 100644
--- a/mail/escape.c
+++ b/mail/escape.c
@@ -324,11 +324,19 @@ escape_run_editor (char *ed, int argc, char **argv, compose_env_t *env)
   if (!mailvar_get (NULL, "editheaders", mailvar_type_boolean, 0))
     {
       char *filename;
-      int fd = mu_tempfile (NULL, &filename);
-      FILE *fp = fdopen (fd, "w+");
+      int fd;
+      FILE *fp;
       char buffer[512];
       int rc;
       
+      rc = mu_tempfile (NULL, 0, &fd, &filename);
+      if (rc)
+        {
+           mu_diag_funcall (MU_DIAG_ERROR, "mu_tempfile", NULL, rc);
+           return rc;
+        }
+
+      fp = fdopen (fd, "w+");
       dump_headers (fp, env);
 
       rewind (env->file);
@@ -639,8 +647,7 @@ escape_pipe (int argc, char **argv, compose_env_t *env)
       return 1;
     }
 
-  fd = mu_tempfile (NULL, NULL);
-  if (fd == -1)
+  if (mu_tempfile (NULL, 0, &fd, NULL))
     return 1;
 
   if ((pid = fork ()) < 0)
diff --git a/mail/send.c b/mail/send.c
index 4594309..62437b4 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -305,8 +305,18 @@ fill_body (mu_message_t msg, mu_stream_t instr)
   mu_stream_t stream = NULL;
   mu_off_t n;
   
-  mu_message_get_body (msg, &body);
-  mu_body_get_streamref (body, &stream);
+  rc = mu_message_get_body (msg, &body);
+  if (rc)
+    {
+      mu_error (_("cannot get message body: %s"), mu_strerror (rc));
+      return 1;
+    }
+  rc = mu_body_get_streamref (body, &stream);
+  if (rc)
+    {
+      mu_error (_("cannot get body: %s"), mu_strerror (rc));
+      return 1;
+    }
 
   rc = mu_stream_copy (stream, instr, 0, &n);
   mu_stream_destroy (&stream);
@@ -428,16 +438,16 @@ int
 mail_send0 (compose_env_t * env, int save_to)
 {
   int done = 0;
-  int fd;
+  int fd, rc;
   char *filename;
   char *savefile = NULL;
   int int_cnt;
   char *escape;
 
-  fd = mu_tempfile (NULL, &filename);
-  if (fd == -1)
+  rc = mu_tempfile (NULL, 0, &fd, &filename);
+  if (rc)
     {
-      util_error (_("Cannot open temporary file"));
+      util_error (_("Cannot open temporary file: %s"), mu_strerror (rc));
       return 1;
     }
 
diff --git a/mh/burst.c b/mh/burst.c
index 03b7eb7..8396106 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -396,7 +396,7 @@ flush_stream (struct burst_stream *bs, char *buf, size_t size)
     return;
   if (!bs->stream)
     {
-      if ((rc = mu_temp_file_stream_create (&bs->stream, NULL))) 
+      if ((rc = mu_temp_file_stream_create (&bs->stream, NULL, 0))) 
 	{
 	  mu_error (_("Cannot open temporary file: %s"),
 		    mu_strerror (rc));
diff --git a/mh/prompter.c b/mh/prompter.c
index 062bd9c..4a1ede2 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -193,7 +193,7 @@ main (int argc, char **argv)
       return 1;
     }
   
-  if ((rc = mu_temp_file_stream_create (&tmp, NULL))) 
+  if ((rc = mu_temp_file_stream_create (&tmp, NULL, 0))) 
     {
       mu_error (_("Cannot open temporary file: %s"),
 		mu_strerror (rc));


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 25 16:42:49 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLjab-0006ig-2U
	for mharc-commit-mailutils@gnu.org; Thu, 25 Nov 2010 16:42:49 -0500
Received: from [140.186.70.92] (port=60274 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLjaH-0006hH-GL
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 16:42:48 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLjZy-0003n3-59
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 16:42:29 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:39268
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLjZy-0003my-3d
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 16:42:10 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLjZx-0003WH-KT
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 21:42:09 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLjZv-0006pe-CU
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 21:42:09 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 9df638667be69868851e0882eb172b1476ff962d
X-Git-Newrev: 37e95daa73d9f2b757ae77f132fb81c08f9e29c6
Message-Id: <E1PLjZv-0006pe-CU@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 25 Nov 2010 21:42:08 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-226-g37e95da
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Nov 2010 21:42:48 -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=37e95daa73d9f2b757ae77f132fb81c08f9e29c6

The branch, master has been updated
       via  37e95daa73d9f2b757ae77f132fb81c08f9e29c6 (commit)
      from  9df638667be69868851e0882eb172b1476ff962d (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 37e95daa73d9f2b757ae77f132fb81c08f9e29c6
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Nov 25 23:31:42 2010 +0200

    mhn: implement mhn-suffix-<type> profile component.
    
    * mh/mhn.c (_mhn_profile_get): All arguments are const.
    (mhn_tempfile_name): New function.
    (mhn_show_command): Use mhn_tempfile_name.

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

Summary of changes:
 mh/mhn.c |   30 ++++++++++++++++++++++++++----
 1 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/mh/mhn.c b/mh/mhn.c
index 69aa832..cf80736 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -576,7 +576,8 @@ msg_part_subpart (msg_part_t p, int level)
 /* *********************** Context file accessors ************************* */
 
 const char *
-_mhn_profile_get (char *prefix, char *type, char *subtype, char *defval)
+_mhn_profile_get (const char *prefix, const char *type, const char *subtype,
+		  const char *defval)
 {
   char *name;
   const char *str;
@@ -670,6 +671,26 @@ mhn_compose_command (char *typestr, int *flags, char *file)
   return (char*) str;
 }
 
+static void
+mhn_tempfile_name (char **tempfile, const char *type, const char *subtype)
+{
+  struct mu_tempfile_hints hints;
+  int flags = 0, rc;
+  const char *s = _mhn_profile_get ("suffix", type, subtype, NULL);;
+  
+  if (s)
+    {
+      hints.suffix = (char*) s;
+      flags |= MU_TEMPFILE_SUFFIX;
+    }
+  rc = mu_tempfile (&hints, flags, NULL, tempfile);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_tempfile", NULL, rc);
+      exit (1);
+    }
+}
+
 char *
 mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 		  char **tempfile)
@@ -722,7 +743,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 	    case 'f':
 	      /* filename containing content */
 	      if (!*tempfile)
-		*tempfile = mu_tempname (NULL);
+		mhn_tempfile_name (tempfile, type, subtype);
 	      obstack_grow (&stk, *tempfile, strlen (*tempfile));
 	      break;
 				     
@@ -730,7 +751,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 	      /* %e, %f, and stdin is terminal not content */
 	      *flags |= MHN_STDIN|MHN_EXCLUSIVE_EXEC;
 	      if (!*tempfile)
-		*tempfile = mu_tempname (NULL);
+		mhn_tempfile_name (tempfile, type, subtype);
 	      obstack_grow (&stk, *tempfile, strlen (*tempfile));
 	      break;
 	      
@@ -1318,7 +1339,8 @@ mhn_run_command (mu_message_t msg, msg_part_t part,
 	  return ENOSYS;
 	}
 
-      rc = mu_file_stream_create (&tmp, tempfile, MU_STREAM_RDWR);
+      rc = mu_file_stream_create (&tmp, tempfile,
+				  MU_STREAM_RDWR|MU_STREAM_CREAT);
       if (rc)
 	{
 	  mu_error (_("cannot create temporary stream (file %s): %s"),


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Nov 25 18:17:02 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLl3m-0001aH-0s
	for mharc-commit-mailutils@gnu.org; Thu, 25 Nov 2010 18:17:02 -0500
Received: from [140.186.70.92] (port=49158 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLl31-0001WA-A8
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 18:17:01 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLl2M-00060U-O7
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 18:16:15 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:53698
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLl2M-00060N-L7
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 18:15:34 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLl2L-0004an-NL
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 23:15:34 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLl2F-0004tK-FZ
	for commit-mailutils@gnu.org; Thu, 25 Nov 2010 23:15:33 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 37e95daa73d9f2b757ae77f132fb81c08f9e29c6
X-Git-Newrev: 2ad19f568fede86dec081cf363b5fad0340b43c0
Message-Id: <E1PLl2F-0004tK-FZ@vcs-noshell.in.savannah.gnu.org>
Date: Thu, 25 Nov 2010 23:15:31 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-227-g2ad19f5
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 25 Nov 2010 23:17: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=2ad19f568fede86dec081cf363b5fad0340b43c0

The branch, master has been updated
       via  2ad19f568fede86dec081cf363b5fad0340b43c0 (commit)
      from  37e95daa73d9f2b757ae77f132fb81c08f9e29c6 (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 2ad19f568fede86dec081cf363b5fad0340b43c0
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Nov 26 01:11:21 2010 +0200

    mhn: minor improvements
    
    * mh/mhn.c: Use _sget_ calls where appropriate.  Eliminate
    unnecessary memory allocations.

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

Summary of changes:
 mh/mhn.c |  148 ++++++++++++++++++++++++++++++--------------------------------
 1 files changed, 72 insertions(+), 76 deletions(-)

diff --git a/mh/mhn.c b/mh/mhn.c
index cf80736..5b7c2c0 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -203,7 +203,7 @@ _get_content_type (mu_header_t hdr, char **value, char **rest)
     {
       if (type)
 	free (type);
-      type = strdup ("text/plain"); /* Default.  */
+      type = xstrdup ("text/plain"); /* Default.  */
       if (rest)
 	*rest = NULL;
     }
@@ -229,7 +229,7 @@ _get_content_encoding (mu_header_t hdr, char **value)
     {
       if (encoding)
 	free (encoding);
-      encoding = strdup ("7bit"); /* Default.  */
+      encoding = xstrdup ("7bit"); /* Default.  */
     }
   *value = encoding;
   return 0;
@@ -665,7 +665,7 @@ mhn_compose_command (char *typestr, int *flags, char *file)
   if (!*p)
     str = NULL;
   else
-    str = strdup (p);
+    str = xstrdup (p);
 
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -695,8 +695,7 @@ char *
 mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 		  char **tempfile)
 {
-  const char *p, *str;
-  char *tmp;
+  const char *p, *str, *tmp;
   char *typestr, *type, *subtype, *typeargs;
   struct obstack stk;
   mu_header_t hdr;
@@ -772,12 +771,9 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 	      
 	    case 'd':
 	      /* content description */
-	      if (mu_header_aget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
-				     &tmp) == 0)
-		{
-		  obstack_grow (&stk, tmp, strlen (tmp));
-		  free (tmp);
-		}
+	      if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
+					&tmp) == 0)
+		obstack_grow (&stk, tmp, strlen (tmp));
 	      break;
 	      
 	    default:
@@ -799,7 +795,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
   if (!*p)
     str = NULL;
   else
-    str = strdup (p);
+    str = xstrdup (p);
 
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -808,8 +804,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 char *
 mhn_store_command (mu_message_t msg, msg_part_t part, char *name)
 {
-  const char *p, *str;
-  char *tmp;
+  const char *p, *str, *tmp;
   char *typestr, *type, *subtype, *typeargs;
   struct obstack stk;
   mu_header_t hdr;
@@ -863,12 +858,9 @@ mhn_store_command (mu_message_t msg, msg_part_t part, char *name)
 	      
 	    case 'd':
 	      /* content description */
-	      if (mu_header_aget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
+	      if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
 				        &tmp) == 0)
-		{
-		  obstack_grow (&stk, tmp, strlen (tmp));
-		  free (tmp);
-		}
+		obstack_grow (&stk, tmp, strlen (tmp));
 	      break;
 	      
 	    default:
@@ -890,7 +882,7 @@ mhn_store_command (mu_message_t msg, msg_part_t part, char *name)
   if (!*p)
     str = NULL;
   else
-    str = strdup (p);
+    str = xstrdup (p);
   
   obstack_free (&stk, NULL);
   return (char*) str;
@@ -900,13 +892,13 @@ mhn_store_command (mu_message_t msg, msg_part_t part, char *name)
 /* ************************* Auxiliary functions ************************** */
 
 static void
-split_args (char *argstr, int *pargc, char ***pargv)
+split_args (const char *argstr, size_t len, int *pargc, char ***pargv)
 {
   struct mu_wordsplit ws;
 
   ws.ws_delim = ";";
-  if (mu_wordsplit (argstr, &ws,
-		    MU_WRDSF_DEFFLAGS | MU_WRDSF_DELIM | MU_WRDSF_WS))
+  if (mu_wordsplit_len (argstr, len, &ws,
+			MU_WRDSF_DEFFLAGS | MU_WRDSF_DELIM | MU_WRDSF_WS))
     {
       mu_error (_("cannot split line `%s': %s"), argstr,
 		mu_wordsplit_strerror (&ws));
@@ -938,7 +930,7 @@ _message_is_external_body (mu_message_t msg, char ***env)
   if (rc && env)
     {
       int c;
-      split_args (argstr, &c, env);
+      split_args (argstr, strlen (argstr), &c, env);
     }
 
   free (typestr);
@@ -1001,7 +993,7 @@ get_extbody_params (mu_message_t msg, char **content, char **descr)
 	{
 	  p = mu_str_skip_class (buf + sizeof (MU_HEADER_CONTENT_DESCRIPTION),
 				 MU_CTYPE_SPACE);
-	  *descr = strdup (p);
+	  *descr = xstrdup (p);
 	}
       else if (content
 	       && mu_c_strncasecmp (buf, MU_HEADER_CONTENT_TYPE ":",
@@ -1013,7 +1005,7 @@ get_extbody_params (mu_message_t msg, char **content, char **descr)
 	  q = strchr (p, ';');
 	  if (q)
 	    *q = 0;
-	  *content = strdup (p);
+	  *content = xstrdup (p);
 	}
     }
   mu_stream_destroy (&stream);
@@ -1194,12 +1186,9 @@ list_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
   
   if (mu_message_get_header (msg, &hdr) == 0)
     {
-      char *descr;
-      if (mu_header_aget_value (hdr, "Content-Description", &descr) == 0)
-	{
-	  printf (" %s", descr);
-	  free (descr);
-	}
+      const char *descr;
+      if (mu_header_sget_value (hdr, "Content-Description", &descr) == 0)
+	printf (" %s", descr);
     }
   
   printf ("\n");
@@ -2060,7 +2049,8 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level)
   mu_header_t hdr;
   mu_mime_t mime;
   mu_message_t msg;
-  char *val, *newval;
+  const char *val;
+  char *newval;
   
   skipws (cmd);
   while (stop == 0 && status == 0 && *cmd)
@@ -2151,13 +2141,12 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level)
   
   mu_mime_get_message (mime, &msg);
   mu_message_get_header (msg, &hdr);
-  mu_header_aget_value (hdr, MU_HEADER_CONTENT_TYPE, &val);
+  mu_header_sget_value (hdr, MU_HEADER_CONTENT_TYPE, &val);
   sp = strchr (val, ';');
   if (!sp)
     abort ();
   mu_asprintf (&newval, "multipart/digest%s", sp);
   mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, newval, 1);
-  free (val);
   free (newval);
 
   if (!id)
@@ -2246,11 +2235,11 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
       _get_content_type (hdr, &typestr, NULL);
       split_content (typestr, &type, &subtype);
       if (mu_c_strcasecmp (type, "message") == 0)
-	encoding = strdup ("7bit");
+	encoding = xstrdup ("7bit");
       else if (mu_c_strcasecmp (type, "text") == 0)
-	encoding = strdup ("quoted-printable");
+	encoding = xstrdup ("quoted-printable");
       else
-	encoding = strdup ("base64");
+	encoding = xstrdup ("base64");
       mu_header_set_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding, 1);
       free (typestr);
       free (type);
@@ -2278,7 +2267,7 @@ edit_mime (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
 }
 
 static int
-has_nonascii (char *buf, size_t n)
+has_nonascii (const char *buf, size_t n)
 {
   size_t i;
   for (i = 0; i < n; i++)
@@ -2441,55 +2430,61 @@ mhn_edit (struct compose_env *env, int level)
 }
 
 int
-parse_header_directive (char *val, char **encoding, char **charset, char **subject)
+parse_header_directive (const char *val, char **encoding, char **charset,
+			char **subject)
 {
-  char *p;
+  const char *p;
 
   /* Provide default values */
   *encoding = NULL;
   *charset = NULL;
-  *subject = val;
+  *subject = NULL;
 
   if (*val != '#')
-    return 1;
+    {
+      *subject = xstrdup (val);
+      return 1;
+    }
   val++;
   
   switch (*val)
     {
     case '#':
-      *subject = val;
-      return 1;
+      break;
 
     case '<':
-      for (p = val; *p; p++)
-	if (*p == '>')
-	  {
-	    int i, argc;
-	    char **argv;
+      p = strchr (val, '>');
+      if (p)
+	{
+	  int i, argc;
+	  char **argv;
 	    
-	    *subject = p + 1;
-	    *p = 0;
-	    split_args (val + 1, &argc, &argv);
-	    for (i = 0; i < argc; i++)
-	      {
-		if (strlen (argv[i]) > 8
-		    && memcmp (argv[i], "charset=", 8) == 0)
-		  {
-		    free (*charset);
-		    *charset = strdup (argv[i] + 8);
-		  }
-		else if (strlen (argv[i]) > 9
-			 && memcmp (argv[i], "encoding=", 9) == 0)
-		  {
-		    free (*encoding);
-		    *encoding = strdup (argv[i] + 9);
-		  }
-	      }
-	    mu_argcv_free (argc, argv);
-	    return 0;
-	  }
+	  *subject = xstrdup (p + 1);
+	  split_args (val + 1, p - val - 1, &argc, &argv);
+	  for (i = 0; i < argc; i++)
+	    {
+	      if (strlen (argv[i]) > 8
+		  && memcmp (argv[i], "charset=", 8) == 0)
+		{
+		  free (*charset);
+		  *charset = xstrdup (argv[i] + 8);
+		}
+	      else if (strlen (argv[i]) > 9
+		       && memcmp (argv[i], "encoding=", 9) == 0)
+		{
+		  free (*encoding);
+		  *encoding = xstrdup (argv[i] + 9);
+		}
+	    }
+	  mu_argcv_free (argc, argv);
+	  return 0;
+	}
       break;
+
+    default:
+      val--;
     }
+  *subject = xstrdup (val);
   return 1;
 }
 
@@ -2498,10 +2493,10 @@ void
 mhn_header (mu_message_t msg, mu_message_t omsg)
 {
   mu_header_t hdr = NULL;
-  char *val;
+  const char *val;
   
   mu_message_get_header (msg, &hdr);
-  if (mu_header_aget_value (hdr, MU_HEADER_SUBJECT, &val) == 0)
+  if (mu_header_sget_value (hdr, MU_HEADER_SUBJECT, &val) == 0)
     {
       char *subject, *encoding, *charset;
       
@@ -2530,12 +2525,12 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
 		      int i, argc;
 		      char **argv;
 		      
-		      split_args (typeargs, &argc, &argv);
+		      split_args (typeargs, strlen (typeargs), &argc, &argv);
 		      for (i = 0; i < argc; i++)
 			if (strlen (argv[i]) > 8
 			    && memcmp (argv[i], "charset=", 8) == 0)
 			  {
-			    charset = strdup (argv[i]+8);
+			    charset = xstrdup (argv[i]+8);
 			    break;
 			  }
 		      mu_argcv_free (argc, argv);
@@ -2553,7 +2548,7 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
 	  if (!encoding || strcmp (encoding, "7bit") == 0)
 	    {
 	      free (encoding);
-	      encoding = strdup ("base64");
+	      encoding = xstrdup ("base64");
 	    }
  	  rc = mu_rfc2047_encode (charset, encoding, subject, &p);
 	  if (rc)
@@ -2567,6 +2562,7 @@ mhn_header (mu_message_t msg, mu_message_t omsg)
 	}
       free (charset);
       free (encoding);
+      free (subject);
     }
 }
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Nov 26 05:46:10 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLvog-0005aD-7H
	for mharc-commit-mailutils@gnu.org; Fri, 26 Nov 2010 05:46:10 -0500
Received: from [140.186.70.92] (port=57379 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLvoc-0005Yh-6m
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 05:46:08 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLvoa-0004MH-3l
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 05:46:06 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:51250
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLvoa-0004LF-0a
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 05:46:04 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLvoZ-0003zg-Ne
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 10:46:03 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLvoT-0002fN-8V
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 10:46:03 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 2ad19f568fede86dec081cf363b5fad0340b43c0
X-Git-Newrev: 7dcee33a0ee8923108dbdfa024d1c7bc1e7d2800
Message-Id: <E1PLvoT-0002fN-8V@vcs-noshell.in.savannah.gnu.org>
Date: Fri, 26 Nov 2010 10:45:57 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-228-g7dcee33
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Nov 2010 10:46:08 -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=7dcee33a0ee8923108dbdfa024d1c7bc1e7d2800

The branch, master has been updated
       via  7dcee33a0ee8923108dbdfa024d1c7bc1e7d2800 (commit)
      from  2ad19f568fede86dec081cf363b5fad0340b43c0 (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 7dcee33a0ee8923108dbdfa024d1c7bc1e7d2800
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Nov 26 12:42:17 2010 +0200

    mh: improve mhn store mode.
    
    * mh/mhn.c (options): Add --build as an alias to --compose.
    (options): Likewise.
    (store_destination): New enum.
    (mhn_store_command): Support all variants of mhn-store-* components.
    Return store_destination type.
    (store_handler): Rewrite accordingly.
    (main): Consistently use mh_expand_name to expand the value of
    input_file.
    * mh/tests/mhn.at: New file.
    * mh/tests/Makefile.am (TESTSUITE_AT): Add mhn.at.
    * mh/tests/testsuite.at: Include mhn.at.

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

Summary of changes:
 mh/mhn.c              |  245 +++++++++++++++++++++++++++++++++++++------------
 mh/tests/Makefile.am  |    1 +
 mh/tests/mhn.at       |  131 ++++++++++++++++++++++++++
 mh/tests/testsuite.at |    1 +
 4 files changed, 320 insertions(+), 58 deletions(-)
 create mode 100644 mh/tests/mhn.at

diff --git a/mh/mhn.c b/mh/mhn.c
index 5b7c2c0..132c676 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -39,7 +39,11 @@ static struct argp_option options[] = {
   {N_("MIME editing options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
   {"compose",      ARG_COMPOSE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
    N_("compose the MIME message (default)"), GRID+1},
-  {"nocompose",    ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN, "", GRID+1},
+  {"build",        0,                NULL,       OPTION_ALIAS,
+   NULL, GRID+1 },
+  {"nocompose",    ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN, NULL, GRID+1},
+  {"nobuild",      ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN|OPTION_ALIAS,
+   NULL, GRID+1},
 #undef GRID
 #define GRID 20  
   {N_("Listing options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
@@ -97,6 +101,7 @@ static struct argp_option options[] = {
 struct mh_option mh_option[] = {
   { "file",          MH_OPT_ARG, "filename" },
   { "compose" },
+  { "build" },
   { "list",          MH_OPT_BOOL },
   { "headers",       MH_OPT_BOOL },
   { "realsize",      MH_OPT_BOOL },
@@ -801,18 +806,71 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
   return (char*) str;
 }
 
-char *
-mhn_store_command (mu_message_t msg, msg_part_t part, char *name)
+enum store_destination
+  {
+    store_to_folder,
+    store_to_folder_msg,
+    store_to_file,
+    store_to_command,
+    store_to_stdout
+  };
+
+enum store_destination
+mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
+		   char **return_string)
 {
   const char *p, *str, *tmp;
   char *typestr, *type, *subtype, *typeargs;
   struct obstack stk;
   mu_header_t hdr;
+  enum store_destination dest;
   
   mu_message_get_header (msg, &hdr);
   _get_content_type (hdr, &typestr, &typeargs);
   split_content (typestr, &type, &subtype);
-  str = _mhn_profile_get ("store", type, subtype, "%m%P.%s");
+  str = _mhn_profile_get ("store", type, subtype, NULL);
+
+  if (!str)
+    {
+      /* FIXME:
+	 [If the mhn-store component] isn't found, mhn will check to see if
+	 the content is application/octet-stream with parameter "type=tar".
+	 If so, mhn will choose an appropriate filename.
+      */
+
+      if (mu_c_strcasecmp (type, "message") == 0)
+	{
+	  /* If the content is not application/octet-stream, then mhn
+	     will check to see if the content is a message.  If so, mhn
+	     will use the value "+".  */
+	  *return_string = xstrdup (mh_current_folder ());
+	  return store_to_folder_msg;
+	}
+      else
+	str = "%m%P.%s";
+    }
+  
+  switch (str[0])
+    {
+    case '+':
+      if (str[1])
+	*return_string = xstrdup (str);
+      else
+	*return_string = xstrdup (mh_current_folder ());
+      return store_to_folder;
+
+    case '-':
+      *return_string = NULL;
+      return store_to_stdout;
+
+    case '|':
+      dest = store_to_command;
+      str = mu_str_skip_class (str + 1, MU_CTYPE_SPACE);
+      break;
+
+    default:
+      dest = store_to_file;
+    }
   
   /* Expand macro-notations:
      %m  message number
@@ -880,12 +938,12 @@ mhn_store_command (mu_message_t msg, msg_part_t part, char *name)
   str = obstack_finish (&stk);
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
-    str = NULL;
+    *return_string = NULL;
   else
-    str = xstrdup (p);
+    *return_string = xstrdup (p);
   
   obstack_free (&stk, NULL);
-  return (char*) str;
+  return dest;
 }
 
 
@@ -1539,13 +1597,14 @@ int
 store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
 	       void *data)
 {
-  char *prefix = data;
+  const char *prefix = data;
   char *name = NULL;
-  char *tmp;
+  char *partstr;
   int ismime;
   int rc;
   mu_stream_t out;
   const char *dir = mh_global_profile_get ("mhn-storage", NULL);
+  enum store_destination dest = store_to_file;
   
   if (mu_message_is_multipart (msg, &ismime) == 0 && ismime)
     return 0;
@@ -1559,6 +1618,7 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
 	{
 	  name = normalize_path (dir, val);
 	  free (val);
+	  dest = store_to_file;
 	}
       else if (rc != MU_ERR_NOENT)
 	{
@@ -1571,57 +1631,126 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
     }
   
   if (!name)
-    {
-      char *fname = mhn_store_command (msg, part, prefix);
-      if (dir)
-	name = mh_safe_make_file_name (dir, fname);
-      else
-	name = fname;
-    }
-  
-  tmp = msg_part_format (part);
-  if (prefix)
-    printf (_("storing message %s part %s as file %s\n"),
-	    prefix,
-	    tmp,
-	    name);
-  else
-    printf (_("storing message %s part %s as file %s\n"),
-	    mu_umaxtostr (0, msg_part_subpart (part, 0)),
-	    tmp,
-	    name);
-  free (tmp);
-
-  if (!(mode_options & OPT_QUIET) && access (name, R_OK) == 0)
-    {
-      char *p;
-      int rc;
+    dest = mhn_store_command (msg, part, prefix, &name);
+
+  partstr = msg_part_format (part);
+  /* Set prefix for diagnostic purposes */
+  if (!prefix)
+    prefix = mu_umaxtostr (0, msg_part_subpart (part, 0));
+  out = NULL;
+  rc = 0;
+  switch (dest)
+    {
+    case store_to_folder_msg:
+    case store_to_folder:
+      {
+	mu_mailbox_t mbox = mh_open_folder (name, 1);
+	size_t uid;
+
+	mu_mailbox_uidnext (mbox, &uid);
+	printf (_("storing message %s part %s to folder %s as message %lu\n"),
+		prefix, partstr, name, (unsigned long) uid);
+	if (dest == store_to_folder_msg)
+	  {
+	    mu_body_t body;
+	    mu_stream_t str;
+	    mu_message_t tmpmsg;
+	    
+	    rc = mu_message_get_body (msg, &body);
+	    if (rc)
+	      {
+		mu_diag_funcall (MU_DIAG_ERROR, "mu_message_get_body",
+				 NULL, rc);
+		break;
+	      }
+	    rc = mu_body_get_streamref (body, &str);
+	    if (rc)
+	      {
+		mu_diag_funcall (MU_DIAG_ERROR, "mu_body_get_stream",
+				 NULL, rc);
+		break;
+	      }
+	    rc = mu_stream_to_message (str, &tmpmsg);
+	    mu_stream_unref (str);
+	    if (rc)
+	      {
+		mu_diag_funcall (MU_DIAG_ERROR, "mu_stream_to_message",
+				 NULL, rc);
+		break;
+	      }
+	    
+	    rc = mu_mailbox_append_message (mbox, tmpmsg);
+	    mu_message_destroy (&tmpmsg, mu_message_get_owner (tmpmsg));
+	  }
+	else
+	  rc = mu_mailbox_append_message (mbox, msg);
 	
-      mu_asprintf (&p, _("File %s already exists. Rewrite"), name);
-      rc = mh_getyn (p);
-      free (p);
-      if (!rc)
+	if (rc)
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_append_message", NULL,
+			   rc);
+	mu_mailbox_close (mbox);
+	mu_mailbox_destroy (&mbox);
+      }
+      break;
+
+    case store_to_file:
+      printf (_("storing message %s part %s as file %s\n"),
+	      prefix, partstr, name);
+
+      if (!(mode_options & OPT_QUIET) && access (name, R_OK) == 0)
 	{
-	  free (name);
-	  return 0;
+	  char *p;
+	  int ok;
+	  
+	  mu_asprintf (&p, _("File %s already exists. Rewrite"), name);
+	  ok = mh_getyn (p);
+	  free (p);
+	  if (!ok)
+	    {
+	      free (name);
+	      return 0;
+	    }
+	  unlink (name);
 	}
-      unlink (name);
-    }
   
-  rc = mu_file_stream_create (&out, name, MU_STREAM_WRITE|MU_STREAM_CREAT);
-  if (rc)
+      rc = mu_file_stream_create (&out, name, MU_STREAM_WRITE|MU_STREAM_CREAT);
+      if (rc)
+	mu_error (_("cannot create output stream (file %s): %s"),
+		  name, mu_strerror (rc));
+      break;
+
+    case store_to_command:
+      /* FIXME: Change to homedir, reflect this in the message below.
+	 Chdir should better be implemented within mu_prog_stream_create
+	 Example message:
+	   storing msg 4 part 1 using command (cd /home/gray;  less)
+      */
+      printf (_("storing msg %s part %s using command %s\n"),
+	      prefix, partstr, name);
+      rc = mu_prog_stream_create (&out, name, MU_STREAM_WRITE);
+      if (rc)
+	mu_diag_funcall (MU_DIAG_ERROR, "mu_prog_stream_create", NULL, rc);
+      break;
+      
+    case store_to_stdout:
+      printf (_("storing msg %s part %s to stdout\n"),
+	      prefix, partstr);
+      rc = mu_stdio_stream_create (&out, MU_STDOUT_FD, 0);
+      if (rc)
+	mu_diag_funcall (MU_DIAG_ERROR, "mu_stdio_stream_create", NULL, rc);
+      break;
+    }
+			   
+  if (out)
     {
-      mu_error (_("cannot create output stream (file %s): %s"),
-		name, mu_strerror (rc));
-      free (name);
-      return rc;
+      show_internal (msg, part, encoding, out);
+      mu_stream_destroy (&out);
     }
-  show_internal (msg, part, encoding, out);      
-
-  mu_stream_destroy (&out);
+      
   free (name);
+  free (partstr);
   
-  return 0;
+  return rc;
 }
 
 void
@@ -2663,7 +2792,9 @@ main (int argc, char **argv)
 	  mu_error (_("extra arguments"));
 	  return 1;
 	}
-      message = mh_file_to_message (mu_folder_directory (), input_file);
+      input_file = mh_expand_name (mu_folder_directory (),
+				   argc == 1 ? argv[0] : "draft", 0);
+      message = mh_file_to_message (NULL, input_file);
       if (!message)
 	return 1;
     }
@@ -2674,8 +2805,9 @@ main (int argc, char **argv)
 	  mu_error (_("extra arguments"));
 	  return 1;
 	}
-      input_file = argc == 1 ? argv[0] : "draft";
-      message = mh_file_to_message (mu_folder_directory (), input_file);
+      input_file = mh_expand_name (mu_folder_directory (),
+				   argc == 1 ? argv[0] : "draft", 0);
+      message = mh_file_to_message (NULL, input_file);
       if (!message)
 	return 1;
     }
@@ -2688,9 +2820,6 @@ main (int argc, char **argv)
   switch (mode)
     {
     case mode_compose:
-      /* Prepare filename for diagnostic purposes */
-      if (input_file[0] != '/')
-	input_file = mh_safe_make_file_name (mu_folder_directory (), input_file);
       rc = mhn_compose ();
       break;
       
diff --git a/mh/tests/Makefile.am b/mh/tests/Makefile.am
index 7e76c33..49a8854 100644
--- a/mh/tests/Makefile.am
+++ b/mh/tests/Makefile.am
@@ -49,6 +49,7 @@ TESTSUITE_AT = \
  install-mh.at\
  mark.at\
  mhl.at\
+ mhn.at\
  mhparam.at\
  mhpath.at\
  mhseq.at\
diff --git a/mh/tests/mhn.at b/mh/tests/mhn.at
new file mode 100644
index 0000000..bef8ae3
--- /dev/null
+++ b/mh/tests/mhn.at
@@ -0,0 +1,131 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2010 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+m4_pushdef([MH_KEYWORDS],[mhn])
+
+dnl -------------------------------------------------------------------
+dnl 1. List mode
+dnl -------------------------------------------------------------------
+
+MH_CHECK([mhn -list],[mhn00 mhn-list],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhn +inbox -list all
+],
+[0],
+[ msg part type/subtype              size  description
+   1      text/plain                 937
+   2      text/plain                 215
+   3      multipart/mixed             2K
+     1    text/plain                 230 How doth
+     2    application/octet-stream   462 Father William Part I
+   4      multipart/mixed             3K
+     1    text/plain                 341 Father William Part I
+     2    multipart/mixed             3K
+     2.1  application/octet-stream   479 Father William Part II
+     2.2  multipart/mixed             2K
+     2.2.1 application/octet-stream   483 Father William Part III
+     2.2.2 application/octet-stream   495 Father William Part IV
+   5      multipart/mixed            355
+     1    text/plain                   0 Empty part
+     2    text/plain                   1 Single line part
+])
+
+MH_CHECK([mhn -list -realsize],[mhn01 mhn-list-realsize],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhn +inbox -list -realsize all
+],
+[0],
+[ msg part type/subtype              size  description
+   1      text/plain                 937
+   2      text/plain                 215
+   3      multipart/mixed             2K
+     1    text/plain                 230 How doth
+     2    application/octet-stream   341 Father William Part I
+   4      multipart/mixed             3K
+     1    text/plain                 341 Father William Part I
+     2    multipart/mixed             3K
+     2.1  application/octet-stream   352 Father William Part II
+     2.2  multipart/mixed             2K
+     2.2.1 application/octet-stream   357 Father William Part III
+     2.2.2 application/octet-stream   366 Father William Part IV
+   5      multipart/mixed            355
+     1    text/plain                   0 Empty part
+     2    text/plain                   1 Single line part
+])
+
+dnl -------------------------------------------------------------------
+dnl 2. Store mode
+dnl -------------------------------------------------------------------
+
+MH_CHECK([mhn -store],[mhn02 mhn-store],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhn +inbox -store 4 || exit $?
+for file in 4.1.plain 4.2.1.octet-stream 4.2.2.1.octet-stream 4.2.2.2.octet-stream
+do
+  echo == $file ==
+  cat $file
+done
+],
+[0],
+[storing message 4 part 1 as file 4.1.plain
+storing message 4 part 2.1 as file 4.2.1.octet-stream
+storing message 4 part 2.2.1 as file 4.2.2.1.octet-stream
+storing message 4 part 2.2.2 as file 4.2.2.2.octet-stream
+== 4.1.plain ==
+`You are old, Father William,' the young man said,
+`And your hair has become very white;
+And yet you incessantly stand on your head--
+Do you think, at your age, it is right?'
+
+`In my youth,' Father William replied to his son,
+`I feared it might injure the brain;
+But, now that I'm perfectly sure I have none,
+Why, I do it again and again.'
+
+== 4.2.1.octet-stream ==
+`You are old,' said the youth, `as I mentioned before,
+And have grown most uncommonly fat;
+Yet you turned a back-somersault in at the door--
+Pray, what is the reason of that?'
+
+`In my youth,' said the sage, as he shook his grey locks,
+`I kept all my limbs very supple
+By the use of this ointment--one shilling the box--
+Allow me to sell you a couple?'
+== 4.2.2.1.octet-stream ==
+`You are old,' said the youth, `and your jaws are too weak
+For anything tougher than suet;
+Yet you finished the goose, with the bones and the beak--
+Pray how did you manage to do it?'
+
+`In my youth,' said his father, `I took to the law,
+And argued each case with my wife;
+And the muscular strength, which it gave to my jaw,
+Has lasted the rest of my life.'
+== 4.2.2.2.octet-stream ==
+`You are old,' said the youth, `one would hardly suppose
+That your eye was as steady as ever;
+Yet you balanced an eel on the end of your nose--
+What made you so awfully clever?'
+
+`I have answered three questions, and that is enough,'
+Said his father; `don't give yourself airs!
+Do you think I can listen all day to such stuff?
+Be off, or I'll kick you down stairs!'
+])
+
+m4_popdef[MH_KEYWORDS])
+# End of mhn.at
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index 0b708f6..ef4def6 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -63,3 +63,4 @@ m4_include([burst.at])
 m4_include([comp.at])
 m4_include([forw.at])
 m4_include([repl.at])
+m4_include([mhn.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Nov 26 10:12:05 2010
Received: from mailman by lists.gnu.org with archive (Exim 4.43)
	id 1PLzy0-0003MI-Ud
	for mharc-commit-mailutils@gnu.org; Fri, 26 Nov 2010 10:12:05 -0500
Received: from [140.186.70.92] (port=56222 helo=eggs.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.43) id 1PLzxx-0003K3-0q
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 10:12:03 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLzxu-00066E-IA
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 10:12:00 -0500
Received: from colonialone.fsf.org ([140.186.70.51]:50063
	helo=internal.in.savannah.gnu.org)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLzxu-00066A-G9
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 10:11:58 -0500
Received: from [10.1.0.108] (helo=vcs-noshell.in.savannah.gnu.org)
	by internal.in.savannah.gnu.org with esmtp (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLzxu-00074f-Cb
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 15:11:58 +0000
Received: from gray by vcs-noshell.in.savannah.gnu.org with local (Exim 4.69)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1PLzxt-0004Br-Ce
	for commit-mailutils@gnu.org; Fri, 26 Nov 2010 15:11:58 +0000
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 7dcee33a0ee8923108dbdfa024d1c7bc1e7d2800
X-Git-Newrev: 1ae763d4ecb847ea17dbaf97565af58dae832d02
Message-Id: <E1PLzxt-0004Br-Ce@vcs-noshell.in.savannah.gnu.org>
Date: Fri, 26 Nov 2010 15:11:57 +0000
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
Subject: [SCM] GNU Mailutils branch, master,
	updated. release-2.2-229-g1ae763d
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.5
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <http://lists.gnu.org/mailman/listinfo/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: <http://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 26 Nov 2010 15:12:03 -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=1ae763d4ecb847ea17dbaf97565af58dae832d02

The branch, master has been updated
       via  1ae763d4ecb847ea17dbaf97565af58dae832d02 (commit)
      from  7dcee33a0ee8923108dbdfa024d1c7bc1e7d2800 (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 1ae763d4ecb847ea17dbaf97565af58dae832d02
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Nov 26 17:03:56 2010 +0200

    mh: further improvements in mnh & mh testsuite.
    
    * mh/mhn.c (_mhn_profile_get): Try mhn-<prefix>-<type> if
    mhn-<prefix>-<type>/<subtype> does not exist.
    (normalize_path): Use mu_normalize_path.
    (store_handler) <store_to_file>: Honor mhn-<prefix>, if set.
    * tests/atlocal.in (remove_curdir): New function.
    * mh/tests/mhn.at: Implement more -store tests.
    * mh/tests/testsuite.at (MH_SETUP): Set curdir for use by other testcases.
    * mh/tests/comp.at: Use remove_curdir to sort out the cwd.
    * mh/tests/forw.at: Likewise.
    * mh/tests/mark.at: Likewise.
    * mh/tests/mhpath.at: Likewise.
    * mh/tests/repl.at: Likewise.

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

Summary of changes:
 mh/mhn.c              |   65 ++++++-----------------
 mh/tests/atlocal.in   |    4 +-
 mh/tests/comp.at      |   18 +++----
 mh/tests/forw.at      |   21 +++-----
 mh/tests/mark.at      |    1 -
 mh/tests/mhn.at       |  139 +++++++++++++++++++++++++++++++++++++++++++++++++
 mh/tests/mhpath.at    |   19 +++----
 mh/tests/repl.at      |    6 +-
 mh/tests/testsuite.at |    6 +-
 9 files changed, 187 insertions(+), 92 deletions(-)

diff --git a/mh/mhn.c b/mh/mhn.c
index 132c676..e39e498 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -585,17 +585,16 @@ _mhn_profile_get (const char *prefix, const char *type, const char *subtype,
 		  const char *defval)
 {
   char *name;
-  const char *str;
+  const char *str = NULL;
   
   if (subtype)
     {
       mu_asprintf (&name, "mhn-%s-%s/%s", prefix, type, subtype);
       str = mh_global_profile_get (name, NULL);
       free (name);
-      if (!str)
-	return _mhn_profile_get (prefix, type, NULL, defval);
     }
-  else
+
+  if (!str)
     {
       mu_asprintf (&name, "mhn-%s-%s", prefix, type);
       str = mh_global_profile_get (name, defval);
@@ -1533,58 +1532,16 @@ mhn_show ()
 char *
 normalize_path (const char *cwd, char *path)
 {
-  int len;
-  char *p;
+  size_t len;
   char *pcwd = NULL;
   
   if (!path)
     return path;
 
-  if (path[0] == '/')
-    return NULL;
-
   if (!cwd)
     cwd = pcwd = mu_getcwd ();
 
-  path = mh_safe_make_file_name (cwd, path);
-
-  /* delete trailing delimiter if any */
-  if (len && path[len-1] == '/')
-    path[len-1] = 0;
-
-  /* Eliminate any /../ */
-  for (p = strchr (path, '.'); p; p = strchr (p, '.'))
-    {
-      if (p > path && p[-1] == '/')
-	{
-	  if (p[1] == '.' && (p[2] == 0 || p[2] == '/'))
-	    /* found */
-	    {
-	      char *q, *s;
-
-	      /* Find previous delimiter */
-	      for (q = p-2; *q != '/' && q >= path; q--)
-		;
-
-	      if (q < path)
-		break;
-	      /* Copy stuff */
-	      s = p + 2;
-	      p = q;
-	      while ((*q++ = *s++))
-		;
-	      continue;
-	    }
-	}
-
-      p++;
-    }
-
-  if (path[0] == 0)
-    {
-      path[0] = '/';
-      path[1] = 0;
-    }
+  path = mu_normalize_path (mh_safe_make_file_name (cwd, path));
 
   len = strlen (cwd);
   if (strlen (path) < len || memcmp (path, cwd, len))
@@ -1694,6 +1651,18 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
       break;
 
     case store_to_file:
+      if (dir && name[0] != '/')
+	{
+	  char *s = mu_make_file_name (dir, name);
+	  if (!s)
+	    {
+	      rc = ENOMEM;
+	      mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, rc);
+	      break;
+	    }
+	  free (name);
+	  name = s;
+	}
       printf (_("storing message %s part %s as file %s\n"),
 	      prefix, partstr, name);
 
diff --git a/mh/tests/atlocal.in b/mh/tests/atlocal.in
index 66fb14c..7c53369 100644
--- a/mh/tests/atlocal.in
+++ b/mh/tests/atlocal.in
@@ -3,4 +3,6 @@
 # Copyright (C) 2004, 2010 Free Software Foundation, Inc.
 
 PATH=@abs_builddir@:@abs_top_builddir@/mh:$top_srcdir:$srcdir:$PATH
-  
\ No newline at end of file
+remove_curdir() {
+	sed "s|$curdir/*||;s|  *$||" $*
+}	
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index fee2040..52c9619 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -18,8 +18,7 @@ m4_pushdef([MH_KEYWORDS],[comp])
 m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
 
 MH_CHECK([comp -file],[comp00 comp-file],[
-dir=`pwd`
-echo quit | compcmd -file ./infile | sed "s|$dir/*||;s|  *$||"
+echo quit | compcmd -file ./infile | remove_curdir
 cat infile
 ],
 [0],
@@ -39,8 +38,7 @@ Seen by mhed
 ])
 
 MH_CHECK([comp -file (del)],[comp01 comp-file_del],[
-dir=`pwd`
-echo 'quit -delete' | compcmd -file ./infile | sed "s|$dir/*||;s|  *$||"
+echo 'quit -delete' | compcmd -file ./infile | remove_curdir
 ],
 [0],
 [-- Editor invocation: ./infile
@@ -53,7 +51,7 @@ Subject:
 What now?])
 
 MH_CHECK([comp file],[comp02 comp_file],[
-echo 'quit' | compcmd file | sed "s|$dir/*||;s|  *$||"
+echo 'quit' | compcmd file | remove_curdir
 cat Mail/file 
 ],
 [0], 
@@ -80,7 +78,7 @@ Subject: test input
 message body
 ])
 
-echo 'quit' | compcmd -use file | sed "s|$dir/*||;s|  *$||"
+echo 'quit' | compcmd -use file | remove_curdir
 cat Mail/file 
 ],
 [0], 
@@ -110,7 +108,7 @@ Subject: test input
 message body
 ])
 
-echo 'quit' | compcmd +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo 'quit' | compcmd +inbox 1 | remove_curdir
 echo Mail/draft
 cat Mail/draft
 echo Message
@@ -143,8 +141,7 @@ message body
 
 MH_CHECK([comp -draftfolder],[comp05 comp-draftfolder draftfolder],[
 mkdir Mail/drafts
-dir=`pwd`
-echo 'quit' | compcmd -draftfolder drafts | sed "s|$dir/*||;s|  *$||"
+echo 'quit' | compcmd -draftfolder drafts | remove_curdir
 cat Mail/drafts/1
 ],
 [0],
@@ -173,8 +170,7 @@ message body
 ])
 echo "cur: 1" > Mail/drafts/.mh_sequences
 
-dir=`pwd`
-echo 'quit' | compcmd -draftfolder drafts -use| sed "s|$dir/*||;s|  *$||"
+echo 'quit' | compcmd -draftfolder drafts -use| remove_curdir
 cat Mail/drafts/1
 ],
 [0],
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
index 0b68122..e749a81 100644
--- a/mh/tests/forw.at
+++ b/mh/tests/forw.at
@@ -26,8 +26,7 @@ Subject: test input
 message body
 ])
 
-dir=`pwd`
-echo quit | forwcmd +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo quit | forwcmd +inbox 1 | remove_curdir
 echo == Mail/draft ==
 cat Mail/draft
 echo == Message ==
@@ -87,8 +86,7 @@ Subject: test input
 message body
 ])
 
-dir=`pwd`
-echo quit | forwcmd -format +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo quit | forwcmd -format +inbox 1 | remove_curdir
 echo == Mail/draft ==
 cat Mail/draft
 echo == Message ==
@@ -154,8 +152,7 @@ Subject: 2nd message
 2nd message body
 ])
 
-dir=`pwd`
-echo quit | forwcmd +inbox 1 2 | sed "s|$dir/*||;s|  *$||"
+echo quit | forwcmd +inbox 1 2 | remove_curdir
 echo == Mail/draft ==
 cat Mail/draft
 echo == Message 1 ==
@@ -239,8 +236,7 @@ Subject: test input
 message body
 ])
 
-dir=`pwd`
-forwcmd -build +inbox 1 | sed "s|$dir/*||;s|  *$||"
+forwcmd -build +inbox 1 | remove_curdir
 echo == Mail/draft ==
 cat Mail/draft
 echo == Message ==
@@ -285,10 +281,9 @@ Subject: 2nd message
 2nd message body
 ])
 
-dir=`pwd`
-forwcmd -build -mime +inbox 1 2 | sed "s|$dir/*||;s|  *$||"
+forwcmd -build -mime +inbox 1 2 | remove_curdir
 echo == Mail/draft ==
-sed "s|$dir/*||;s|  *$||" Mail/draft
+remove_curdir Mail/draft
 echo == Message 1 ==
 sed '/^X-IMAPbase/d' Mail/inbox/1
 echo == Message 2 ==
@@ -326,7 +321,7 @@ Subject: test input
 message body
 ])
 
-echo "quit" | forwcmd -draftfolder drafts 1 | sed "s|$dir/*||;s|  *$||"
+echo "quit" | forwcmd -draftfolder drafts 1 | remove_curdir
 echo == Mail/drafts/1 ==
 cat Mail/drafts/1
 echo == Message ==
@@ -383,7 +378,7 @@ Subject: test input
 message body
 ])
 
-echo "quit" | forwcmd -file infile | sed "s|$dir/*||;s|  *$||"
+echo "quit" | forwcmd -file infile | remove_curdir
 ],
 [0],
 [-- Editor invocation: Mail/draft
diff --git a/mh/tests/mark.at b/mh/tests/mark.at
index 623ed3a..1738a58 100644
--- a/mh/tests/mark.at
+++ b/mh/tests/mark.at
@@ -44,7 +44,6 @@ MH_CHECK([mark -add -nopublic],[mark02 mark-add-nopublic],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 echo 'Current-Folder: inbox' > Mail/context
 mark -nopublic -sequence andro -add 1 2 3
-dir=`pwd`
 sed -n '/^atr-andro/{s/  */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p}' Mail/context
 ],
 [0],
diff --git a/mh/tests/mhn.at b/mh/tests/mhn.at
index bef8ae3..a2fcd4e 100644
--- a/mh/tests/mhn.at
+++ b/mh/tests/mhn.at
@@ -127,5 +127,144 @@ Do you think I can listen all day to such stuff?
 Be off, or I'll kick you down stairs!'
 ])
 
+MH_CHECK([mhn -store -auto],[mhn03 mhn-store-auto],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhn +inbox -store -auto 4 | remove_curdir || exit $?
+],
+[0],
+[storing message 4 part 1 as file msg.21
+storing message 4 part 2.1 as file msg.22
+storing message 4 part 2.2.1 as file msg.23
+storing message 4 part 2.2.2 as file msg.24
+])
+
+MH_CHECK([mhn -store -auto -part],[mhn04 mhn-store-auto-part],[
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $?
+],
+[0],
+[storing message 4 part 2.2.1 as file msg.23
+])
+
+MH_CHECK([mhn -store -auto (pathname safety)],[mhn05 mhn-store-auto-safety],[
+mkdir Mail/inbox
+sed 's|; *name="msg|; name="../msg|' \
+  $abs_top_srcdir/testsuite/mh/mbox1/4 > Mail/inbox/4
+mhn +inbox -store -auto -part 2.1 4 || echo $?
+echo == 4.2.1.octet-stream ==
+cat 4.2.1.octet-stream
+],
+[0],
+[storing message 4 part 2.1 as file 4.2.1.octet-stream
+== 4.2.1.octet-stream ==
+`You are old,' said the youth, `as I mentioned before,
+And have grown most uncommonly fat;
+Yet you turned a back-somersault in at the door--
+Pray, what is the reason of that?'
+
+`In my youth,' said the sage, as he shook his grey locks,
+`I kept all my limbs very supple
+By the use of this ointment--one shilling the box--
+Allow me to sell you a couple?'
+])
+
+MH_CHECK([mhn-storage],[mhn06 mhn-store-auto],[
+mkdir Mail/inbox
+cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
+
+mkdir out
+echo "mhn-storage: $curdir/out" >> $MH
+
+mhn +inbox -store 4 | remove_curdir || echo $?
+],
+[0],
+[storing message 4 part 1 as file out/4.1.plain
+storing message 4 part 2.1 as file out/4.2.1.octet-stream
+storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream
+storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream
+])
+
+MH_CHECK([mhn-store-: all escapes],[mhn07 mhn-store_escapes],[
+mkdir Mail/inbox
+cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
+echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
+mhn +inbox -store 4 | remove_curdir || exit $?
+find . -name '%*'
+],
+[0],
+[storing message 4 part 1 as file 4.1.plain
+storing message 4 part 2.1 as file %4.2.1.octet-stream-2.1
+storing message 4 part 2.2.1 as file %4.2.2.1.octet-stream-2.2.1
+storing message 4 part 2.2.2 as file %4.2.2.2.octet-stream-2.2.2
+./%4.2.1.octet-stream-2.1
+./%4.2.2.1.octet-stream-2.2.1
+./%4.2.2.2.octet-stream-2.2.2
+])
+
+MH_CHECK([mhn-store-: absolute path],[mhn08 mhn-store_abspath],[
+mkdir Mail/inbox
+mkdir out
+cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
+echo "mhn-store-application: $curdir/out/%m%P.%s" >> $MH
+mhn +inbox -store 4 | remove_curdir || exit $?
+],
+[0],
+[storing message 4 part 1 as file 4.1.plain
+storing message 4 part 2.1 as file out/4.2.1.octet-stream
+storing message 4 part 2.2.1 as file out/4.2.2.1.octet-stream
+storing message 4 part 2.2.2 as file out/4.2.2.2.octet-stream
+])
+
+MH_CHECK([mhn-store-: +folder],[mhn09 mhn-store+folder],[
+mkdir Mail/inbox
+mkdir Mail/app
+cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
+echo "mhn-store-application: +app" >> $MH
+mhn +inbox -store 4 | remove_curdir || exit $?
+],
+[0],
+[storing message 4 part 1 as file 4.1.plain
+storing message 4 part 2.1 to folder +app as message 1
+storing message 4 part 2.2.1 to folder +app as message 2
+storing message 4 part 2.2.2 to folder +app as message 3
+])
+
+MH_CHECK([mhn-store-: +],[mhn10 mhn-store+],[
+mkdir Mail/inbox
+cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
+echo "Current-Folder: inbox" > Mail/context
+cat >> $MH <<EOT
+mhn-store-application/octet-stream: +
+EOT
+mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $?
+],
+[0],
+[storing message 4 part 2.2.1 to folder inbox as message 5
+])
+
+MH_CHECK([mhn-store-: pipe],[mhn11 mhn-store-pipe],[
+mkdir Mail/inbox
+cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
+echo "Current-Folder: inbox" > Mail/context
+echo "mhn-store-text: | $abs_top_srcdir/mh/tests/mhed -" >> $MH
+mhn +inbox -store -part 1 4 | sed 's| *$||' || exit $?
+],
+[0],
+[-- Editor invocation: -
+-- Input file:
+`You are old, Father William,' the young man said,
+`And your hair has become very white;
+And yet you incessantly stand on your head--
+Do you think, at your age, it is right?'
+
+`In my youth,' Father William replied to his son,
+`I feared it might injure the brain;
+But, now that I'm perfectly sure I have none,
+Why, I do it again and again.'
+
+-- Input file end
+storing msg 4 part 1 using command /home/gray/gnu/mailutils/mh/tests/mhed -
+])
+
 m4_popdef[MH_KEYWORDS])
 # End of mhn.at
diff --git a/mh/tests/mhpath.at b/mh/tests/mhpath.at
index ba08c38..48cfdad 100644
--- a/mh/tests/mhpath.at
+++ b/mh/tests/mhpath.at
@@ -19,7 +19,7 @@ m4_pushdef([MH_KEYWORDS],[mhpath])
 MH_CHECK([mhpath],[mhpath00],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 echo 'Current-Folder: inbox' > Mail/context
-mhpath | sed 's|^'"$dir"'/||'
+mhpath | remove_curdir
 ],
 [0],
 [Mail/inbox
@@ -28,7 +28,7 @@ mhpath | sed 's|^'"$dir"'/||'
 MH_CHECK([mhpath +],[mhpath01 mhpath+],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 echo 'Current-Folder: inbox' > Mail/context
-mhpath +| sed 's|^'"$dir"'/||'
+mhpath +| remove_curdir
 ],
 [0],
 [Mail
@@ -36,8 +36,7 @@ mhpath +| sed 's|^'"$dir"'/||'
 
 MH_CHECK([mhpath msgs],[mhpath02 mhparam_msgs],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
-dir=`pwd`
-mhpath 1-3 | sed 's|^'"$dir"'/||'
+mhpath 1-3 | remove_curdir
 ],
 [0],
 [Mail/inbox/1
@@ -47,8 +46,7 @@ Mail/inbox/3
 
 MH_CHECK([mhpath msgs (some nonexistent)],[mhpath03 mhparam_msgs_some_nonex],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
-dir=`pwd`
-mhpath 4-10 | sed 's|^'"$dir"'/||'
+mhpath 4-10 | remove_curdir
 ],
 [0],
 [Mail/inbox/4
@@ -57,8 +55,7 @@ Mail/inbox/5
 
 MH_CHECK([mhpath msgs (all nonexistent)],[mhpath04 mhparam_msgs_all_nonex],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
-dir=`pwd`
-mhpath 8-10 | sed 's|^'"$dir"'/||'
+mhpath 8-10 | remove_curdir
 ],
 [0],
 [],
@@ -89,8 +86,7 @@ mhpath 8-10 | sed 's|^'"$dir"'/||'
 
 MH_CHECK([mhpath nonexistent],[mhpath05 mhparam_nonexistent],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
-dir=`pwd`
-mhpath 10 | sed 's|^'"$dir"'/||'
+mhpath 10 | remove_curdir
 ],
 [0],
 [],
@@ -99,8 +95,7 @@ mhpath 10 | sed 's|^'"$dir"'/||'
 
 MH_CHECK([mhpath new],[mhpath06 mhparam_new],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
-dir=`pwd`
-mhpath new | sed 's|^'"$dir"'/||'
+mhpath new | remove_curdir
 ],
 [0],
 [Mail/inbox/6
diff --git a/mh/tests/repl.at b/mh/tests/repl.at
index 2df8e6b..81a7bd2 100644
--- a/mh/tests/repl.at
+++ b/mh/tests/repl.at
@@ -26,7 +26,7 @@ Subject: test input
 
 message body
 ])
-echo "quit" | replcmd +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo "quit" | replcmd +inbox 1 | remove_curdir
 echo == Mail/draft ==
 cat Mail/draft
 ],
@@ -56,7 +56,7 @@ Subject: test input
 
 message body
 ])
-echo "quit" | replcmd -draftfolder drafts +inbox 1 | sed "s|$dir/*||;s|  *$||"
+echo "quit" | replcmd -draftfolder drafts +inbox 1 | remove_curdir
 echo == Mail/drafts/1 ==
 cat Mail/drafts/1
 ],
@@ -79,4 +79,4 @@ Seen by mhed
 
 m4_popdef([replcmd])
 m4_popdef([MH_KEYWORDS])
-# End of repl.at
\ No newline at end of file
+# End of repl.at
diff --git a/mh/tests/testsuite.at b/mh/tests/testsuite.at
index ef4def6..8699938 100644
--- a/mh/tests/testsuite.at
+++ b/mh/tests/testsuite.at
@@ -18,11 +18,11 @@ m4_include([testsuite.inc])
 
 m4_define([MH_SETUP],[
 test -d Mail || mkdir Mail
-dir=`pwd`
-MH=$dir/mh_profile
+curdir=`pwd`
+MH=$curdir/mh_profile
 export MH
 cat > $MH <<EOT
-Path: $dir/Mail
+Path: $curdir/Mail
 mhetcdir: $abs_top_srcdir/mh/etc
 EOT
 exec <&-


hooks/post-receive
-- 
GNU Mailutils


