From MAILER-DAEMON Sat Oct 15 07:44:40 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RF2fQ-0007qP-Dc
	for mharc-commit-mailutils@gnu.org; Sat, 15 Oct 2011 07:44:40 -0400
Received: from eggs.gnu.org ([140.186.70.92]:37933)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RF2fL-0007qB-3T
	for commit-mailutils@gnu.org; Sat, 15 Oct 2011 07:44:38 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RF2fG-0002ID-Ug
	for commit-mailutils@gnu.org; Sat, 15 Oct 2011 07:44:35 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:34782)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RF2fG-0002I9-SS
	for commit-mailutils@gnu.org; Sat, 15 Oct 2011 07:44:30 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RF2fG-0003rC-49
	for commit-mailutils@gnu.org; Sat, 15 Oct 2011 11:44:30 +0000
Date: Sat, 15 Oct 2011 11:44:30 +0000
Message-Id: <E1RF2fG-0003rC-49@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-391-g5e5b68f
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: e759db27d650197ed1d8f837f30a2d03dcc23b4a
X-Git-Newrev: 5e5b68fd028495f7076a576df26962bbdf51ac63
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 15 Oct 2011 11:44: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=5e5b68fd028495f7076a576df26962bbdf51ac63

The branch, master has been updated
       via  5e5b68fd028495f7076a576df26962bbdf51ac63 (commit)
      from  e759db27d650197ed1d8f837f30a2d03dcc23b4a (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 5e5b68fd028495f7076a576df26962bbdf51ac63
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Oct 15 14:30:40 2011 +0300

    imap4d: fix returned INTERNALDATE and date searches.
    
    INTERNALDATE now includes a meaningful timezone information (it
    used to return +0000).
    
    Date searches disregard the time and timezone of the INTERNALDATE
    or Date: header, as mandated by RFC 3501.
    
    * libmailutils/base/date.c (mu_parse_ctime_date_time): In the absence
    of TZ in ctime strings, return local time zone.
    
    * imap4d/io.c (imap4d_tokbuf_getline): Kill trailing whitespace.
    
    * imap4d/util.c (adjust_tm): New function.
    (util_parse_internal_date)
    (util_parse_822_date)
    (util_parse_ctime_date): Take three arguments, the third one controlling
    what information to return. All uses updated.
    * imap4d/fetch.c (_frt_internaldate): Return meaningful timezone.
    If all else fails, use local TZ.
    * imap4d/imap4d.h (datetime_parse_mode): New enum.
    (util_parse_internal_date)
    (util_parse_822_date)
    (util_parse_ctime_date): Change signature.
    * imap4d/search.c (parse_simple_key)
    (_header_date,cond_before,cond_on,cond_since): Use datetime_date_only mode.
    
    * testsuite/spool/search.mbox: New file.
    * testsuite/spool/DISTFILES: Add search.mbox
    * imap4d/testsuite/lib/imap4d.exp (imap4d_start): New option -mbox.
    * imap4d/testsuite/imap4d/search.exp: Rewrite.
    
    * imap4d/testsuite/imap4d/create.exp: Account for TZ part in internaldate
    strings, which may vary.
    * imap4d/testsuite/imap4d/fetch.exp: Likewise.
    * imap4d/testsuite/imap4d/list.exp: List the new mailbox.

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

Summary of changes:
 imap4d/append.c                    |    2 +-
 imap4d/fetch.c                     |   23 ++++++-
 imap4d/imap4d.h                    |   17 +++++-
 imap4d/io.c                        |    2 +
 imap4d/search.c                    |   11 ++--
 imap4d/testsuite/imap4d/create.exp |    2 +-
 imap4d/testsuite/imap4d/fetch.exp  |   18 +++---
 imap4d/testsuite/imap4d/list.exp   |    4 +
 imap4d/testsuite/imap4d/search.exp |  102 +++++++++++++++------------------
 imap4d/testsuite/lib/imap4d.exp    |    7 ++-
 imap4d/util.c                      |   44 +++++++++++++-
 libmailutils/base/date.c           |   11 ++-
 testsuite/lib/mailutils.exp        |    2 +-
 testsuite/spool/DISTFILES          |    1 +
 testsuite/spool/search.mbox        |  113 ++++++++++++++++++++++++++++++++++++
 15 files changed, 271 insertions(+), 88 deletions(-)
 create mode 100644 testsuite/spool/search.mbox

diff --git a/imap4d/append.c b/imap4d/append.c
index 10cbafe..ed01200 100644
--- a/imap4d/append.c
+++ b/imap4d/append.c
@@ -79,7 +79,7 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
      message is set to the current date and time by default. */
   if (date_time)
     {
-      if (util_parse_internal_date (date_time, &t))
+      if (util_parse_internal_date (date_time, &t, datetime_default))
 	{
 	  *err_text = "Invalid date/time format";
 	  return 1;
diff --git a/imap4d/fetch.c b/imap4d/fetch.c
index 2f645aa..077e38b 100644
--- a/imap4d/fetch.c
+++ b/imap4d/fetch.c
@@ -862,19 +862,34 @@ _frt_internaldate (struct fetch_function_closure *ffc,
   struct tm tm, *tmp = NULL;
   mu_timezone tz;
   char datebuf[sizeof ("13-Jul-2002 00:00:00")];
-
+  int tzoff;
+  int tzh = 0, tzm = 0;
+  
   mu_message_get_envelope (frt->msg, &env);
   if (mu_envelope_sget_date (env, &date) == 0
       && mu_parse_ctime_date_time (&date, &tm, &tz) == 0)
-    tmp = &tm;
+    {
+      tmp = &tm;
+      tzoff = tz.utc_offset;
+    }
   else
     {
-      time_t t = time (NULL);
+      time_t t;
+      struct timeval stv;
+      struct timezone stz;
+      
+      gettimeofday(&stv, &stz);
+      t = stv.tv_sec;
+      tzoff = - stz.tz_minuteswest;
       tmp = localtime (&t);
     }
+  tzh = tzoff / 3600;
+  if (tzoff < 0)
+    tzoff = - tzoff;
+  tzm = tzoff % 3600;
   mu_strftime (datebuf, sizeof (datebuf), "%d-%b-%Y %H:%M:%S", tmp);
   io_sendf ("%s", ffc->name);
-  io_sendf (" \"%s +0000\"", datebuf);
+  io_sendf (" \"%s %+03d%02d\"", datebuf, tzh, tzm);
   return 0;
 }
 
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index 8d6170b..5245e2f 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -367,9 +367,20 @@ extern char *util_getfullpath (const char *, const char *);
 extern int  util_msgset (char *, size_t **, int *, int);
 extern struct imap4d_command *util_getcommand (char *, 
                                                struct imap4d_command []);
-extern int util_parse_internal_date (char *date, time_t *timep);
-extern int util_parse_822_date (const char *date, time_t *timep);
-extern int util_parse_ctime_date (const char *date, time_t *timep);
+
+enum datetime_parse_mode     /* how to parse date/time strings */
+  {
+    datetime_default,        /* default mode */
+    datetime_date_only,      /* return only date part, ignore time and TZ */
+    datetime_time_only       /* return only time and TZ, ignore date */ 
+  };
+
+extern int util_parse_internal_date (char *date, time_t *timep,
+				     enum datetime_parse_mode flag);
+extern int util_parse_822_date (const char *date, time_t *timep,
+				enum datetime_parse_mode flag);
+extern int util_parse_ctime_date (const char *date, time_t *timep,
+				  enum datetime_parse_mode flag);
 extern char *util_strcasestr (const char *haystack, const char *needle);
 extern char *util_localname (void);
 
diff --git a/imap4d/io.c b/imap4d/io.c
index 3cfa373..6c1c375 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -548,6 +548,8 @@ imap4d_tokbuf_getline (struct imap4d_tokbuf *tok)
   tok->buffer[--tok->level] = 0;
   if (tok->buffer[tok->level - 1] == '\r')
     tok->buffer[--tok->level] = 0;
+  while (tok->level > 0 && mu_isblank (tok->buffer[tok->level-1]))
+    tok->buffer[--tok->level] = 0;
   return level;
 }
 
diff --git a/imap4d/search.c b/imap4d/search.c
index e2fa6c2..bb9656b 100644
--- a/imap4d/search.c
+++ b/imap4d/search.c
@@ -670,7 +670,8 @@ parse_simple_key (struct parsebuf *pb)
 	      break;
 	      
 	    case 'd': /* date */
-	      if (util_parse_internal_date (pb->token, &time))
+	      if (util_parse_internal_date (pb->token, &time,
+					    datetime_date_only))
 		{
 		  pb->err_mesg = "Bad date format";
 		  return NULL;
@@ -801,7 +802,7 @@ _header_date (struct parsebuf *pb, time_t *timep)
   
   mu_message_get_header (pb->msg, &header);
   if (mu_header_sget_value (header, "Date", &hval) == 0
-      && util_parse_822_date (hval, timep))
+      && util_parse_822_date (hval, timep, datetime_date_only))
     return 0;
   return 1;
 }
@@ -893,7 +894,7 @@ cond_before (struct parsebuf *pb, struct search_node *node, struct value *arg,
     retval->v.number = 0;
   else
     {
-      util_parse_ctime_date (date, &mesg_time);
+      util_parse_ctime_date (date, &mesg_time, datetime_date_only);
       retval->v.number = mesg_time < t;
     }
 }                   
@@ -980,7 +981,7 @@ cond_on (struct parsebuf *pb, struct search_node *node, struct value *arg,
     retval->v.number = 0;
   else
     {
-      util_parse_ctime_date (date, &mesg_time);
+      util_parse_ctime_date (date, &mesg_time, datetime_date_only);
       retval->v.number = t <= mesg_time && mesg_time <= t + 86400;
     }
 }                       
@@ -1038,7 +1039,7 @@ cond_since (struct parsebuf *pb, struct search_node *node, struct value *arg,
     retval->v.number = 0;
   else
     {
-      util_parse_ctime_date (date, &mesg_time);
+      util_parse_ctime_date (date, &mesg_time, datetime_date_only);
       retval->v.number = mesg_time >= t;
     }
 }                    
diff --git a/imap4d/testsuite/imap4d/create.exp b/imap4d/testsuite/imap4d/create.exp
index f7748ff..a0d0e0f 100644
--- a/imap4d/testsuite/imap4d/create.exp
+++ b/imap4d/testsuite/imap4d/create.exp
@@ -63,7 +63,7 @@ imap4d_test "SELECT en/to/tre"\
 "OK \[READ-WRITE\] SELECT Completed"
 
 imap4d_test "FETCH 1 ALL"\
-"1 FETCH (FLAGS (\\Recent) INTERNALDATE \"25-Aug-2002 16:00:00 +0000\" RFC822.SIZE 285 ENVELOPE (\"Mon, 7 Feb 1994 21:52:25 -0800 (PST)\" \"afternoon meeting again\" ((\"Fred Foobar\" NIL \"foobar\" \"Blurdybloop.COM\")) ((\"Fred Foobar\" NIL \"foobar\" \"Blurdybloop.COM\")) ((\"Fred Foobar\" NIL \"foobar\" \"Blurdybloop.COM\")) ((NIL NIL \"mooch\" \"owatagu.siam.edu\")) NIL NIL NIL \"<B27397-0200000@Blurdybloop.COM>\"))"\
+-re {1 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"25-Aug-2002 16:00:00 [+-][0-9][0-9][0-9][0-9]\" RFC822.SIZE 285 ENVELOPE \(\"Mon, 7 Feb 1994 21:52:25 -0800 \(PST\)\" \"afternoon meeting again\" \(\(\"Fred Foobar\" NIL \"foobar\" \"Blurdybloop.COM\"\)\) \(\(\"Fred Foobar\" NIL \"foobar\" \"Blurdybloop.COM\"\)\) \(\(\"Fred Foobar\" NIL \"foobar\" \"Blurdybloop.COM\"\)\) \(\(NIL NIL \"mooch\" \"owatagu.siam.edu\"\)\) NIL NIL NIL \"<B27397-0200000@Blurdybloop.COM>\"\)\)}\
 "OK"
 
 	
diff --git a/imap4d/testsuite/imap4d/fetch.exp b/imap4d/testsuite/imap4d/fetch.exp
index 4b3708a..33f5131 100644
--- a/imap4d/testsuite/imap4d/fetch.exp
+++ b/imap4d/testsuite/imap4d/fetch.exp
@@ -47,7 +47,7 @@ imap4d_test "FETCH 3 (FLAGS)"\
 
 # INTERNALDATE   The internal date of the message.
 imap4d_test "FETCH 3 INTERNALDATE"\
-"3 FETCH (INTERNALDATE \"13-Jul-2002 00:43:18 +0000\")"\
+-re {3 FETCH \(INTERNALDATE \"13-Jul-2002 00:43:18 [+-][0-9][0-9][0-9][0-9]\"\)} \
 "OK"
 
 # UID            The unique identifier for the message.
@@ -56,7 +56,7 @@ imap4d_test "FETCH 3 UID"\
 "OK"
 
 imap4d_test "FETCH 3 (FLAGS INTERNALDATE UID)"\
-"3 FETCH (FLAGS (\\Recent) INTERNALDATE \"13-Jul-2002 00:43:18 +0000\" UID 3)"\
+-re {3 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"13-Jul-2002 00:43:18 [+-][0-9][0-9][0-9][0-9]\" UID 3\)}\
 "OK"
 
 # ENVELOPE       The envelope structure of the message.  This is
@@ -76,11 +76,11 @@ imap4d_test "FETCH 1:* ENVELOPE"\
 #                RFC822.SIZE 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 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>\"))"\
+-re {1 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"28-Dec-2001 22:18:09 [+-][0-9][0-9][0-9][0-9]\" 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>\"\)\)}\
+-re {2 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"28-Dec-2001 23:28:09 [+-][0-9][0-9][0-9][0-9]\" 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>\"\)\)}\
+-re {3 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"13-Jul-2002 00:43:18 [+-][0-9][0-9][0-9][0-9]\" 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>\"\)\)}\
+-re {4 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"13-Jul-2002 00:50:58 [+-][0-9][0-9][0-9][0-9]\" 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>\"\)\)}\
+-re {5 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"13-Jul-2002 00:43:18 [+-][0-9][0-9][0-9][0-9]\" 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
@@ -508,14 +508,14 @@ imap4d_test "FETCH 2 RFC822.TEXT"\
 #                RFC822.SIZE)
 
 imap4d_test "FETCH 1 FAST" \
-"1 FETCH (FLAGS (\\Seen \\Recent) INTERNALDATE \"28-Dec-2001 22:18:09 +0000\" RFC822.SIZE 1298)"\
+-re {1 FETCH \(FLAGS \(\\Seen \\Recent\) INTERNALDATE \"28-Dec-2001 22:18:09 [+-][0-9][0-9][0-9][0-9]\" RFC822.SIZE 1298\)}\
 "OK"
 
 # FULL           Macro equivalent to: (FLAGS INTERNALDATE
 #                RFC822.SIZE ENVELOPE BODY)
 
 imap4d_test "FETCH 4 FULL"\
-"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))"\
+    -re {4 FETCH \(FLAGS \(\\Recent\) INTERNALDATE \"13-Jul-2002 00:50:58 [+-][0-9][0-9][0-9][0-9]\" 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/imap4d/testsuite/imap4d/list.exp b/imap4d/testsuite/imap4d/list.exp
index 99d8c14..a0db60b 100644
--- a/imap4d/testsuite/imap4d/list.exp
+++ b/imap4d/testsuite/imap4d/list.exp
@@ -22,6 +22,7 @@ imap4d_auth "user!passwd" "guessme"
 imap4d_test -sort "LIST \"~\" \"*\""\
 "LIST (\\NoInferiors) \"/\" ~/mbox1"\
 "LIST (\\NoInferiors) \"/\" ~/mbox"\
+"LIST (\\NoInferiors) \"/\" ~/search.mbox"\
 "LIST (\\NoInferiors) \"/\" ~/sieve.mbox"\
 "LIST (\\NoInferiors) \"/\" ~/teaparty.mbox"\
 "LIST (\\NoInferiors) \"/\" ~/bigto.mbox"\
@@ -31,6 +32,7 @@ imap4d_test -sort "LIST \"~\" \"*\""\
 imap4d_test -sort "LIST \"~\" \"%\""\
 "LIST (\\NoInferiors) \"/\" ~/mbox1"\
 "LIST (\\NoInferiors) \"/\" ~/mbox"\
+"LIST (\\NoInferiors) \"/\" ~/search.mbox"\
 "LIST (\\NoInferiors) \"/\" ~/sieve.mbox"\
 "LIST (\\NoInferiors) \"/\" ~/teaparty.mbox"\
 "LIST (\\NoInferiors) \"/\" ~/bigto.mbox"\
@@ -41,6 +43,7 @@ imap4d_test -sort "LIST \"\" \"*\""\
 "LIST (\\NoInferiors) NIL INBOX"\
 "LIST (\\NoInferiors) \"/\" mbox1"\
 "LIST (\\NoInferiors) \"/\" mbox"\
+"LIST (\\NoInferiors) \"/\" search.mbox"\
 "LIST (\\NoInferiors) \"/\" sieve.mbox"\
 "LIST (\\NoInferiors) \"/\" teaparty.mbox"\
 "LIST (\\NoInferiors) \"/\" bigto.mbox"\
@@ -60,6 +63,7 @@ imap4d_test -sort "LIST \"$MU_DATA_DIR\" \"*\""\
 "LIST (\\NoInferiors) \"/\" $MU_DATA_DIR/spool/relational.mbox" \
 "LIST (\\NoInferiors) \"/\" $MU_DATA_DIR/spool/mbox1"\
 "LIST (\\NoInferiors) \"/\" $MU_DATA_DIR/spool/mbox"\
+"LIST (\\NoInferiors) \"/\" $MU_DATA_DIR/spool/search.mbox"\
 "LIST (\\NoInferiors) \"/\" $MU_DATA_DIR/spool/sieve.mbox"\
 "LIST (\\NoInferiors) \"/\" $MU_DATA_DIR/spool/teaparty.mbox"\
 "LIST (\\NoSelect) \"/\" $MU_DATA_DIR/folder"\
diff --git a/imap4d/testsuite/imap4d/search.exp b/imap4d/testsuite/imap4d/search.exp
index 3087f76..47acab3 100644
--- a/imap4d/testsuite/imap4d/search.exp
+++ b/imap4d/testsuite/imap4d/search.exp
@@ -30,15 +30,15 @@
 #      contains a listing of message sequence numbers corresponding to
 #      those messages that match the searching criteria.
 
-imap4d_start 
+imap4d_start -mbox "search.mbox"
 imap4d_auth "user!passwd" "guessme"
 
 imap4d_test "SELECT INBOX"\
-"95 EXISTS"\
-"95 RECENT"\
+"8 EXISTS"\
+"5 RECENT"\
 -re {OK \[UIDVALIDITY [0-9]+\] UID valididy status}\
-"OK \[UIDNEXT 96\] Predicted next uid"\
-"OK \[UNSEEN 1\] first unseen messsage "\
+"OK \[UIDNEXT 9\] Predicted next uid"\
+"OK \[UNSEEN 4\] first unseen messsage "\
 "FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
 "OK \[PERMANENTFLAGS (\\Answered \\Deleted \\Seen)\] Permanent flags"\
 "OK \[READ-WRITE\] SELECT Completed"
@@ -48,14 +48,14 @@ imap4d_test "SELECT INBOX"\
 #                number set
 
 imap4d_test "SEARCH 1:*" \
-"SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95" \
+"SEARCH 1 2 3 4 5 6 7 8" \
 "OK"
 
 # ALL            All messages in the mailbox; the default initial
 #                key for ANDing.
 
 imap4d_test "SEARCH ALL" \
-"SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95" \
+"SEARCH 1 2 3 4 5 6 7 8" \
 "OK"
 
 # NEW            Messages that have the \Recent flag set but not the
@@ -64,39 +64,39 @@ imap4d_test "SEARCH ALL" \
 
 # All messages are still new
 imap4d_test "SEARCH NEW" \
-"SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95" \
+"SEARCH 4 5 6 7 8" \
 "OK"
 
 # FROM <string>  Messages that contain the specified string in the
 #                envelope structure's FROM field.
 
-imap4d_test "SEARCH FROM alice" \
-"SEARCH 2 4 6 8 10 12 14 20 25 27 29 33 36 38 40 43 45 47 51 53 55 57 59 63 66 68 70 72 74 76 78 80 82 85 87 90 93 95" \
+imap4d_test "SEARCH FROM corrector" \
+"SEARCH 2 4 8" \
 "OK"
 
-imap4d_test "SEARCH FROM hare" \
-"SEARCH 1 3 5 7 9 11 13 16 22 24 35 42 58 62 71" \
+imap4d_test "SEARCH FROM lexi@example.net" \
+"SEARCH 1 3 5 6 7" \
 "OK"
 
 # LARGER <n>     Messages with an [RFC-822] size larger than the
 #                specified number of octets.
 
 imap4d_test "SEARCH LARGER 512" \
-"SEARCH 41 46" \
+"SEARCH 3 4" \
 "OK"
 
 # SMALLER <n>    Messages with an [RFC-822] size smaller than the
 #                specified number of octets.
 
-imap4d_test "SEARCH SMALLER 300" \
-"SEARCH 12 20 35" \
+imap4d_test "SEARCH SMALLER 400" \
+"SEARCH 7 8" \
 "OK"
 
 # SUBJECT <string>   Messages that contain the specified string in the
 #                    envelope structure's SUBJECT field.
 
-imap4d_test "SEARCH SUBJECT \"watch\"" \
-"SEARCH 19 20 21 22 23 24 25 26 27 28 29"\
+imap4d_test "SEARCH SUBJECT \"Alliance\"" \
+"SEARCH 6"\
 "OK"
 
 # HEADER <field-name> <string>
@@ -105,75 +105,65 @@ imap4d_test "SEARCH SUBJECT \"watch\"" \
 #                    contains the specified string in the [RFC-822]
 #                    field-body.
 
-imap4d_test "SEARCH HEADER Message-Id \"<200207292200.3303@wonder.land>\"" \
+imap4d_test "SEARCH HEADER Message-Id \"<200207291200.3303@example.org>\"" \
 "SEARCH 3" \
 "OK"	
 
 # CC <string>    Messages that contain the specified string in the
 #                 envelope structure's CC field.
 
-imap4d_test "SEARCH CC dormouse" \
-"SEARCH 60" \
+imap4d_test "SEARCH CC Corrector" \
+"SEARCH 6" \
 "OK"
 
 # TO <string>    Messages that contain the specified string in the
 #                envelope structure's TO field.
 
-imap4d_test "SEARCH TO hare"\
-"SEARCH 2 4 6 8 10 12 14 21 23 42 59 72" \
+imap4d_test "SEARCH TO editor+recheck"\
+"SEARCH 7" \
 "OK"
 
 # SENTBEFORE <date>
 #                Messages whose [RFC-822] Date: header is earlier
 #                than the specified date.
 
-imap4d_test "SEARCH SENTBEFORE \"29-Jul-2002 22:00:02 +0100\"" \
-"SEARCH 1"\
+imap4d_test "SEARCH SENTBEFORE \"30-Jul-2002\"" \
+"SEARCH 1 2"\
 "OK"
 
 # SENTSINCE <date>
 #                Messages whose [RFC-822] Date: header is within or
 #                later than the specified date.
 
-imap4d_test "SEARCH SENTSINCE \"29-Jul-2002 22:01:32 +0100\""\
-"SEARCH 92 93 94 95"\
-"OK"
-
-imap4d_test "SEARCH SENTSINCE \"29-Jul-2002 23:01:32 +0200\""\
-"SEARCH 92 93 94 95"\
+imap4d_test "SEARCH SENTSINCE \"31-Jul-2002\""\
+"SEARCH 5 6 7 8"\
 "OK"
 
 # BEFORE <date>  Messages whose internal date is earlier than the
 #                specified date.
 
-imap4d_test "SEARCH BEFORE \"29-Jul-2002 22:00:09 +0000\""\
+imap4d_test "SEARCH BEFORE \"30-Jul-2002\""\
 "SEARCH 1"\
 "OK"
 
 # SINCE <date>   Messages whose internal date is within or later
 #                than the specified date.
 
-imap4d_test "SEARCH SINCE \"29-Jul-2002 22:01:36 +0000\""\
-"SEARCH 89 90 91 92 93 94 95"\
-"OK"
-
-imap4d_test "STORE 3,5,89 +FLAGS (\\Answered)"\
-"3 FETCH (FLAGS (\\Answered \\Recent))"\
-"5 FETCH (FLAGS (\\Answered \\Recent))"\
-"89 FETCH (FLAGS (\\Answered \\Recent))"\
+imap4d_test "SEARCH SINCE \"30-Jul-2002\""\
+"SEARCH 2 3 4 5 6 7 8"\
 "OK"
 
 # ANSWERED       Messages with the \Answered flag set.
 
 imap4d_test "SEARCH ANSWERED"\
-"SEARCH 3 5 89"\
+"SEARCH 2 3"\
 "OK"
 
 # TEXT <string>  Messages that contain the specified string in the
 #                header or body of the message.
 
-imap4d_test "SEARCH TEXT wine"\
-"SEARCH 1 2"\
+imap4d_test "SEARCH TEXT person"\
+"SEARCH 2 5 8"\
 "OK"
 
 ## Boolean operations
@@ -181,33 +171,33 @@ imap4d_test "SEARCH TEXT wine"\
 # When multiple keys are specified, the result is the intersection
 # (AND function) of all the messages that match those keys.
 
-imap4d_test "SEARCH TEXT wine FROM alice"\
+imap4d_test "SEARCH TEXT person FROM corrector"\
 "SEARCH 2"\
 "OK"
 
+imap4d_test "SEARCH SENTSINCE \"30-Jul-2002\" SENTBEFORE \"31-Jul-2002\"" \
+"SEARCH 3 4" \
+"OK"    
+
 # OR <search-key1> <search-key2>
 #                Messages that match either search key.
 
-imap4d_test "SEARCH OR FROM alice ANSWERED"\
-"SEARCH 2 3 4 5 6 8 10 12 14 20 25 27 29 33 36 38 40 43 45 47 51 53 55 57 59 63 66 68 70 72 74 76 78 80 82 85 87 89 90 93 95"\
-"OK"
+imap4d_test "SEARCH OR FROM corrector ANSWERED"\
+"SEARCH 2 3 4 8" \
+"OK"    
 
 ## Check precedence
 
-imap4d_test "SEARCH (OR FROM alice ANSWERED) SENTSINCE \"29-Jul-2002 22:00:33 +0100\""\
-"SEARCH 33 36 38 40 43 45 47 51 53 55 57 59 63 66 68 70 72 74 76 78 80 82 85 87 89 90 93 95" \
-"OK"
-
-imap4d_test "SEARCH (OR FROM alice ANSWERED) SENTSINCE \"29-Jul-2002 22:00:33 +0100\" SENTBEFORE \"29-Jul-2002 22:00:56 +0100\""\
-"SEARCH 33 36 38 40 43 45 47 51 53 55"\
+imap4d_test "SEARCH (OR FROM corrector ANSWERED) SENTSINCE \"30-Jul-2002\""\
+"SEARCH 3 4 8" \
 "OK"
 
-imap4d_test "SEARCH OR FROM alice ANSWERED SENTSINCE \"29-Jul-2002 22:00:33 +0100\" SENTBEFORE \"29-Jul-2002 22:00:56 +0100\""\
-"SEARCH 33 36 38 40 43 45 47 51 53 55"\
+imap4d_test "SEARCH OR FROM corrector ANSWERED SENTSINCE \"30-Jul-2002\""\
+"SEARCH 3 4 8" \
 "OK"
 
-imap4d_test "SEARCH OR FROM alice (ANSWERED SENTSINCE \"29-Jul-2002 22:00:33 +0100\" SENTBEFORE \"29-Jul-2002 22:00:56 +0100\")"\
-"SEARCH 2 4 6 8 10 12 14 20 25 27 29 33 36 38 40 43 45 47 51 53 55 57 59 63 66 68 70 72 74 76 78 80 82 85 87 90 93 95"\
+imap4d_test "SEARCH OR FROM corrector (ANSWERED SENTSINCE \"30-Jul-2002\")"\
+"SEARCH 2 3 4 8" \
 "OK"
 
 imap4d_stop
diff --git a/imap4d/testsuite/lib/imap4d.exp b/imap4d/testsuite/lib/imap4d.exp
index c8178c1..b15de23 100644
--- a/imap4d/testsuite/lib/imap4d.exp
+++ b/imap4d/testsuite/lib/imap4d.exp
@@ -107,10 +107,15 @@ proc imap4d_start {args} {
     verbose "Starting imap4d"
 
     set reuse_spool 0
+    set mbox "teaparty.mbox"
+    
     for {set i 0} {$i < [llength $args]} {incr i} {
 	set a [lindex $args $i]
 	if {"$a" == "-reuse-spool"} {
 	    set reuse_spool 1
+	} elseif {"$a" == "-mbox"} {
+	    set mbox [lindex $args [expr $i + 1]]
+	    incr i
 	} else {
 	    break;
 	}
@@ -118,7 +123,7 @@ proc imap4d_start {args} {
 
     if {$reuse_spool == 0} {
 	mu_prepare_spools
-	mu_copy_file $MU_SPOOL_DIR/teaparty.mbox $MU_SPOOL_DIR/INBOX
+	mu_copy_file $MU_SPOOL_DIR/$mbox $MU_SPOOL_DIR/INBOX
     }
     return [default_imap4d_start [concat [lrange $args $i end]]]
 }
diff --git a/imap4d/util.c b/imap4d/util.c
index 065ce38..2b546f0 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -335,8 +335,40 @@ add2set (size_t ** set, int *n, unsigned long val)
   return 0;
 }
 
+static void
+adjust_tm (struct tm *tm, mu_timezone *tz, enum datetime_parse_mode flag)
+{
+  switch (flag)
+    {
+    case datetime_default:
+      break;
+    case datetime_date_only:
+      tm->tm_sec = 0;
+      tm->tm_min = 0;
+      tm->tm_hour = 0;
+#if HAVE_STRUCT_TM_TM_ISDST
+      tm->tm_isdst = 0;
+#endif
+#if HAVE_STRUCT_TM_TM_GMTOFF
+      tm->tm_gmtoff = 0;
+#endif
+      tz->utc_offset = 0;
+      tz->tz_name = NULL;
+      break;
+
+    case datetime_time_only:
+      tm->tm_mon = 0;
+      tm->tm_year = 0;
+      tm->tm_yday = 0;
+      tm->tm_wday = 0;
+      tm->tm_mday = 0;
+      break;
+    }
+}
+  
 int
-util_parse_internal_date (char *date, time_t * timep)
+util_parse_internal_date (char *date, time_t *timep,
+			  enum datetime_parse_mode flag)
 {
   struct tm tm;
   mu_timezone tz;
@@ -346,6 +378,8 @@ util_parse_internal_date (char *date, time_t * timep)
   if (mu_parse_imap_date_time ((const char **) datep, &tm, &tz))
     return 1;
 
+  adjust_tm (&tm, &tz, flag);
+  
   time = mu_tm2time (&tm, &tz);
   if (time == (time_t) - 1)
     return 2;
@@ -355,7 +389,8 @@ util_parse_internal_date (char *date, time_t * timep)
 }
 
 int
-util_parse_822_date (const char *date, time_t * timep)
+util_parse_822_date (const char *date, time_t *timep,
+		     enum datetime_parse_mode flag)
 {
   struct tm tm;
   mu_timezone tz;
@@ -363,6 +398,7 @@ util_parse_822_date (const char *date, time_t * timep)
 
   if (mu_parse822_date_time (&p, date + strlen (date), &tm, &tz) == 0)
     {
+      adjust_tm (&tm, &tz, flag);
       *timep = mu_tm2time (&tm, &tz);
       return 0;
     }
@@ -370,13 +406,15 @@ util_parse_822_date (const char *date, time_t * timep)
 }
 
 int
-util_parse_ctime_date (const char *date, time_t * timep)
+util_parse_ctime_date (const char *date, time_t *timep,
+		       enum datetime_parse_mode flag)
 {
   struct tm tm;
   mu_timezone tz;
 
   if (mu_parse_ctime_date_time (&date, &tm, &tz) == 0)
     {
+      adjust_tm (&tm, &tz, flag);
       *timep = mu_tm2time (&tm, &tz);
       return 0;
     }
diff --git a/libmailutils/base/date.c b/libmailutils/base/date.c
index 1ca1140..e1e03fb 100644
--- a/libmailutils/base/date.c
+++ b/libmailutils/base/date.c
@@ -182,7 +182,7 @@ mu_parse_imap_date_time (const char **p, struct tm *tm, mu_timezone *tz)
 
 /* "ctime" format is: Thu Jul 01 15:58:27 1999, with no trailing \n.  */
 int
-mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
+mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone *tz)
 {
   int wday = 0;
   int year = 0;
@@ -236,9 +236,12 @@ mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
 #endif
     }
 
-  /* ctime has no timezone information, set tz to UTC if they ask. */
+  /* ctime has no timezone information, set tz to local TZ if they ask. */
   if (tz)
-    memset (tz, 0, sizeof (struct mu_timezone));
-
+    {
+      tz->utc_offset = mu_utc_offset ();
+      tz->tz_name = NULL;
+    }
+  
   return 0;
 }
diff --git a/testsuite/lib/mailutils.exp b/testsuite/lib/mailutils.exp
index 3a18cbd..0042116 100644
--- a/testsuite/lib/mailutils.exp
+++ b/testsuite/lib/mailutils.exp
@@ -45,7 +45,7 @@ proc mu_copy_file {src dst} {
     set output [open $dst w]
     set arg "$"
     for {gets $input line} {![eof $input]} {gets $input line} {
-	puts $output [subst -nobackslashes $line]
+	puts $output [subst -nobackslashes -nocommands $line]
     }
     close $input
     close $output
diff --git a/testsuite/spool/DISTFILES b/testsuite/spool/DISTFILES
index ccb51c4..59bb01e 100644
--- a/testsuite/spool/DISTFILES
+++ b/testsuite/spool/DISTFILES
@@ -1,6 +1,7 @@
 bigto.mbox
 mbox1
 mbox
+search.mbox
 sieve.mbox
 relational.mbox
 teaparty.mbox
diff --git a/testsuite/spool/search.mbox b/testsuite/spool/search.mbox
new file mode 100644
index 0000000..dd4f238
--- /dev/null
+++ b/testsuite/spool/search.mbox
@@ -0,0 +1,113 @@
+From lexi@example.net Mon Jul 29 22:00:08 2002
+Received: (from lexi@example.com) 
+	by example.org id 3301
+	for editor@example.org; Mon, 29 Jul 2002 22:00:06 +0100
+Date: Mon, 29 Jul 2002 22:00:01 +0100
+From: Lexicographer <lexi@example.com>
+To: Editor <editor@example.org>
+Subject: Abasement
+Status: OR
+
+ABASEMENT, n.  A decent and customary mental attitude in the presence
+of wealth of power.  Peculiarly appropriate in an employee when
+addressing an employer.
+
+From correct@example.net Tue Jul 30 00:00:00 2002
+Received: (from correct@example.com) 
+	by example.org id 3302
+	for editor@example.org Tue, Jul 30 00:00:00 2002 +0100
+Date: Mon, 29 Jul 2002 22:00:02 +0100
+From: Corrector <correct@example.com>
+To: Editor <editor@example.org>
+Subject: Aboriginies
+Status: ORA
+
+ABORIGINIES, n.  Persons of little worth found cumbering the soil of a
+newly discovered country.  They soon cease to cumber; they fertilize.
+
+From lexi@example.net Tue Jul 30 12:00:10 2002
+Received: (from lexi@example.com) 
+	by example.org id 3303
+	for editor@example.org Tue, 30 Jul 2002 12:00:08 +0100
+Date: Tue, 30 Jul 2002 12:00:03 +0100
+From: Lexicographer <lexi@example.com>
+To: Editor <editor@example.org>
+Message-Id: "<200207291200.3303@example.org>"
+Subject: Abnormal
+Status: ORA
+
+ABNORMAL, adj.  Not conforming to standard.  In matters of thought and
+conduct, to be independent is to be abnormal, to be abnormal is to be
+detested.  Wherefore the lexicographer adviseth a striving toward the
+straiter [sic] resemblance of the Average Man than he hath to himself.
+Whoso attaineth thereto shall have peace, the prospect of death and
+the hope of Hell.
+
+From corrector@example.net Tue Jul 30 12:00:11 2002
+Received: (from correct@example.com) 
+	by example.org id 3304
+	for editor@example.org Tue, 30 Jul 2002 12:00:09 +0100
+Date: Tue, 30 Jul 2002 12:00:04 +0100
+From: Corrector <corrector@example.com>
+To: Editor <editor@example.org>
+Subject: Occident
+
+OCCIDENT, n.  The part of the world lying west (or east) of the
+Orient.  It is largely inhabited by Christians, a powerful subtribe of
+the Hypocrites, whose principal industries are murder and cheating,
+which they are pleased to call "war" and "commerce."  These, also, are
+the principal industries of the Orient.
+
+From lexi@example.net Wed Jul 31 02:00:12 2002
+Received: (from lexi@example.com) 
+	by example.org id 3305
+	for corrector@example.org Wed, 31 Jul 2002 02:00:10 +0100
+Date: Wed, 31 Jul 2002 02:00:05 +0100
+From: Lexicographer <lexi@example.com>
+To: Corrector <correct@example.org>
+Subject: Acquaintance
+
+ACQUAINTANCE, n.  A person whom we know well enough to borrow from,
+but not well enough to lend to.  A degree of friendship called slight
+when its object is poor or obscure, and intimate when he is rich or
+famous.
+
+From lexi@example.net Thu Aug 01 10:00:13 2002
+Received: (from lexi@example.com) 
+	by example.org id 3306
+	for editor@example.org Thu, 01 Aug 2002 10:00:11 +0100
+Date: Thu, 01 Aug 2002 22:00:06 +0100
+From: Lexicographer <lexi@example.com>
+To: Editor <editor@example.org>
+Cc: Corrector <correct@example.org>
+Subject: Alliance
+
+ALLIANCE, n.  In international politics, the union of two thieves who
+have their hands so deeply inserted in each other's pockets that they
+cannot separately plunder a third.
+
+From lexi@example.net Fri Aug 02 11:00:14 2002
+Received: (from lexi@example.com) 
+	by example.org id 3307
+	for editor@example.org Fri, 02 Aug 2002 11:00:12 +0100
+Date: Fri, 02 Aug 2002 11:00:07 +0100
+From: Lexicographer <lexi@example.com>
+To: Editor <editor+recheck@example.org>
+Subject: White
+
+WHITE, adj. and n.  Black.
+
+From correct@example.net Fri Aug 02 12:00:15 2002
+Received: (from correct@example.com) 
+	by example.org id 3308
+	for editor@example.org Fri, 02 Aug 2002 12:00:13 +0100
+Date: Fri, 02 Aug 2002 12:00:08 +0100
+From: Corrector <correct@example.com>
+To: Editor <editor@example.org>
+Subject: Telephone
+
+TELEPHONE, n.  An invention of the devil which abrogates some of the
+advantages of making a disagreeable person keep his distance.
+
+
+


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Oct 16 06:27:20 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RFNw8-0000um-UY
	for mharc-commit-mailutils@gnu.org; Sun, 16 Oct 2011 06:27:20 -0400
Received: from eggs.gnu.org ([140.186.70.92]:44611)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFNw5-0000ue-3p
	for commit-mailutils@gnu.org; Sun, 16 Oct 2011 06:27:19 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFNw1-0007wc-Dn
	for commit-mailutils@gnu.org; Sun, 16 Oct 2011 06:27:16 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:42273)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFNw1-0007wU-BI
	for commit-mailutils@gnu.org; Sun, 16 Oct 2011 06:27:13 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFNw0-0004Ge-9w
	for commit-mailutils@gnu.org; Sun, 16 Oct 2011 10:27:12 +0000
Date: Sun, 16 Oct 2011 10:27:12 +0000
Message-Id: <E1RFNw0-0004Ge-9w@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-394-g502c635
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 5e5b68fd028495f7076a576df26962bbdf51ac63
X-Git-Newrev: 502c63533d25a0144b65041f9a164b4090bea37b
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 16 Oct 2011 10:27: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=502c63533d25a0144b65041f9a164b4090bea37b

The branch, master has been updated
       via  502c63533d25a0144b65041f9a164b4090bea37b (commit)
       via  1e33c774caafff0816a346ba1f34b6c7352b6874 (commit)
       via  85032d0e724bcba34a61458c44034336e15b9cbe (commit)
      from  5e5b68fd028495f7076a576df26962bbdf51ac63 (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 502c63533d25a0144b65041f9a164b4090bea37b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Oct 16 12:32:10 2011 +0300

    Minor changes, proposed by Jordi Mallach.
    
    * scheme/sieve2scm.scmi: Tailor help output to meet help2man expectations.
    * libmu_scm/mailutils/Makefile.am (EXTRA_DIST): Remove generated
    file mailutils.scm.

commit 1e33c774caafff0816a346ba1f34b6c7352b6874
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Oct 16 12:01:50 2011 +0300

    mh: open mailboxes in read-only mode unless the requested operation mandates otherwise.
    
    * mh/mhn.c: Open mailbox in read-only mode.
    * mh/mhseq.c: Likewise.
    * mh/scan.c: Likewise.
    * mh/pick.c: If sequences are given, open mailbox for RW, otherwise
    open it for reading only.
    
    * testsuite/testsuite.inc (MUT_MBCHMOD): New macro.
    (MUT_MBCOPY): Take optional third argument - mailbox mode.
    * mh/tests/mhl.at: Make sure mailboxes are r/o.
    * mh/tests/mhn.at: Likewise.
    * mh/tests/mhseq.at: Likewise.
    * mh/tests/scan.at: Likewise.

commit 85032d0e724bcba34a61458c44034336e15b9cbe
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 6 11:44:06 2011 +0300

    Bugfixes.
    
    * libmailutils/base/amd.c (amd_open): Return error if the mailbox
    cannot be opened for the required access permissions.
    (amd_message_stream_open): Fix condition for
    determining r/w access.
    * mh/mh_list.c (eval_extras): Break the loop if mu_header_aget_field_name
    fails.

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

Summary of changes:
 libmailutils/base/amd.c         |    9 ++++++-
 libmu_scm/mailutils/Makefile.am |    2 +-
 mh/etc/components               |    2 -
 mh/etc/forwcomps                |    2 -
 mh/mh_list.c                    |    3 +-
 mh/mhn.c                        |    6 ++--
 mh/mhseq.c                      |    2 +-
 mh/pick.c                       |    3 +-
 mh/scan.c                       |    2 +-
 mh/tests/mhl.at                 |    6 ++--
 mh/tests/mhn.at                 |   39 +++++++++++++++++----------------
 mh/tests/mhseq.at               |   45 +++++++++++++++++++++++++++++---------
 mh/tests/scan.at                |   10 ++++----
 scheme/sieve2scm.scmi           |    3 +-
 testsuite/testsuite.inc         |   17 ++++++++++++--
 15 files changed, 94 insertions(+), 57 deletions(-)

diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index f73f740..a63651a 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -365,10 +365,15 @@ amd_open (mu_mailbox_t mailbox, int flags)
       else
 	return errno;
     }
-  
+    
   if (!S_ISDIR (st.st_mode))
     return EINVAL;
 
+  if (access (amd->name,
+	      (flags & (MU_STREAM_WRITE|MU_STREAM_APPEND)) ?
+	       W_OK : R_OK | X_OK))
+    return errno;
+
   if (mailbox->locker == NULL)
     mu_locker_create (&mailbox->locker, "/dev/null", 0);
   
@@ -1674,7 +1679,7 @@ amd_message_stream_open (struct _amd_message *mhm)
     }
   
   /* The message should be at least readable */
-  if (amd->mailbox->flags & (MU_STREAM_RDWR|MU_STREAM_WRITE|MU_STREAM_APPEND))
+  if (amd->mailbox->flags & (MU_STREAM_WRITE|MU_STREAM_APPEND))
     flags |= MU_STREAM_RDWR;
   else 
     flags |= MU_STREAM_READ;
diff --git a/libmu_scm/mailutils/Makefile.am b/libmu_scm/mailutils/Makefile.am
index 9e46149..aea9790 100644
--- a/libmu_scm/mailutils/Makefile.am
+++ b/libmu_scm/mailutils/Makefile.am
@@ -15,7 +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/>.
 
-EXTRA_DIST=mailutils.scm mailutils.scm.in
+EXTRA_DIST=mailutils.scm.in
 
 DISTCLEANFILES=\
  mailutils.scm
diff --git a/mh/etc/components b/mh/etc/components
index e754508..33d4728 100644
--- a/mh/etc/components
+++ b/mh/etc/components
@@ -1,5 +1,3 @@
-;; Default components file for GNU MH.
-;; Lines beginning with ; are ignored.  Rest of lines is copied verbatim.
 To: 
 cc: 
 Subject: 
diff --git a/mh/etc/forwcomps b/mh/etc/forwcomps
index 7926e6f..2669f04 100644
--- a/mh/etc/forwcomps
+++ b/mh/etc/forwcomps
@@ -1,5 +1,3 @@
-;; Default forward components file for GNU MH.
-;; Lines beginning with ; are ignored.  Rest of lines is copied verbatim.
 To:
 cc:
 Subject:
diff --git a/mh/mh_list.c b/mh/mh_list.c
index 3fbe0ab..ebedf41 100644
--- a/mh/mh_list.c
+++ b/mh/mh_list.c
@@ -755,7 +755,8 @@ eval_extras (struct eval_env *env)
   mu_header_get_field_count (hdr, &num);
   for (i = 1; i <= num; i++)
     {
-      mu_header_aget_field_name (hdr, i, &str);
+      if (mu_header_aget_field_name (hdr, i, &str))
+	break;
       if (want_header (env, str)
 	  && !header_is_printed (env, str))
 	{
diff --git a/mh/mhn.c b/mh/mhn.c
index a7652da..4882fc9 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -2322,12 +2322,12 @@ edit_forw (char *cmd, struct compose_env *env, mu_message_t *pmsg, int level)
 
   if (ws.ws_wordv[0][0] == '+')
     {
-      mbox = mh_open_folder (ws.ws_wordv[0], MU_STREAM_RDWR);
+      mbox = mh_open_folder (ws.ws_wordv[0], MU_STREAM_READ);
       i = 1;
     }
   else
     {
-      mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
+      mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
       i = 0;
     }
   
@@ -2970,7 +2970,7 @@ main (int argc, char **argv)
     }
   else
     {
-      mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
+      mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
       mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
     }
   
diff --git a/mh/mhseq.c b/mh/mhseq.c
index 4ec8e9a..1059c4a 100644
--- a/mh/mhseq.c
+++ b/mh/mhseq.c
@@ -80,7 +80,7 @@ main (int argc, char **argv)
 
   argc -= index;
   argv += index;
-  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
+  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
 
   mh_msgset_parse (mbox, &msgset, argc, argv, "cur");
   if (uid_option)
diff --git a/mh/pick.c b/mh/pick.c
index f9b1976..db7aa43 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -390,7 +390,8 @@ main (int argc, char **argv)
   if (pick_parse (lexlist))
     return 1;
 
-  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
+  mbox = mh_open_folder (mh_current_folder (),
+			 seq_list ? MU_STREAM_RDWR : MU_STREAM_READ);
 
   argc -= index;
   argv += index;
diff --git a/mh/scan.c b/mh/scan.c
index ccefb69..bee454d 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -179,7 +179,7 @@ main (int argc, char **argv)
       exit (1);
     }
 
-  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
+  mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
 
   argc -= index;
   argv += index;
diff --git a/mh/tests/mhl.at b/mh/tests/mhl.at
index 7debc1d..c136a66 100644
--- a/mh/tests/mhl.at
+++ b/mh/tests/mhl.at
@@ -17,7 +17,7 @@
 m4_pushdef([MH_KEYWORDS],[mhl])
 
 MH_CHECK([mhl],[mhl00],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox],[700])
 mhl -form mhl.format Mail/inbox/2
 ],
 [0],
@@ -35,7 +35,7 @@ I don't see any wine
 ]) 
 
 MH_CHECK([mhl repl],[mhl01 mhl.repl],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox],[700])
 mhl -form mhl.repl Mail/inbox/15
 ],
 [0],
@@ -46,7 +46,7 @@ mhl -form mhl.repl Mail/inbox/15
 ])		  
 
 MH_CHECK([mhl usenet],[mhl02 mhl.usenet],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox],[700])
 mhl -form mhl.usenet Mail/inbox/15
 ],
 [0],
diff --git a/mh/tests/mhn.at b/mh/tests/mhn.at
index 3d0e4e0..95caed9 100644
--- a/mh/tests/mhn.at
+++ b/mh/tests/mhn.at
@@ -21,7 +21,7 @@ dnl 1. List mode
 dnl -------------------------------------------------------------------
 
 MH_CHECK([mhn -list],[mhn00 mhn-list],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhn +inbox -list all
 ],
 [0],
@@ -44,7 +44,7 @@ mhn +inbox -list all
 ])
 
 MH_CHECK([mhn -list -realsize],[mhn01 mhn-list-realsize],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhn +inbox -list -realsize all
 ],
 [0],
@@ -71,7 +71,7 @@ dnl 2. Store mode
 dnl -------------------------------------------------------------------
 
 MH_CHECK([mhn -store],[mhn02 mhn-store],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 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
@@ -139,7 +139,7 @@ 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])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhn +inbox -store -auto -part 2.2.1 4 | remove_curdir || exit $?
 ],
 [0],
@@ -150,6 +150,7 @@ 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhn +inbox -store -auto -part 2.1 4 || echo $?
 echo == 4.2.1.octet-stream ==
 cat 4.2.1.octet-stream
@@ -171,7 +172,7 @@ 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
-chmod +w Mail/inbox/4
+MUT_MBCHMOD(Mail/inbox, 700)
 
 mkdir out
 echo "mhn-storage: $curdir/out" >> $MH
@@ -188,7 +189,7 @@ 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
-chmod +w Mail/inbox/4
+MUT_MBCHMOD(Mail/inbox, 700)
 
 echo "mhn-store-application: %%-%m%P.%s-%p" >> $MH
 mhn +inbox -store 4 | remove_curdir || exit $?
@@ -208,7 +209,7 @@ 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
-chmod +w Mail/inbox/4
+MUT_MBCHMOD(Mail/inbox, 700)
 
 echo "mhn-store-application: $curdir/out/%m%P.%s" >> $MH
 mhn +inbox -store 4 | remove_curdir || exit $?
@@ -224,7 +225,7 @@ 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
-chmod +w Mail/inbox/4
+MUT_MBCHMOD(Mail, 700)
 
 echo "mhn-store-application: +app" >> $MH
 mhn +inbox -store 4 | remove_curdir || exit $?
@@ -239,7 +240,7 @@ 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
-chmod +w Mail/inbox/4
+MUT_MBCHMOD(Mail/inbox, 700)
 
 echo "Current-Folder: inbox" > Mail/context
 cat >> $MH <<EOT
@@ -251,15 +252,15 @@ mhn +inbox -store -part 2.2.1 4 | remove_curdir || exit $?
 [storing message 4 part 2.2.1 to folder inbox as message 5
 ])
 
-MH_CHECK([mhn-store-: pipe],[mhn11 mhn-store-pipe],[[
+MH_CHECK([mhn-store-: pipe],[mhn11 mhn-store-pipe],[
 mkdir Mail/inbox
 cp $abs_top_srcdir/testsuite/mh/mbox1/4 Mail/inbox
-chmod +w Mail/inbox/4
+MUT_MBCHMOD(Mail/inbox, 700)
 
 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|$abs_top_srcdir/mh/tests/||;s|(cd \(.*\)\;|(cd home\;|;s|  *$||" || exit $?
-]],
+],
 [0],
 [-- Editor invocation: -
 -- Input file:
@@ -281,7 +282,7 @@ dnl -------------------------------------------------------------------
 dnl 3. Show mode
 dnl -------------------------------------------------------------------
 MH_CHECK([mhn-show msg1],[mhn12 mhn-show-msg1],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhn -show 1 | sed /^X-IMAPbase/d
 ],
 [0],
@@ -332,7 +333,7 @@ And the mome raths outgrabe.
 ])
 
 MH_CHECK([mhn-show type=tar],[mhn13 mhn-show-type=tar],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 AT_DATA([filter.awk],[
 /^X-IMAPbase/ { next }
 /^-rw-r--r--/ { print $1, $2, $3, $6; next }
@@ -360,7 +361,7 @@ Initial text.
 # FIXME: What about exit code?
 # FIXME: See comment about the error message, near mhn.c:792
 MH_CHECK([mhn-show unsupported type],[mhn14 mhn-show-unsupported-type],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 mhn -show 1 | sed /^X-IMAPbase/d
 ],
 [0],
@@ -382,7 +383,7 @@ Initial text.
 
 MH_CHECK([mhn-show- variable (with subtype)],
 [mhn15 mhn-show-with-subtype],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 echo "mhn-show-application/x-tar: %ltar tvf '%F'" >> $MH
 AT_DATA([filter.awk],[
 /^X-IMAPbase/ { next }
@@ -411,7 +412,7 @@ part     2 application/x-tar        13835
 
 MH_CHECK([mhn-show- variable (without subtype)],
 [mhn16 mhn-show-without-subtype],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 echo "mhn-show-application: %ltar tvf '%F'" >> $MH
 AT_DATA([filter.awk],[
 /^X-IMAPbase/ { next }
@@ -821,7 +822,7 @@ Content-Description: Single line part
 
 MH_CHECK([mhn-compose: forward (single message)],
 [mhn23 mhn-compose mhn-compose-07],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 AT_DATA([input],
 [From: gray@example.net
 Subject: Forwards
@@ -925,7 +926,7 @@ Content-Type: application/octet-stream; type=tar; conversions=compress
 MH_CHECK([mhn-compose: multipart],
 [mhn25 mhn-compose mhn-compose-09],[
 
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail],[700])
 
 AT_DATA([foo.tar],
 [Not a tarball, really
diff --git a/mh/tests/mhseq.at b/mh/tests/mhseq.at
index f3f841d..8ca1596 100644
--- a/mh/tests/mhseq.at
+++ b/mh/tests/mhseq.at
@@ -19,7 +19,7 @@ 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])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq 1
 ],
 [0],
@@ -27,7 +27,7 @@ mhseq 1
 ])
 
 MH_CHECK([mhseq: not existing message number],[mhseq01],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq 100
 ],
 [1],
@@ -37,7 +37,7 @@ dnl FIXME: See FIXME 3 in mhpath.at
 ])
 
 MH_CHECK([mhseq: contiguous message range],[mhseq02],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq 2-5
 ],
 [0],
@@ -48,7 +48,7 @@ mhseq 2-5
 ])
 
 MH_CHECK([mhseq: reversed contiguous message range],[mhseq03],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq 5-2
 ],
 [0],
@@ -61,6 +61,7 @@ mhseq 5-2
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 5-2
 ],
 [0],
@@ -71,6 +72,7 @@ mhseq 5-2
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 1-5
 ],
 [0],
@@ -82,6 +84,7 @@ mhseq 1-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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 1-5
 ],
 [0],
@@ -93,6 +96,7 @@ mhseq 1-5
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 1-5
 ],
 [0],
@@ -104,6 +108,7 @@ mhseq 1-5
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 1-2
 ],
 [1],
@@ -112,7 +117,7 @@ mhseq 1-2
 ])
 
 MH_CHECK([mhseq: non-existent message range (right)],[mhseq09],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq 6-10
 ],
 [1],
@@ -121,7 +126,7 @@ mhseq 6-10
 ])
 
 MH_CHECK([mhseq: message set addition],[mhseq10],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox],[700])
 mhseq 5 8-10 15-20
 ],
 [0],
@@ -140,6 +145,7 @@ mhseq 5 8-10 15-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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 5 1-10 15-20
 ],
 [0],
@@ -160,7 +166,7 @@ mhseq 5 1-10 15-20
 ])
 
 MH_CHECK([mhseq: counted range (positive)],[mhseq12],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox],[700])
 mhseq 10:4
 ],
 [0],
@@ -173,6 +179,7 @@ mhseq 10:4
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 10:4
 ],
 [0],
@@ -185,6 +192,7 @@ mhseq 10:4
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 1:3
 ],
 [0],
@@ -194,7 +202,7 @@ mhseq 1:3
 ])
 
 MH_CHECK([mhseq: counted range (positive, right fixup)],[mhseq15],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq 2:10
 ],
 [0],
@@ -207,6 +215,7 @@ mhseq 2:10
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 10:2
 ],
 [1],
@@ -215,7 +224,7 @@ mhseq 10:2
 ])
 
 MH_CHECK([mhseq: counted range (negative)],[mhseq17],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/inbox],[700])
 mhseq 10:-4
 ],
 [0],
@@ -228,6 +237,7 @@ mhseq 10:-4
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 10:-4
 ],
 [0],
@@ -240,6 +250,7 @@ mhseq 10:-4
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 4:-30
 ],
 [0],
@@ -250,6 +261,7 @@ mhseq 4:-30
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 4:30
 ],
 [0],
@@ -260,6 +272,7 @@ mhseq 4:30
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq 1:-30
 ],
 [1],
@@ -270,6 +283,7 @@ mhseq 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq cur
 ],
 [0],
@@ -279,6 +293,7 @@ mhseq cur
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq cur:2
 ],
 [0],
@@ -289,6 +304,7 @@ mhseq cur:2
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq cur:-2
 ],
 [0],
@@ -299,6 +315,7 @@ mhseq cur:-2
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq cur:+2
 ],
 [0],
@@ -310,6 +327,7 @@ 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq next
 ],
 [0],
@@ -319,6 +337,7 @@ mhseq next
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq next:2
 ],
 [0],
@@ -330,6 +349,7 @@ 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq prev
 ],
 [0],
@@ -339,6 +359,7 @@ mhseq prev
 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
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq prev:2
 ],
 [0],
@@ -349,6 +370,7 @@ mhseq prev:2
 MH_CHECK([mhseq: first],[mhseq30 first],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 rm Mail/inbox/1
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq first
 ],
 [0],
@@ -358,6 +380,7 @@ mhseq first
 MH_CHECK([mhseq: first:n -- default direction],[mhseq31 first:n],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 rm Mail/inbox/1
+MUT_MBCHMOD(Mail/inbox, 700)
 mhseq first:2
 ],
 [0],
@@ -366,7 +389,7 @@ mhseq first:2
 ])
 
 MH_CHECK([mhseq: last],[mhseq32 last],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq last
 ],
 [0],
@@ -374,7 +397,7 @@ mhseq last
 ])
 
 MH_CHECK([mhseq: last:n -- default direction],[mhseq33 last:n],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 mhseq last:2
 ],
 [0],
diff --git a/mh/tests/scan.at b/mh/tests/scan.at
index 11dc2b4..a5aabff 100644
--- a/mh/tests/scan.at
+++ b/mh/tests/scan.at
@@ -17,7 +17,7 @@
 m4_pushdef([MH_KEYWORDS],[scan])
 
 MH_CHECK([scan],[scan00],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 echo "Current-Folder: inbox" > Mail/context
 scan | sed 's/ *$//'
 ],
@@ -30,7 +30,7 @@ scan | sed 's/ *$//'
 ])
 
 MH_CHECK([scan -folder],[scan01 scan-folder],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox],[700])
 scan +inbox | sed 's/ *$//'
 ],
 [0],
@@ -42,7 +42,7 @@ scan +inbox | sed 's/ *$//'
 ])
 
 MH_CHECK([scan -format],[scan02 scan-format],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail],[700])
 scan +mbox1 -format '%4(msg) %{from} - %{to}'
 ],
 [0],
@@ -54,7 +54,7 @@ scan +mbox1 -format '%4(msg) %{from} - %{to}'
 ])
 
 MH_CHECK([scan -form],[scan03 scan-form],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail],[700])
 echo '%4(msg) %(decode(friendly{from})) - %(decode(friendly{to}))' > formfile
 scan +mbox1 -form formfile
 ],
@@ -67,7 +67,7 @@ scan +mbox1 -form formfile
 ])
 
 MH_CHECK([scan -reverse],[scan04 scan-reverse],[
-MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail])
+MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail],[700])
 scan +mbox1 -reverse | sed 's/ *$//'
 ],
 [0],
diff --git a/scheme/sieve2scm.scmi b/scheme/sieve2scm.scmi
index 6d2c85d..87736cf 100644
--- a/scheme/sieve2scm.scmi
+++ b/scheme/sieve2scm.scmi
@@ -982,8 +982,7 @@ exec ${GUILE-guile} -l $0 -c '(mailutils-main)'\n")
 
 (define (sieve-usage)
   (display "usage: sieve2scm [OPTIONS][mailbox]\n")
-  (display "GNU sieve2scm -- compile a Sieve program into Scheme code\n")
-  (display "Options are:\n")
+  (display "GNU sieve2scm -- compile a Sieve program into Scheme code\n\n")
   (display "   -f, --file FILENAME      Set input file name\n")
   (display "   -o, --output FILENAME    Set output file name\n")
   (display "   -L, --lib-dir DIRNAME    Set sieve library directory name\n")
diff --git a/testsuite/testsuite.inc b/testsuite/testsuite.inc
index d4498f4..64407a0 100644
--- a/testsuite/testsuite.inc
+++ b/testsuite/testsuite.inc
@@ -45,17 +45,28 @@ AT_CLEANUP
 ])
 
 dnl ------------------------------------------------------------
-dnl MUT_MBCOPY(SRC, [DST = `.'])  -- Copy mailbox SRC to DST.
+dnl MUT_MBCHMOD(MBOX, MODE)
+dnl
+m4_define([MUT_MBCHMOD],[
+# First, set all modes to $2
+find $1 | xargs chmod $2
+# Then, remove executable bit from regular files
+find $1 -type f | xargs chmod -x
+])
+
+dnl ------------------------------------------------------------
+dnl MUT_MBCOPY(SRC, [DST = `.'], [mode])  -- 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)])
+m4_pushdef([__mode],[m4_if([$3],,[+w],[$3])])
 cp -r $1 __dst
 if test -e __dst/__basename; then
- chmod -R +w __dst/__basename
+ MUT_MBCHMOD(__dst/__basename, __mode)
 else
- chmod -R +w __dst
+ MUT_MBCHMOD(__dst, __mode)
 fi
 m4_popdef([__basename])
 m4_popdef([__dst])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 17 15:54:06 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RFtGA-0007Uu-GS
	for mharc-commit-mailutils@gnu.org; Mon, 17 Oct 2011 15:54:06 -0400
Received: from eggs.gnu.org ([140.186.70.92]:50144)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFtG6-0007UY-3q
	for commit-mailutils@gnu.org; Mon, 17 Oct 2011 15:54:04 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFtG3-00065o-1L
	for commit-mailutils@gnu.org; Mon, 17 Oct 2011 15:54:02 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:40634)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFtG2-00065g-QH
	for commit-mailutils@gnu.org; Mon, 17 Oct 2011 15:53:58 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RFtG1-0004HJ-Gq
	for commit-mailutils@gnu.org; Mon, 17 Oct 2011 19:53:58 +0000
Date: Mon, 17 Oct 2011 19:53:57 +0000
Message-Id: <E1RFtG1-0004HJ-Gq@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-395-gdfed0be
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 502c63533d25a0144b65041f9a164b4090bea37b
X-Git-Newrev: dfed0be6c0fb0541234422af700e955b77d09bd4
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 17 Oct 2011 19:54:04 -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=dfed0be6c0fb0541234422af700e955b77d09bd4

The branch, master has been updated
       via  dfed0be6c0fb0541234422af700e955b77d09bd4 (commit)
      from  502c63533d25a0144b65041f9a164b4090bea37b (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 dfed0be6c0fb0541234422af700e955b77d09bd4
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 17 09:37:10 2011 +0300

    Provide a mechanism for configurable file safety checking.
    
    Use it in maidag (.forward file safety) and in libmu_auth (TLS files).
    
    * include/mailutils/tls.h (mu_tls_module_config): New members
    for safety check flags.
    * include/mailutils/util.h (MU_FILE_SAFETY_NONE,MU_FILE_SAFETY_ALL)
    (MU_FILE_SAFETY_OWNER_MISMATCH)
    (MU_FILE_SAFETY_GROUP_WRITABLE,MU_FILE_SAFETY_WORLD_WRITABLE)
    (MU_FILE_SAFETY_GROUP_READABLE,MU_FILE_SAFETY_WORLD_READABLE)
    (MU_FILE_SAFETY_LINKED_WRDIR)
    (MU_FILE_SAFETY_DIR_IWGRP,MU_FILE_SAFETY_DIR_IWOTH): New constants.
    (mu_file_safety_check,mu_file_safety_name_to_code)
    (mu_file_safety_name_to_error): New protos.
    * libmailutils/base/checkperms.c: New file.
    * libmailutils/base/Makefile.am (libbase_la_SOURCES): Add checkperms.c.
    * libmailutils/diag/errors: Add new error codes.
    (MU_ERR_UNSAFE_PERMS): change description wording.
    * libmu_auth/tls.c (mu_check_tls_environment): Use mu_file_safety_check.
    * libmu_cfg/tls.c (tls_settings): Initialize.
    (mu_tls_param): New configuration file statements:
    key-file-safety-checks, cert-file-safety-checks, ca-file-safety-checks.
    * maidag/forward.c (maidag_forward): Use mu_file_safety_check.
    * maidag/maidag.c (cb2_forward_file_checks): Use
    mu_file_safety_name_to_code.

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

Summary of changes:
 include/mailutils/tls.h        |    6 +
 include/mailutils/util.h       |   29 +++++
 libmailutils/base/Makefile.am  |    1 +
 libmailutils/base/filesafety.c |  253 ++++++++++++++++++++++++++++++++++++++++
 libmailutils/diag/errors       |   14 ++-
 libmu_auth/tls.c               |   47 ++++----
 libmu_cfg/tls.c                |   86 ++++++++++++++-
 maidag/forward.c               |  168 +++------------------------
 maidag/maidag.c                |   45 +++----
 maidag/maidag.h                |    9 --
 10 files changed, 446 insertions(+), 212 deletions(-)
 create mode 100644 libmailutils/base/filesafety.c

diff --git a/include/mailutils/tls.h b/include/mailutils/tls.h
index abaa98e..6fdd49a 100644
--- a/include/mailutils/tls.h
+++ b/include/mailutils/tls.h
@@ -28,9 +28,15 @@ extern "C" {
 struct mu_tls_module_config
 {
   int enable;
+  
   char *ssl_cert;
+  int ssl_cert_safety_checks;
+
   char *ssl_key;
+  int ssl_key_safety_checks;
+  
   char *ssl_cafile;
+  int ssl_cafile_safety_checks;
 };
 
 extern int mu_tls_module_init (enum mu_gocs_op, void *);
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index 3ea257f..a1d4159 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -199,6 +199,35 @@ void mu_onexit_reset (void);
 /* Register the onexit function and associated data */
 int mu_onexit (mu_onexit_t func, void *data);
 
+#define MU_FILE_SAFETY_NONE           0x00
+#define MU_FILE_SAFETY_OWNER_MISMATCH 0x01
+#define MU_FILE_SAFETY_GROUP_WRITABLE 0x02
+#define MU_FILE_SAFETY_WORLD_WRITABLE 0x04
+#define MU_FILE_SAFETY_GROUP_READABLE 0x08
+#define MU_FILE_SAFETY_WORLD_READABLE 0x10  
+#define MU_FILE_SAFETY_LINKED_WRDIR   0x20 
+#define MU_FILE_SAFETY_DIR_IWGRP      0x40
+#define MU_FILE_SAFETY_DIR_IWOTH      0x80
+
+#define MU_FILE_SAFETY_ALL      (		\
+  MU_FILE_SAFETY_OWNER_MISMATCH |		\
+  MU_FILE_SAFETY_GROUP_WRITABLE |		\
+  MU_FILE_SAFETY_WORLD_WRITABLE |		\
+  MU_FILE_SAFETY_GROUP_READABLE |		\
+  MU_FILE_SAFETY_WORLD_READABLE |		\
+  MU_FILE_SAFETY_LINKED_WRDIR   |		\
+  MU_FILE_SAFETY_DIR_IWGRP      |		\
+  MU_FILE_SAFETY_DIR_IWOTH      )
+  
+
+struct mu_auth_data;
+
+int mu_file_safety_check (const char *filename, int mode,
+			  struct mu_auth_data *auth,
+			  mu_list_t idlist);
+int mu_file_safety_name_to_code (const char *name, int *pcode);
+int mu_file_safety_name_to_error (const char *name, int *pcode);  
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index 592eb7c..96ea2f8 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -24,6 +24,7 @@ libbase_la_SOURCES = \
  argcvjoin.c\
  argcvrem.c\
  assoc.c\
+ filesafety.c\
  daemon.c\
  date.c\
  fdwait.c\
diff --git a/libmailutils/base/filesafety.c b/libmailutils/base/filesafety.c
new file mode 100644
index 0000000..5bf2820
--- /dev/null
+++ b/libmailutils/base/filesafety.c
@@ -0,0 +1,253 @@
+/* File safety checks.
+   Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2010, 2011
+   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 <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/errno.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/list.h>
+#include <mailutils/util.h>
+
+/* Functions for checking mode of a file and the directory it resides in.
+   Each of these checks certain bits and returns 0 if they are OK
+   and non-0 otherwise. */
+
+struct file_check_buffer
+{
+  struct stat filst;
+  struct stat dirst;
+  int cdir;
+};
+
+static int
+_check_grdfil (struct file_check_buffer *fb)
+{
+  return fb->filst.st_mode & S_IRGRP;
+}
+
+static int
+_check_ardfil (struct file_check_buffer *fb)
+{
+  return fb->filst.st_mode & S_IROTH;
+}
+
+static int
+_check_gwrfil (struct file_check_buffer *fb)
+{
+  return fb->filst.st_mode & S_IWGRP;
+}
+
+static int
+_check_awrfil (struct file_check_buffer *fb)
+{
+  return fb->filst.st_mode & S_IWOTH;
+}
+
+static int
+_check_linkwrdir (struct file_check_buffer *fb)
+{
+  return (fb->filst.st_mode & S_IFLNK) &&
+         (fb->dirst.st_mode & (S_IWGRP | S_IWOTH));
+}
+
+static int
+_check_gwrdir (struct file_check_buffer *fb)
+{
+  return fb->dirst.st_mode & S_IWGRP;
+}
+
+static int
+_check_awrdir (struct file_check_buffer *fb)
+{
+  return fb->dirst.st_mode & S_IWOTH;
+}
+
+/* The table of permission checkers below has this type: */
+struct safety_checker
+{
+  char *name;            /* Symbolic name */
+  int flag;              /* MU_FILE_SAFETY_ flag that enables this entry */
+  int err;               /* Corresponding error code */
+  int cdir;              /* True if the function needs dirst member */
+  int (*fun) (struct file_check_buffer *fb); /* Checker function */
+};
+
+static struct safety_checker file_safety_check_tab[] = {
+  { "grdfil", MU_FILE_SAFETY_GROUP_READABLE, MU_ERR_PERM_GROUP_READABLE,
+    0, _check_grdfil },
+  { "ardfil", MU_FILE_SAFETY_WORLD_READABLE, MU_ERR_PERM_WORLD_READABLE,
+    0, _check_ardfil },
+  { "gwrfil", MU_FILE_SAFETY_GROUP_WRITABLE, MU_ERR_PERM_GROUP_WRITABLE,
+    0, _check_gwrfil },
+  { "awrfil", MU_FILE_SAFETY_WORLD_WRITABLE, MU_ERR_PERM_WORLD_WRITABLE,
+    0, _check_awrfil },
+  { "linkwrdir", MU_FILE_SAFETY_LINKED_WRDIR,   MU_ERR_PERM_LINKED_WRDIR,
+    1, _check_linkwrdir },
+  { "gwrdir", MU_FILE_SAFETY_DIR_IWGRP,      MU_ERR_PERM_DIR_IWGRP,
+    1, _check_gwrdir },
+  { "awrdir", MU_FILE_SAFETY_DIR_IWOTH,      MU_ERR_PERM_DIR_IWOTH,
+    1, _check_awrdir },
+  { 0 }
+};
+
+struct file_id
+{
+  dev_t dev;
+  ino_t inode;
+};
+
+static int
+file_id_cmp (const void *item, const void *data)
+{
+  const struct file_id *a = item;
+  const struct file_id *b = data;
+
+  if (a->dev != b->dev)
+    return 1;
+  if (a->inode != b->inode)
+    return 1;
+  return 0;
+}
+
+static int
+file_id_lookup (mu_list_t idlist, dev_t dev, ino_t ino)
+{
+  struct file_id id;
+
+  id.dev = dev;
+  id.inode = ino;
+  return mu_list_locate (idlist, &id, NULL);
+}
+
+static int
+file_id_remember (mu_list_t idlist, dev_t dev, ino_t ino)
+{
+  struct file_id *id = malloc (sizeof (*id));
+  if (!id)
+    {
+      mu_error ("%s", mu_strerror (errno));
+      return 1;
+    }
+  id->dev = dev;
+  id->inode = ino;
+  return mu_list_append (idlist, id);
+}
+
+static struct safety_checker *
+_find_safety_checker (const char *name)
+{
+  struct safety_checker *pck;
+  for (pck = file_safety_check_tab; pck->flag; pck++)
+    if (strcmp (pck->name, name) == 0)
+      return pck;
+  return NULL;
+}
+
+int
+mu_file_safety_name_to_code (const char *name, int *pcode)
+{
+  struct safety_checker *pck = _find_safety_checker (name);
+  if (pck)
+    {
+      *pcode = pck->flag;
+      return 0;
+    }
+  return MU_ERR_NOENT;
+}
+
+int
+mu_file_safety_name_to_error (const char *name, int *pcode)
+{
+  struct safety_checker *pck = _find_safety_checker (name);
+  if (pck)
+    {
+      *pcode = pck->err;
+      return 0;
+    }
+  return MU_ERR_NOENT;
+}
+
+int
+mu_file_safety_check (const char *filename, int mode,
+		      struct mu_auth_data *auth,
+		      mu_list_t idlist)
+{
+  struct file_check_buffer buf;
+  
+  memset (&buf, 0, sizeof (buf));
+  if (stat (filename, &buf.filst) == 0)
+    {
+      struct safety_checker *pck;
+
+      if (idlist)
+	{
+	  mu_list_set_destroy_item (idlist, mu_list_free_item);
+	  mu_list_set_comparator (idlist, file_id_cmp);
+	  if (file_id_lookup (idlist, buf.filst.st_dev, buf.filst.st_ino) == 0)
+	    return MU_ERR_EXISTS;
+	}
+
+      if ((mode & MU_FILE_SAFETY_OWNER_MISMATCH) &&
+	  auth &&
+	  auth->uid != buf.filst.st_uid)
+	return MU_ERR_PERM_OWNER_MISMATCH;
+
+      for (pck = file_safety_check_tab; pck->flag; pck++)
+	if (mode & pck->flag)
+	  {
+	    if (pck->cdir && !buf.cdir)
+	      {
+		char *dirname, *p;
+
+		p = strrchr (filename, '/');
+		if (!p)
+		  dirname = strdup (".");
+		else if (p == filename)
+		  dirname = strdup ("/");
+		else
+		  {
+		    size_t len = p - filename;
+		    dirname = malloc (len + 1);
+		    if (dirname)
+		      {
+			memcpy (dirname, filename, len);
+			dirname[len] = 0;
+		      }
+		  }
+		if (!dirname)
+		  return ENOMEM;
+		if (stat (dirname, &buf.dirst))
+		  return errno;
+		buf.cdir = 1;
+	      }
+	    if (pck->fun (&buf))
+	      return pck->err;
+	  }
+      if (idlist)
+	file_id_remember (idlist, buf.filst.st_dev, buf.filst.st_ino);
+      return 0;
+    }
+  return errno;
+}
diff --git a/libmailutils/diag/errors b/libmailutils/diag/errors
index 10bad5c..79fed33 100644
--- a/libmailutils/diag/errors
+++ b/libmailutils/diag/errors
@@ -65,7 +65,6 @@ MU_ERR_BADREPLY             _("Invalid reply from the remote host")
 MU_ERR_SEQ                  _("Bad command sequence")
 MU_ERR_REPLY                _("Erroneous reply received")
 
-MU_ERR_UNSAFE_PERMS         _("Unsafe file permissions. Set 0600")
 MU_ERR_BAD_AUTH_SCHEME      _("Unsupported authentication scheme")
 MU_ERR_AUTH_FAILURE         _("Authentication failed")
 
@@ -106,3 +105,16 @@ MU_ERR_BADFLAGS	            _("Bad value for flags")
 MU_ERR_SOCKTYPE             _("Socket type not supported")
 MU_ERR_FAMILY               _("Address family not supported")
 MU_ERR_SERVICE              _("Requested service not supported")
+
+# File safety check
+MU_ERR_PERM_OWNER_MISMATCH  _("File owner mismatch")
+MU_ERR_PERM_GROUP_WRITABLE  _("Group writable file")
+MU_ERR_PERM_WORLD_WRITABLE  _("World writable file")
+MU_ERR_PERM_GROUP_READABLE  _("Group readable file")
+MU_ERR_PERM_WORLD_READABLE  _("World readable file")
+MU_ERR_PERM_LINKED_WRDIR    _("Linked file in a writable directory")
+MU_ERR_PERM_DIR_IWGRP       _("File in group writable directory")
+MU_ERR_PERM_DIR_IWOTH       _("File in world writable directory")
+
+# A simpler version of the above.  Possibly will be removed in the future.
+MU_ERR_UNSAFE_PERMS         _("Unsafe file permissions")
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index ae3a9a5..d140cb7 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -33,8 +33,9 @@
 #include <mailutils/nls.h>
 #include <mailutils/stream.h>
 #include <mailutils/errno.h>
+#include <mailutils/util.h>
 
-struct mu_tls_module_config mu_tls_module_config = { 1, NULL, NULL, NULL };
+struct mu_tls_module_config mu_tls_module_config;
   
 int
 mu_tls_module_init (enum mu_gocs_op op, void *data)
@@ -65,44 +66,38 @@ mu_tls_module_init (enum mu_gocs_op op, void *data)
 static gnutls_dh_params dh_params;
 static gnutls_certificate_server_credentials x509_cred;
 
+/* Return: zero means NOT READY, one means READY */
 int
 mu_check_tls_environment (void)
 {
-  /* Return: zero means NOT READY, one means READY */
-
   if (mu_tls_module_config.ssl_cert && mu_tls_module_config.ssl_key)
     {
-      struct stat st;
-
-      if (stat (mu_tls_module_config.ssl_cert, &st) == -1)
+      int rc = mu_file_safety_check (mu_tls_module_config.ssl_cert,
+				     mu_tls_module_config.ssl_cert_safety_checks,
+				     NULL, NULL);
+      if (rc)
 	{
-	  mu_error ("%s: %s.", mu_tls_module_config.ssl_cert, 
-		    mu_strerror (errno));
+	  mu_error ("%s: %s", mu_tls_module_config.ssl_cert, 
+		    mu_strerror (rc));
 	  return 0;
 	}
-      if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK))
+      rc = mu_file_safety_check (mu_tls_module_config.ssl_key,
+				 mu_tls_module_config.ssl_key_safety_checks,
+				 NULL, NULL);
+      if (rc)
 	{
-	  mu_error (_("%s is not a regular file or a symbolic link."),
-		    mu_tls_module_config.ssl_cert);
+	  mu_error ("%s: %s", mu_tls_module_config.ssl_key, 
+		    mu_strerror (rc));
 	  return 0;
 	}
 
-      if (stat (mu_tls_module_config.ssl_key, &st) == -1)
-	{
-	  mu_error ("%s: %s.", mu_tls_module_config.ssl_key,
-		    mu_strerror(errno));
-	  return 0;
-	}
-      if (!(st.st_mode & S_IFREG) || !(st.st_mode & S_IFLNK))
-	{
-	  mu_error (_("%s is not a regular file or a symbolic link."),
-		    mu_tls_module_config.ssl_key);
-	  return 0;
-	}
-      if ((st.st_mode & S_IRWXG) || (st.st_mode & S_IRWXO))
+      rc = mu_file_safety_check (mu_tls_module_config.ssl_cafile,
+				 mu_tls_module_config.ssl_cafile_safety_checks,
+				 NULL, NULL);
+      if (rc)
 	{
-	  mu_error (_("wrong permissions on %s (set 0600)"),
-		    mu_tls_module_config.ssl_key);
+	  mu_error ("%s: %s", mu_tls_module_config.ssl_cafile, 
+		    mu_strerror (rc));
 	  return 0;
 	}
     }
diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
index cb5d8d4..d6f44fa 100644
--- a/libmu_cfg/tls.c
+++ b/libmu_cfg/tls.c
@@ -21,8 +21,65 @@
 #include <stdlib.h>
 #include "mailutils/libcfg.h"
 #include <mailutils/tls.h>
+#include <mailutils/util.h>
+#include <mailutils/kwd.h>
 
-static struct mu_tls_module_config tls_settings;
+static struct mu_tls_module_config tls_settings = {
+    1,                   /* enabled by default */
+
+    NULL,                /* Certificate file */
+    MU_FILE_SAFETY_GROUP_WRITABLE |
+     MU_FILE_SAFETY_GROUP_WRITABLE |
+     MU_FILE_SAFETY_LINKED_WRDIR,
+
+    NULL,               /* Key file */ 
+    MU_FILE_SAFETY_ALL, /* Stringent safety checks for keys */
+
+    NULL,               /* CA file */
+    MU_FILE_SAFETY_GROUP_WRITABLE |
+     MU_FILE_SAFETY_GROUP_WRITABLE |
+     MU_FILE_SAFETY_LINKED_WRDIR
+};
+
+
+static int
+cb2_safety_checks (const char *name, void *data)
+{
+  int negate = 0;
+  int val;
+  int *res = data;
+  
+  if (strcmp (name, "none") == 0)
+    {
+      *res = MU_FILE_SAFETY_NONE;
+      return 0;
+    }
+
+  if (*name == '-')
+    {
+      negate = 1;
+      name++;
+    }
+  else if (*name == '+')
+    name++;
+    
+  if (mu_file_safety_name_to_code (name, &val))
+    mu_error (_("unknown keyword: %s"), name);
+  else
+    {
+      if (negate)
+	*res &= ~val;
+      else
+	*res |= val;
+    }
+  return 0;
+}
+
+static int
+cb_safety_checks (void *data, mu_config_value_t *arg)
+{
+  return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
+}
 
 static struct mu_cfg_param mu_tls_param[] = {
   { "enable", mu_cfg_bool, &tls_settings.enable, 0, NULL,
@@ -36,6 +93,33 @@ static struct mu_cfg_param mu_tls_param[] = {
   { "ssl-cafile", mu_cfg_string, &tls_settings.ssl_cafile, 0, NULL,
     N_("Specify trusted CAs file."),
     N_("file") },
+  { "key-file-safety-checks", mu_cfg_callback,
+    &tls_settings.ssl_key_safety_checks, 0,
+    cb_safety_checks,
+    N_("Configure safety checks for SSL key file.  Argument is a list or "
+       "sequence of check names optionally prefixed with '+' to enable or "
+       "'-' to disable the corresponding check.  Valid check names are:\n"
+       "\n"
+       "  none          disable all checks\n"
+       "  all           enable all checks\n"
+       "  gwrfil        forbid group writable files\n"
+       "  awrfil        forbid world writable files\n"
+       "  grdfil        forbid group readable files\n"
+       "  ardfil        forbid world writable files\n"
+       "  linkwrdir     forbid symbolic links in group or world writable directories\n"
+       "  gwrdir        forbid files in group writable directories\n"
+       "  awrdir        forbid files in world writable directories\n"),
+    N_("arg: list") },  
+  { "cert-file-safety-checks", mu_cfg_callback,
+    &tls_settings.ssl_cert_safety_checks, 0,
+    cb_safety_checks,
+    N_("Configure safety checks for SSL certificate.  See above for a description of <arg>."),
+    N_("arg: list") },  
+  { "ca-file-safety-checks", mu_cfg_callback,
+    &tls_settings.ssl_cafile_safety_checks, 0,
+    cb_safety_checks,
+    N_("Configure safety checks for SSL certificate authority file.  See above for a description of <arg>."),
+    N_("arg: list") },  
   { NULL }
 }; 
 
diff --git a/maidag/forward.c b/maidag/forward.c
index 7846485..dd02164 100644
--- a/maidag/forward.c
+++ b/maidag/forward.c
@@ -19,154 +19,6 @@
 
 #include "maidag.h"
 
-/* Functions for checking file mode of .forward and its directory.
-   Each of these checks certain bits and returns 0 if they are OK
-   and non-0 otherwise. */
-
-static int
-check_iwgrp (struct stat *filest, struct stat *dirst)
-{
-  return filest->st_mode & S_IWGRP;
-}
-
-static int
-check_iwoth (struct stat *filest, struct stat *dirst)
-{
-  return filest->st_mode & S_IWOTH;
-}
-
-static int
-check_linked_wrdir (struct stat *filest, struct stat *dirst)
-{
-  return (filest->st_mode & S_IFLNK) && (dirst->st_mode & (S_IWGRP | S_IWOTH));
-}
-
-static int
-check_dir_iwgrp (struct stat *filest, struct stat *dirst)
-{
-  return dirst->st_mode & S_IWGRP;
-}
-
-static int
-check_dir_iwoth (struct stat *filest, struct stat *dirst)
-{
-  return dirst->st_mode & S_IWOTH;
-}
-
-/* The table of permission checkers below has this type: */
-struct perm_checker
-{
-  int flag;              /* FWD_ flag that enables this entry */
-  char *descr;           /* Textual description to use if FUN returns !0 */
-  int (*fun) (struct stat *filest, struct stat *dirst); /* Checker function */
-};
-
-static struct perm_checker perm_check_tab[] = {
-  { FWD_IWGRP, N_("group writable forward file"), check_iwgrp },
-  { FWD_IWOTH, N_("world writable forward file"), check_iwoth },
-  { FWD_LINK, N_("linked forward file in writable dir"), check_linked_wrdir },
-  { FWD_DIR_IWGRP, N_("forward file in group writable directory"),
-    check_dir_iwgrp },
-  { FWD_DIR_IWOTH, N_("forward file in world writable directory"),
-    check_dir_iwoth },
-  { 0 }
-};
-
-static mu_list_t idlist;
-
-struct file_id
-{
-  dev_t dev;
-  ino_t inode;
-};
-
-static int
-file_id_cmp (const void *item, const void *data)
-{
-  const struct file_id *a = item;
-  const struct file_id *b = data;
-
-  if (a->dev != b->dev)
-    return 1;
-  if (a->inode != b->inode)
-    return 1;
-  return 0;
-}
-
-static int
-file_id_lookup (dev_t dev, ino_t ino)
-{
-  struct file_id id;
-
-  id.dev = dev;
-  id.inode = ino;
-  return mu_list_locate (idlist, &id, NULL);
-}
-
-static int
-file_id_remember (dev_t dev, ino_t ino)
-{
-  struct file_id *id = malloc (sizeof (*id));
-  if (!id)
-    {
-      mu_error ("%s", mu_strerror (errno));
-      return 1;
-    }
-  id->dev = dev;
-  id->inode = ino;
-  return mu_list_append (idlist, id);
-}
-
-
-/* Check if the forwrd file FILENAME has right permissions and file mode.
-   DIRST describes the directory holding the file, AUTH gives current user
-   authority. */
-int
-check_forward_permissions (const char *filename, struct stat *dirst,
-			   struct mu_auth_data *auth)
-{
-  struct stat st;
-  
-  if (stat (filename, &st) == 0)
-    {
-      int i;
-
-      if (!idlist)
-	{
-	  mu_list_create (&idlist);
-	  mu_list_set_comparator (idlist, file_id_cmp);
-	}
-      else if (file_id_lookup (st.st_dev, st.st_ino) == 0)
-	{
-	  mu_diag_output (MU_DIAG_NOTICE,
-			  _("skipping forward file %s: already processed"),
-			  filename);
-	  return 1;
-	}
-      
-      if ((forward_file_checks & FWD_OWNER) &&
-	  auth->uid != st.st_uid)
-	{
-	  mu_error (_("%s not owned by %s"), filename, auth->name);
-	  return 1;
-	}
-      for (i = 0; perm_check_tab[i].flag; i++)
-	if ((forward_file_checks & perm_check_tab[i].flag)
-	    && perm_check_tab[i].fun (&st, dirst))
-	  {
-	    mu_error ("%s: %s", filename, gettext (perm_check_tab[i].descr));
-	    return 1;
-	  }
-      file_id_remember (st.st_dev, st.st_ino);
-      return 0;
-    }
-  else if (errno != ENOENT)
-    mu_error (_("%s: cannot stat file: %s"),
-	      filename, mu_strerror (errno));
-  return 1;
-}
-
-
 /* Auxiliary functions */
 
 /* Forward message MSG to given EMAIL, using MAILER and sender address FROM */
@@ -320,6 +172,9 @@ process_forward (mu_message_t msg, char *filename, const char *myname)
   return result;
 }
 
+
+static mu_list_t idlist;
+
 /* Check if the forward file FWFILE for user given by AUTH exists, and if
    so, use to to forward message MSG. */
 enum maidag_forward_result
@@ -328,7 +183,8 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile)
   struct stat st;
   char *filename;
   enum maidag_forward_result result = maidag_forward_none;
-
+  int rc;
+  
   if (fwfile[0] != '/')
     {
       if (stat (auth->dir, &st))
@@ -353,8 +209,20 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile)
       return maidag_forward_error;
     }
 
-  if (check_forward_permissions (filename, &st, auth) == 0)
+  if (!idlist)
+    mu_list_create (&idlist);
+
+  rc = mu_file_safety_check (filename, forward_file_checks,
+				  auth, idlist);
+  if (rc == 0)
     result = process_forward (msg, filename, auth->name);
+  else if (rc)
+    mu_diag_output (MU_DIAG_NOTICE,
+		    _("skipping forward file %s: already processed"),
+		    filename);
+  else
+    mu_error (_("ignoring forward file %s: %s"),
+	      filename, mu_strerror (rc));
   
   free (filename);
   return result;
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 9ea7c18..a9fe7ac 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -36,7 +36,14 @@ maidag_script_fun script_handler;
 mu_list_t script_list;
 
 char *forward_file = NULL;
-int forward_file_checks = FWD_ALL;
+#define FORWARD_FILE_PERM_CHECK (					\
+			   MU_FILE_SAFETY_OWNER_MISMATCH |	\
+			   MU_FILE_SAFETY_GROUP_WRITABLE |	\
+			   MU_FILE_SAFETY_WORLD_WRITABLE |	\
+			   MU_FILE_SAFETY_LINKED_WRDIR |		\
+			   MU_FILE_SAFETY_DIR_IWGRP |		\
+			   MU_FILE_SAFETY_DIR_IWOTH )
+int forward_file_checks = FORWARD_FILE_PERM_CHECK;
 
 /* Debuggig options */
 int debug_level;           /* General debugging level */ 
@@ -326,44 +333,32 @@ cb_group (void *data, mu_config_value_t *arg)
   return mu_cfg_string_value_cb (arg, cb2_group, *plist);
 }
 
-static struct mu_kwd forward_checks[] = {
-  { "all", FWD_ALL },
-  { "owner", FWD_OWNER },
-  { "groupwritablefile", FWD_IWGRP },
-  { "file_iwgrp", FWD_IWGRP },
-  { "worldwritablefile", FWD_IWOTH },
-  { "file_iwoth", FWD_IWOTH },
-  { "linkedfileinwritabledir", FWD_LINK },
-  { "link", FWD_LINK },
-  { "fileingroupwritabledir", FWD_DIR_IWGRP },
-  { "dir_iwgrp", FWD_DIR_IWGRP },
-  { "fileinworldwritabledir", FWD_DIR_IWOTH },
-  { "dir_iwoth", FWD_DIR_IWOTH },
-  { NULL }
-};
-
 static int
 cb2_forward_file_checks (const char *name, void *data)
 {
-  int negate = 0;
-  const char *str;
   int val;
-
+  int negate = 0;
+  
+  if (strcmp (name, "all") == 0)
+    {
+      forward_file_checks = FORWARD_FILE_PERM_CHECK;
+      return 0;
+    }
   if (strcmp (name, "none") == 0)
     {
       forward_file_checks = 0;
       return 0;
     }
   
-  if (strlen (name) > 2 && mu_c_strncasecmp (name, "no", 2) == 0)
+  if (*name == '-')
     {
       negate = 1;
-      str = name + 2;
+      name++;
     }
-  else
-    str = name;
+  else if (*name == '+')
+    name++;
 
-  if (mu_kwd_xlat_name_ci (forward_checks, str, &val))
+  if (mu_file_safety_name_to_code (name, &val))
     mu_error (_("unknown keyword: %s"), name);
   else
     {
diff --git a/maidag/maidag.h b/maidag/maidag.h
index 75bafc2..2be3818 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -109,15 +109,6 @@ extern int debug_level;
 #define MAXFD 64
 #define EX_QUOTA() (ex_quota_tempfail ? EX_TEMPFAIL : EX_UNAVAILABLE)
 
-/* .forward file checks */
-#define FWD_OWNER     0x0001 /* file ownership */
-#define FWD_IWGRP     0x0002 /* group writable forward file */
-#define FWD_IWOTH     0x0004 /* world writable forward file */
-#define FWD_LINK      0x0008 /* linked forward file in writable dir */
-#define FWD_DIR_IWGRP 0x0010 /* forward file in group writable directory */
-#define FWD_DIR_IWOTH 0x0020 /* forward file in world writable directory */
-#define FWD_ALL (FWD_OWNER|FWD_IWGRP|FWD_IWOTH|FWD_LINK|FWD_DIR_IWOTH|FWD_DIR_IWGRP)
-
 enum maidag_mode
   {
     mode_mda,


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Oct 18 07:57:00 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RG8I0-0004Fa-6u
	for mharc-commit-mailutils@gnu.org; Tue, 18 Oct 2011 07:57:00 -0400
Received: from eggs.gnu.org ([140.186.70.92]:47241)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RG8Hu-0004FD-JI
	for commit-mailutils@gnu.org; Tue, 18 Oct 2011 07:56:58 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RG8Hs-0003Ra-Gg
	for commit-mailutils@gnu.org; Tue, 18 Oct 2011 07:56:54 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:55134)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RG8Hs-0003RT-BY
	for commit-mailutils@gnu.org; Tue, 18 Oct 2011 07:56:52 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RG8Hr-0003dd-08
	for commit-mailutils@gnu.org; Tue, 18 Oct 2011 11:56:51 +0000
Date: Tue, 18 Oct 2011 11:56:51 +0000
Message-Id: <E1RG8Hr-0003dd-08@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-396-g7b85649
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: dfed0be6c0fb0541234422af700e955b77d09bd4
X-Git-Newrev: 7b85649a0f12a73bd8468c322d39811797ba315a
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 18 Oct 2011 11:56:58 -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=7b85649a0f12a73bd8468c322d39811797ba315a

The branch, master has been updated
       via  7b85649a0f12a73bd8468c322d39811797ba315a (commit)
      from  dfed0be6c0fb0541234422af700e955b77d09bd4 (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 7b85649a0f12a73bd8468c322d39811797ba315a
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Oct 18 14:55:16 2011 +0300

    File safety checks: Implement "default" keyword

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

Summary of changes:
 libmu_cfg/tls.c |   65 ++++++++++++++++++++++++++++++++++++------------------
 maidag/maidag.c |   33 ++++++++++++---------------
 2 files changed, 58 insertions(+), 40 deletions(-)

diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
index d6f44fa..d2ecf00 100644
--- a/libmu_cfg/tls.c
+++ b/libmu_cfg/tls.c
@@ -24,21 +24,27 @@
 #include <mailutils/util.h>
 #include <mailutils/kwd.h>
 
+#define SSL_CERT_FILE_CHECKS  (MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_LINKED_WRDIR)
+
+#define SSL_KEY_FILE_CHECKS   MU_FILE_SAFETY_ALL
+
+#define SSL_CA_FILE_CHECKS    (MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_LINKED_WRDIR)
+
 static struct mu_tls_module_config tls_settings = {
     1,                   /* enabled by default */
 
     NULL,                /* Certificate file */
-    MU_FILE_SAFETY_GROUP_WRITABLE |
-     MU_FILE_SAFETY_GROUP_WRITABLE |
-     MU_FILE_SAFETY_LINKED_WRDIR,
+    SSL_CERT_FILE_CHECKS,
 
-    NULL,               /* Key file */ 
-    MU_FILE_SAFETY_ALL, /* Stringent safety checks for keys */
+    NULL,                /* Key file */ 
+    SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
 
-    NULL,               /* CA file */
-    MU_FILE_SAFETY_GROUP_WRITABLE |
-     MU_FILE_SAFETY_GROUP_WRITABLE |
-     MU_FILE_SAFETY_LINKED_WRDIR
+    NULL,                /* CA file */
+    SSL_CA_FILE_CHECKS
 };
 
 
@@ -49,12 +55,6 @@ cb2_safety_checks (const char *name, void *data)
   int val;
   int *res = data;
   
-  if (strcmp (name, "none") == 0)
-    {
-      *res = MU_FILE_SAFETY_NONE;
-      return 0;
-    }
-
   if (*name == '-')
     {
       negate = 1;
@@ -62,16 +62,37 @@ cb2_safety_checks (const char *name, void *data)
     }
   else if (*name == '+')
     name++;
-    
-  if (mu_file_safety_name_to_code (name, &val))
-    mu_error (_("unknown keyword: %s"), name);
-  else
+
+  if (strcmp (name, "none") == 0)
+    val = MU_FILE_SAFETY_NONE;
+  else if (strcmp (name, "all") == 0)
+    val = MU_FILE_SAFETY_ALL;
+  else if (strcmp (name, "default") == 0)
     {
-      if (negate)
-	*res &= ~val;
+      if (data == &tls_settings.ssl_key)
+	val = SSL_KEY_FILE_CHECKS;
+      else if (data == &tls_settings.ssl_cert)
+	val = SSL_CERT_FILE_CHECKS;
+      else if (data == &tls_settings.ssl_cafile)
+	val = SSL_CA_FILE_CHECKS;
       else
-	*res |= val;
+	{
+	  mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
+		    __FILE__, __LINE__);
+	  val = MU_FILE_SAFETY_ALL;
+	}
+    }
+  else if (mu_file_safety_name_to_code (name, &val))
+    {
+      mu_error (_("unknown keyword: %s"), name);
+      return 0;
     }
+
+  if (negate)
+    *res &= ~val;
+  else
+    *res |= val;
+  
   return 0;
 }
 
diff --git a/maidag/maidag.c b/maidag/maidag.c
index a9fe7ac..6c6af88 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -339,17 +339,6 @@ cb2_forward_file_checks (const char *name, void *data)
   int val;
   int negate = 0;
   
-  if (strcmp (name, "all") == 0)
-    {
-      forward_file_checks = FORWARD_FILE_PERM_CHECK;
-      return 0;
-    }
-  if (strcmp (name, "none") == 0)
-    {
-      forward_file_checks = 0;
-      return 0;
-    }
-  
   if (*name == '-')
     {
       negate = 1;
@@ -358,15 +347,23 @@ cb2_forward_file_checks (const char *name, void *data)
   else if (*name == '+')
     name++;
 
-  if (mu_file_safety_name_to_code (name, &val))
-    mu_error (_("unknown keyword: %s"), name);
-  else
+  if (strcmp (name, "none") == 0)
+    forward_file_checks = MU_FILE_SAFETY_NONE;
+  else if (strcmp (name, "all") == 0)
+    forward_file_checks = MU_FILE_SAFETY_ALL;
+  else if (strcmp (name, "default") == 0)
+    forward_file_checks = FORWARD_FILE_PERM_CHECK;
+  else if (mu_file_safety_name_to_code (name, &val))
     {
-      if (negate)
-	forward_file_checks &= ~val;
-      else
-	forward_file_checks |= val;
+      mu_error (_("unknown keyword: %s"), name);
+      return 0;
     }
+
+  if (negate)
+    forward_file_checks &= ~val;
+  else
+    forward_file_checks |= val;
+
   return 0;
 }
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Oct 20 10:08:39 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RGtIV-0000pz-JA
	for mharc-commit-mailutils@gnu.org; Thu, 20 Oct 2011 10:08:39 -0400
Received: from eggs.gnu.org ([140.186.70.92]:40513)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RGtIL-0000nB-RF
	for commit-mailutils@gnu.org; Thu, 20 Oct 2011 10:08:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RGtIF-0003op-Jm
	for commit-mailutils@gnu.org; Thu, 20 Oct 2011 10:08:29 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:39616)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RGtIF-0003oB-HQ
	for commit-mailutils@gnu.org; Thu, 20 Oct 2011 10:08:23 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RGtIE-0000Ps-Pa
	for commit-mailutils@gnu.org; Thu, 20 Oct 2011 14:08:23 +0000
Date: Thu, 20 Oct 2011 14:08:22 +0000
Message-Id: <E1RGtIE-0000Ps-Pa@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-398-gfa3be4b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 7b85649a0f12a73bd8468c322d39811797ba315a
X-Git-Newrev: fa3be4baf0edf9c9df06ca272a19fae88c71d88b
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 20 Oct 2011 14:08: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=fa3be4baf0edf9c9df06ca272a19fae88c71d88b

The branch, master has been updated
       via  fa3be4baf0edf9c9df06ca272a19fae88c71d88b (commit)
       via  f697923aaf4a171efe5a074fc064edf415d6643f (commit)
      from  7b85649a0f12a73bd8468c322d39811797ba315a (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 fa3be4baf0edf9c9df06ca272a19fae88c71d88b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 20 16:16:02 2011 +0300

    Change attribute handling in Maildir format.
    
    * include/mailutils/message.h (MU_MSG_ATTRIBUTE_MODIFIED)
    (MU_MSG_HEADER_MODIFIED,MU_MSG_BODY_MODIFIED): New flags.
    * libmailutils/mailbox/message.c (mu_message_is_modified): Return
    a bitmask from the above values.
    * libmailutils/property/create.c (mu_property_create_init): Return
    error code.
    
    * include/mailutils/sys/amd.h (_amd_data) <chattr_msg>
    <capabilities, prop>: New members.
    <uidvalidity>: Remove.
    * libmailutils/base/amd.c: Use MH-style proplist to keep
    the mailbox properties: uidvalidity, last uid and to
    cache its size.
    Store message attributes in the message header only if the
    mailbox implementation is unable to keep them elsewhere.
    Use chattr_msg method (if provided) to flush changes in
    message attributes.
    
    * libproto/maildir/folder.c (_maildir_list_p): Ignore .mh* and .mu* files.
    * libproto/mh/folder.c (_mh_list_p): Likewise.
    * libproto/maildir/mbox.c: Implement all Maildir flags (except P).
    Implement the chattr_msg method.
    * libproto/mh/mbox.c: Remove special handling for uidvalidity.
    * mh/tests/folder.at: Ignore .mu-prop in directory listings.

commit f697923aaf4a171efe5a074fc064edf415d6643f
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 20 15:35:06 2011 +0300

    Bugfix.
    
    * libmu_cfg/tls.c (cb2_safety_checks): Fix handling of "all" and "none".
    * maidag/maidag.c (cb2_forward_file_checks): Likewise.
    * maidag/forward.c (maidag_forward): Handle MU_ERR_EXISTS return properly.

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

Summary of changes:
 include/mailutils/message.h    |    5 +
 include/mailutils/sys/amd.h    |   19 ++-
 libmailutils/base/amd.c        |  433 +++++++++++++++++++++++++++-------------
 libmailutils/mailbox/message.c |   12 +-
 libmailutils/property/create.c |    2 +-
 libmu_cfg/tls.c                |   10 +-
 libproto/maildir/folder.c      |    3 +-
 libproto/maildir/mbox.c        |   66 +++++--
 libproto/mh/folder.c           |    8 +-
 libproto/mh/mbox.c             |   16 --
 maidag/forward.c               |    4 +-
 maidag/maidag.c                |   10 +-
 mh/tests/folder.at             |    4 +-
 13 files changed, 396 insertions(+), 196 deletions(-)

diff --git a/include/mailutils/message.h b/include/mailutils/message.h
index 605817c..79878ac 100644
--- a/include/mailutils/message.h
+++ b/include/mailutils/message.h
@@ -53,6 +53,11 @@ extern void mu_message_destroy (mu_message_t *, void *owner);
 extern int mu_message_create_copy (mu_message_t *to, mu_message_t from);
 
 extern void *mu_message_get_owner (mu_message_t);
+
+#define MU_MSG_ATTRIBUTE_MODIFIED 0x01
+#define MU_MSG_HEADER_MODIFIED    0x02 
+#define MU_MSG_BODY_MODIFIED      0x04
+
 extern int mu_message_is_modified (mu_message_t);
 extern int mu_message_clear_modified (mu_message_t);
 extern int mu_message_get_mailbox (mu_message_t, mu_mailbox_t *);
diff --git a/include/mailutils/sys/amd.h b/include/mailutils/sys/amd.h
index 35c54c5..ce710d0 100644
--- a/include/mailutils/sys/amd.h
+++ b/include/mailutils/sys/amd.h
@@ -43,7 +43,13 @@
       mu_monitor_wrlock (mbox->monitor);				\
 } while (0);
 
-# define MU_AMD_SIZE_FILE_NAME ".mu-size"
+#define _MU_AMD_PROP_UIDVALIDITY "uid-validity"
+#define _MU_AMD_PROP_NEXT_UID "next-uid"
+#define _MU_AMD_PROP_SIZE "size"
+
+#define _MU_AMD_PROP_FILE_NAME ".mu-prop"
+/* Legacy (2.x) size file name */
+#define _MU_AMD_SIZE_FILE_NAME ".mu-size"
 
 struct _amd_data;
 struct _amd_message
@@ -64,6 +70,10 @@ struct _amd_message
   struct _amd_data *amd;    /* Back pointer.  */
 };
 
+/* AMD capabilities */
+#define MU_AMD_STATUS    0x01  /* format keeps status flags */
+#define MU_AMD_IMAPBASE  0x02  /* format keeps IMAP base */
+
 struct _amd_data
 {
   size_t msg_size;               /* Size of struct _amd_message */
@@ -83,16 +93,19 @@ struct _amd_data
   size_t (*next_uid) (struct _amd_data *mhd);
   int (*remove) (struct _amd_data *);
   int (*delete_msg) (struct _amd_data *, struct _amd_message *);
-		     
+  int (*chattr_msg) (struct _amd_message *, int);
+  
   /* List of messages: */
   size_t msg_count; /* number of messages in the list */
   size_t msg_max;   /* maximum message buffer capacity */
   struct _amd_message **msg_array;
 
-  unsigned long uidvalidity;
+  int capabilities;
   int has_new_msg;  /* New messages have been appended */
   char *name;                    /* Directory name */
 
+  mu_property_t prop; /* Properties: uidvalidity, nextuid, etc. */
+  
   /* Pool of open message streams */
   struct _amd_message *msg_pool[MAX_OPEN_STREAMS];
   int pool_first;    /* Index to the first used entry in msg_pool */
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index a63651a..a5685d9 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -129,7 +129,148 @@ struct _amd_body_stream
   mu_body_t body;
   mu_off_t off;
 };
+
+/* AMD Properties */
+int
+_amd_prop_fetch_off (struct _amd_data *amd, const char *name, mu_off_t *pval)
+{
+  const char *p;
+  mu_off_t n = 0;
+  
+  if (!amd->prop || mu_property_sget_value (amd->prop, name, &p))
+    return MU_ERR_NOENT;
+  if (!pval)
+    return 0;
+  for (; *p; p++)
+    {
+      if (!mu_isdigit (*p))
+	return EINVAL;
+      n = n * 10 + *p - '0';
+    }
+  *pval = n;
+  return 0;
+}
+
+int
+_amd_prop_fetch_size (struct _amd_data *amd, const char *name, size_t *pval)
+{
+  mu_off_t n;
+  int rc = _amd_prop_fetch_off (amd, name, &n);
+  if (rc == 0)
+    {
+      size_t s = n;
+      if (s != n)
+	return ERANGE;
+      if (pval)
+	*pval = s;
+    }
+  return rc;
+}
+
+int
+_amd_prop_fetch_ulong (struct _amd_data *amd, const char *name,
+		       unsigned long *pval)
+{
+  mu_off_t n;
+  int rc = _amd_prop_fetch_off (amd, name, &n);
+  if (rc == 0)
+    {
+      unsigned long s = n;
+      if (s != n)
+	return ERANGE;
+      if (pval)
+	*pval = s;
+    }
+  return rc;
+}
 
+int
+_amd_prop_store_off (struct _amd_data *amd, const char *name, mu_off_t val)
+{
+  char nbuf[128];
+  char *p;
+  int sign = 0;
+  
+  p = nbuf + sizeof nbuf;
+  *--p = 0;
+  if (val < 0)
+    {
+      sign = 1;
+      val = - val;
+    }
+  do
+    {
+      unsigned d = val % 10;
+      if (p == nbuf)
+	return ERANGE;
+      *--p = d + '0';
+      val /= 10;
+    }
+  while (val);
+  if (sign)
+    {
+      if (p == nbuf)
+	return ERANGE;
+      *--p = '-';
+    }
+  return mu_property_set_value (amd->prop, name, p, 1);
+}
+
+/* Backward-compatible size file support */
+static int
+read_size_file (struct _amd_data *amd)
+{
+  FILE *fp;
+  int rc;
+  char *name = mu_make_file_name (amd->name, _MU_AMD_SIZE_FILE_NAME);
+  if (!name)
+    return 1;
+  fp = fopen (name, "r");
+  if (fp)
+    {
+      unsigned long size;
+      if (fscanf (fp, "%lu", &size) == 1)
+	{
+	  rc = _amd_prop_store_off (amd, _MU_AMD_PROP_SIZE, size);
+	}
+      else
+	rc = 1;
+      fclose (fp);
+      unlink (name);
+    }
+  else
+    rc = 1;
+  free (name);
+  return rc;
+}
+
+static int
+_amd_prop_create (struct _amd_data *amd)
+{
+  int rc;
+  struct mu_mh_prop *mhprop;
+  mhprop = calloc (1, sizeof (mhprop[0]));
+  if (!mhprop)
+    return ENOMEM;
+  mhprop->filename = mu_make_file_name (amd->name, _MU_AMD_PROP_FILE_NAME);
+  if (!mhprop->filename)
+    {
+      free (mhprop);
+      return errno;
+    }
+  rc = mu_property_create_init (&amd->prop, mu_mh_property_init, mhprop);
+  if (rc)
+    {
+      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		("mu_property_create_init: %s",
+		 mu_strerror (rc)));
+      free (mhprop->filename);
+      free (mhprop);
+    }
+  else
+    read_size_file (amd);
+  return rc;
+}
 
 /* Operations on message array */
 
@@ -246,8 +387,8 @@ amd_array_expand (struct _amd_data *amd, size_t index)
   return 0;
 }
 
-/* Shrink the message array by removing element at INDEX-COUNT and
-   shifting left by COUNT positions all the elements on the right of
+/* Shrink the message array by removing the element at INDEX-COUNT and
+   shifting left by COUNT positions all the elements to the right of
    it. */
 int
 amd_array_shrink (struct _amd_data *amd, size_t index, size_t count)
@@ -273,7 +414,7 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size,
     return EINVAL;
 
   amd = mailbox->data = calloc (1, amd_size);
-  if (mailbox->data == NULL)
+  if (amd == NULL)
     return ENOMEM;
 
   /* Back pointer.  */
@@ -333,7 +474,9 @@ amd_destroy (mu_mailbox_t mailbox)
       free (amd->msg_array[i]);
     }
   free (amd->msg_array);
-	
+
+  mu_property_destroy (&amd->prop);
+  
   if (amd->name)
     free (amd->name);
 
@@ -374,6 +517,9 @@ amd_open (mu_mailbox_t mailbox, int flags)
 	       W_OK : R_OK | X_OK))
     return errno;
 
+  /* Create/read properties.  It is not an error if this fails. */
+  _amd_prop_create (amd);
+  
   if (mailbox->locker == NULL)
     mu_locker_create (&mailbox->locker, "/dev/null", 0);
   
@@ -405,7 +551,6 @@ amd_close (mu_mailbox_t mailbox)
   amd->msg_count = 0; /* number of messages in the list */
   amd->msg_max = 0;   /* maximum message buffer capacity */
 
-  amd->uidvalidity = 0;
   mu_monitor_unlock (mailbox->monitor);
   
   return 0;
@@ -547,6 +692,27 @@ _amd_attach_message (mu_mailbox_t mailbox, struct _amd_message *mhm,
 }
 
 static int
+_amd_scan0 (struct _amd_data *amd, size_t msgno, size_t *pcount,
+	    int do_notify)
+{
+  int status = amd->scan0 (amd->mailbox, msgno, pcount, do_notify);
+  if (status != 0)
+    return status;
+  /* Reset the uidvalidity.  */
+  if (amd->msg_count > 0)
+    {
+      unsigned long uidval;
+      if (_amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY, &uidval) ||
+	  !uidval)
+	{
+	  uidval = (unsigned long)time (NULL);
+	  _amd_prop_store_off (amd, _MU_AMD_PROP_UIDVALIDITY, uidval);
+	}
+    }
+  return 0;
+}
+
+static int
 amd_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
 {
   int status;
@@ -562,7 +728,7 @@ amd_get_message (mu_mailbox_t mailbox, size_t msgno, mu_message_t *pmsg)
   /* If we did not start a scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
+      status = _amd_scan0 (amd, 1, NULL, 0);
       if (status != 0)
 	return status;
     }
@@ -647,7 +813,6 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
   mu_body_t body;
   const char *sbuf;
   mu_envelope_t env = NULL;
-  char statbuf[MU_STATUS_BUF_SIZE];
 
   status = mu_message_size (msg, &bsize);
   if (status)
@@ -724,17 +889,6 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
     }
   mu_stream_destroy (&stream);
   
-  /* Add imapbase */
-  if (!(amd->mailbox->flags & MU_STREAM_APPEND)
-      && amd->next_uid
-      && (!amd->msg_array || (amd->msg_array[0] == mhm))) /*FIXME*/
-    {
-      nbytes += fprintf (fp, "X-IMAPbase: %lu %u\n",
-			 (unsigned long) amd->uidvalidity,
-			 (unsigned) amd->next_uid (amd));
-      nlines++;
-    }
-  
   mu_message_get_envelope (msg, &env);
   if (mu_envelope_sget_date (env, &sbuf) == 0)
     {
@@ -754,15 +908,21 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
       fprintf (fp, "%s: %s\n", MU_HEADER_ENV_SENDER, sbuf);
       nlines++;
     }
-  
-  /* Add status */
-  mu_message_get_attribute (msg, &attr);
-  mu_attribute_to_string (attr, statbuf, sizeof (statbuf), &n);
-  if (n)
+
+  if (!(amd->capabilities & MU_AMD_STATUS))
     {
-      nbytes += fprintf (fp, "Status: %s\n", statbuf);
-      nlines++;
+      /* Add status */
+      char statbuf[MU_STATUS_BUF_SIZE];
+      
+      mu_message_get_attribute (msg, &attr);
+      mu_attribute_to_string (attr, statbuf, sizeof (statbuf), &n);
+      if (n)
+	{
+	  nbytes += fprintf (fp, "Status: %s\n", statbuf);
+	  nlines++;
+	}
     }
+
   nbytes += fprintf (fp, "\n");
   nlines++;
   
@@ -858,7 +1018,7 @@ amd_append_message (mu_mailbox_t mailbox, mu_message_t msg)
   /* If we did not start a scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
+      status = _amd_scan0 (amd, 1, NULL, 0);
       if (status != 0)
 	{
 	  free (mhm);
@@ -923,7 +1083,7 @@ amd_messages_count (mu_mailbox_t mailbox, size_t *pcount)
     return EINVAL;
 
   if (!amd_is_updated (mailbox))
-    return amd->scan0 (mailbox,  amd->msg_count, pcount, 0);
+    return _amd_scan0 (amd,  amd->msg_count, pcount, 0);
 
   if (pcount)
     *pcount = amd->msg_count;
@@ -943,7 +1103,7 @@ amd_messages_recent (mu_mailbox_t mailbox, size_t *pcount)
   /* If we did not start a scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
-      int status = amd->scan0 (mailbox, 1, NULL, 0);
+      int status = _amd_scan0 (amd, 1, NULL, 0);
       if (status != 0)
 	return status;
     }
@@ -967,7 +1127,7 @@ amd_message_unseen (mu_mailbox_t mailbox, size_t *pmsgno)
   /* If we did not start a scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
-      int status = amd->scan0 (mailbox, 1, NULL, 0);
+      int status = _amd_scan0 (amd, 1, NULL, 0);
       if (status != 0)
 	return status;
     }
@@ -982,71 +1142,10 @@ amd_message_unseen (mu_mailbox_t mailbox, size_t *pmsgno)
     }
   return 0;
 }
-
-static char *
-make_size_file_name (struct _amd_data *amd)
-{
-  size_t size = strlen (amd->name) + 1 + sizeof (MU_AMD_SIZE_FILE_NAME);
-  char *name = malloc (size);
-  if (name)
-    {
-      strcpy (name, amd->name);
-      strcat (name, "/");
-      strcat (name, MU_AMD_SIZE_FILE_NAME);
-    }
-  return name;
-}
-
-static int
-read_size_file (struct _amd_data *amd, mu_off_t *psize)
-{
-  FILE *fp;
-  int rc;
-  char *name = make_size_file_name (amd);
-  if (!name)
-    return 1;
-  fp = fopen (name, "r");
-  if (fp)
-    {
-      unsigned long size;
-      if (fscanf (fp, "%lu", &size) == 1)
-	{
-	  *psize = size;
-	  rc = 0;
-	}
-      else
-	rc = 1;
-      fclose (fp);
-    }
-  else
-    rc = 1;
-  free (name);
-  return rc;
-}
-
-static int
-write_size_file (struct _amd_data *amd, mu_off_t size)
-{
-  FILE *fp;
-  int rc;
-  char *name = make_size_file_name (amd);
-  if (!name)
-    return 1;
-  fp = fopen (name, "w");
-  if (fp)
-    {
-      fprintf (fp, "%lu", (unsigned long) size);
-      fclose (fp);
-      rc = 0;
-    }
-  else
-    rc = 1;
-  free (name);
-  return rc;
-}
-      
+
 static int
-compute_mailbox_size (struct _amd_data *amd, const char *name, mu_off_t *psize)
+_compute_mailbox_size_recursive (struct _amd_data *amd, const char *name,
+				 mu_off_t *psize)
 {
   DIR *dir;
   struct dirent *entry;
@@ -1099,7 +1198,7 @@ compute_mailbox_size (struct _amd_data *amd, const char *name, mu_off_t *psize)
 	      if (S_ISREG (sb.st_mode))
 		*psize += sb.st_size;
 	      else if (S_ISDIR (sb.st_mode))
-		compute_mailbox_size (amd, buf, psize);
+		_compute_mailbox_size_recursive (amd, buf, psize);
 	    }
 	  /* FIXME: else? */
 	  break;
@@ -1113,6 +1212,20 @@ compute_mailbox_size (struct _amd_data *amd, const char *name, mu_off_t *psize)
 }
 
 static int
+compute_mailbox_size (struct _amd_data *amd, mu_off_t *psize)
+{
+  mu_off_t size = 0;
+  int rc = _compute_mailbox_size_recursive (amd, amd->name, &size);
+  if (rc == 0)
+    {
+      rc = _amd_prop_store_off (amd, _MU_AMD_PROP_SIZE, size);
+      if (rc == 0 && psize)
+	*psize = size;
+    }
+  return rc;
+}
+
+static int
 amd_remove_mbox (mu_mailbox_t mailbox)
 {
   int rc;
@@ -1123,11 +1236,22 @@ amd_remove_mbox (mu_mailbox_t mailbox)
   rc = amd->remove (amd);
   if (rc == 0)
     {
-      char *name = make_size_file_name (amd);
+      char *name;
+
+      name = mu_make_file_name (amd->name, _MU_AMD_SIZE_FILE_NAME);
       if (!name)
 	return ENOMEM;
       if (unlink (name) && errno != ENOENT)
 	rc = errno;
+      else
+	{
+	  free (name);
+	  name = mu_make_file_name (amd->name, _MU_AMD_PROP_FILE_NAME);
+	  if (!name)
+	    return ENOMEM;
+	  if (unlink (name) && errno != ENOENT)
+	    rc = errno;
+	}
       free (name);
     }
 
@@ -1147,6 +1271,55 @@ amd_remove_mbox (mu_mailbox_t mailbox)
 }
 
 static int
+_amd_update_message (struct _amd_data *amd, struct _amd_message *mhm,
+		     int expunge, int *upd)
+{
+  int flg, rc;
+      
+  if (mhm->message)
+    flg = mu_message_is_modified (mhm->message);
+  else if (mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
+    flg = MU_MSG_ATTRIBUTE_MODIFIED;
+
+  if (!flg)
+    return 0;
+
+  if (flg == MU_MSG_ATTRIBUTE_MODIFIED && amd->chattr_msg)
+    {
+      rc = amd->chattr_msg (mhm, expunge);
+      if (rc)
+	{
+	  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		    ("_amd_update_message: chattr_msg failed: %s",
+		     mu_strerror (rc)));
+	  return rc;
+	}
+    }
+  else
+    {
+      rc = _amd_attach_message (amd->mailbox, mhm, NULL);
+      if (rc)
+	{
+	  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		    ("_amd_update_message: _amd_attach_message failed: %s",
+		     mu_strerror (rc)));
+	  return rc;
+	}
+	  
+      rc = _amd_message_save (amd, mhm, expunge);
+      if (rc)
+	{
+	  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+		    ("_amd_update_message: _amd_message_save failed: %s",
+		     mu_strerror (rc)));
+	  return rc;
+	}
+    }
+  *upd = 1;
+  return rc;
+}
+
+static int
 amd_expunge (mu_mailbox_t mailbox)
 {
   struct _amd_data *amd = mailbox->data;
@@ -1232,13 +1405,7 @@ amd_expunge (mu_mailbox_t mailbox)
 	}
       else
 	{
-	  if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
-	      || (mhm->message && mu_message_is_modified (mhm->message)))
-	    {
-	      _amd_attach_message (mailbox, mhm, NULL);
-	      _amd_message_save (amd, mhm, 1);
-	      updated = 1;
-	    }
+	  _amd_update_message (amd, mhm, 1, &updated);/*FIXME: Error checking*/
 	}
     }
 
@@ -1263,10 +1430,7 @@ amd_expunge (mu_mailbox_t mailbox)
   
   if (updated && !amd->mailbox_size)
     {
-      mu_off_t size = 0;
-      int rc = compute_mailbox_size (amd, amd->name, &size);
-      if (rc == 0)
-	write_size_file (amd, size);
+      compute_mailbox_size (amd, NULL);
     }
   return 0;
 }
@@ -1297,22 +1461,12 @@ amd_sync (mu_mailbox_t mailbox)
   for ( ; i < amd->msg_count; i++)
     {
       mhm = amd->msg_array[i];
-
-      if ((mhm->attr_flags & MU_ATTRIBUTE_MODIFIED)
-	  || (mhm->message && mu_message_is_modified (mhm->message)))
-	{
-	  _amd_attach_message (mailbox, mhm, NULL);
-	  _amd_message_save (amd, mhm, 0);
-	  updated = 1;
-	}
+      _amd_update_message (amd, mhm, 0, &updated); 
     }
 
   if (updated && !amd->mailbox_size)
     {
-      mu_off_t size = 0;
-      int rc = compute_mailbox_size (amd, amd->name, &size);
-      if (rc == 0)
-	write_size_file (amd, size);
+      compute_mailbox_size (amd, NULL);
     }
 
   return 0;
@@ -1328,13 +1482,12 @@ amd_uidvalidity (mu_mailbox_t mailbox, unsigned long *puidvalidity)
   /* If we did not start a scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
+      status = _amd_scan0 (amd, 1, NULL, 0);
       if (status != 0)
 	return status;
     }
-  if (puidvalidity)
-    *puidvalidity = amd->uidvalidity;
-  return 0;
+
+  return _amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY, puidvalidity);
 }
 
 static int
@@ -1351,7 +1504,7 @@ amd_uidnext (mu_mailbox_t mailbox, size_t *puidnext)
   /* If we did not start a scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
-      status = amd->scan0 (mailbox, 1, NULL, 0);
+      status = _amd_scan0 (amd, 1, NULL, 0);
       if (status != 0)
 	return status;
     }
@@ -1458,7 +1611,9 @@ amd_scan_message (struct _amd_message *mhm)
   size_t body_start = 0;
   struct stat st;
   char *msg_name;
-
+  struct _amd_data *amd = mhm->amd;
+  int amd_capa = amd->capabilities;
+  
   /* Check if the message was modified after the last scan */
   status = mhm->amd->cur_msg_file_name (mhm, &msg_name);
   if (status)
@@ -1498,17 +1653,25 @@ amd_scan_message (struct _amd_message *mhm)
 		hlines++;
 	      
 	      /* Process particular attributes */
-	      if (mu_c_strncasecmp (buf, "status:", 7) == 0)
+	      if (!(amd_capa & MU_AMD_STATUS) &&
+		  mu_c_strncasecmp (buf, "status:", 7) == 0)
 		{
 		  int deleted = mhm->attr_flags & MU_ATTRIBUTE_DELETED;
 		  mu_string_to_flags (buf, &mhm->attr_flags);
 		  mhm->attr_flags |= deleted;
 		}
-	      else if (mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0)
+	      else if (!(amd_capa & MU_AMD_IMAPBASE) &&
+		       mu_c_strncasecmp (buf, "x-imapbase:", 11) == 0)
 		{
-		  char *p;
-		  mhm->amd->uidvalidity = strtoul (buf + 11, &p, 10);
-		  /* second number is next uid. Ignored */
+		  if (_amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY,
+					     NULL))
+		    {
+		      char *p;
+		      unsigned long uidval = strtoul (buf + 11, &p, 10);
+		      /* The next number is next uid. Ignored */
+		      _amd_prop_store_off (amd, _MU_AMD_PROP_UIDVALIDITY,
+					   uidval);
+		    }
 		}
 	    }
 	  else
@@ -1545,7 +1708,7 @@ amd_scan (mu_mailbox_t mailbox, size_t msgno, size_t *pcount)
   struct _amd_data *amd = mailbox->data;
 
   if (! amd_is_updated (mailbox))
-    return amd->scan0 (mailbox, msgno, pcount, 1);
+    return _amd_scan0 (amd, msgno, pcount, 1);
 
   if (pcount)
     *pcount = amd->msg_count;
@@ -1573,14 +1736,8 @@ amd_get_size (mu_mailbox_t mailbox, mu_off_t *psize)
   struct _amd_data *amd = mailbox->data;
   if (amd->mailbox_size)
     return amd->mailbox_size (mailbox, psize);
-  *psize = 0;
-  if (read_size_file (amd, psize))
-    {
-      int rc = compute_mailbox_size (amd, amd->name, psize);
-      if (rc == 0)
-	write_size_file (amd, *psize);
-      return rc;
-    }
+  if (_amd_prop_fetch_off (amd, _MU_AMD_PROP_SIZE, psize))
+    return compute_mailbox_size (amd, psize);
   return 0;
 }
 
diff --git a/libmailutils/mailbox/message.c b/libmailutils/mailbox/message.c
index 01835d6..8cf233a 100644
--- a/libmailutils/mailbox/message.c
+++ b/libmailutils/mailbox/message.c
@@ -667,10 +667,14 @@ mu_message_is_modified (mu_message_t msg)
   int mod = 0;
   if (msg)
     {
-      mod |= mu_header_is_modified (msg->header);
-      mod |= mu_attribute_is_modified (msg->attribute);
-      mod |= mu_body_is_modified (msg->body);
-      mod |= msg->flags;
+      if (mu_header_is_modified (msg->header))
+	mod |= MU_MSG_HEADER_MODIFIED;
+      if (mu_attribute_is_modified (msg->attribute))
+	mod |= MU_MSG_ATTRIBUTE_MODIFIED;
+      if (mu_body_is_modified (msg->body))
+	mod |= MU_MSG_BODY_MODIFIED;
+      if (msg->flags & MESSAGE_MODIFIED)
+	mod |= MU_MSG_BODY_MODIFIED | MU_MSG_HEADER_MODIFIED;
     }
   return mod;
 }
diff --git a/libmailutils/property/create.c b/libmailutils/property/create.c
index c9454ad..e91a5ab 100644
--- a/libmailutils/property/create.c
+++ b/libmailutils/property/create.c
@@ -45,7 +45,7 @@ mu_property_create_init (mu_property_t *pprop,
       mu_property_set_init (prop, initfun, initdata);
       *pprop = prop;
     }
-  return 0;
+  return rc;
 }
 
 int
diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
index d2ecf00..37afc10 100644
--- a/libmu_cfg/tls.c
+++ b/libmu_cfg/tls.c
@@ -64,9 +64,15 @@ cb2_safety_checks (const char *name, void *data)
     name++;
 
   if (strcmp (name, "none") == 0)
-    val = MU_FILE_SAFETY_NONE;
+    {
+      *res = negate ? MU_FILE_SAFETY_ALL : MU_FILE_SAFETY_NONE;
+      return 0;
+    }
   else if (strcmp (name, "all") == 0)
-    val = MU_FILE_SAFETY_ALL;
+    {
+      *res = negate ? MU_FILE_SAFETY_NONE : MU_FILE_SAFETY_ALL;
+      return 0;
+    }
   else if (strcmp (name, "default") == 0)
     {
       if (data == &tls_settings.ssl_key)
diff --git a/libproto/maildir/folder.c b/libproto/maildir/folder.c
index 5397315..bba6848 100644
--- a/libproto/maildir/folder.c
+++ b/libproto/maildir/folder.c
@@ -92,7 +92,8 @@ _maildir_list_p (mu_record_t record, const char *name, int flags MU_ARG_UNUSED)
   return strcmp (name, TMPSUF)
     && strcmp (name, CURSUF) 
     && strcmp (name, NEWSUF)
-    && strcmp (name, MU_AMD_SIZE_FILE_NAME);
+    && !((strlen (name) > 3) &&
+	 (memcmp (name, ".mh", 3) == 0 || memcmp (name, ".mu", 3) == 0));
 }
 
 static struct _mu_record _maildir_record =
diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c
index 90768e2..acf8f9b 100644
--- a/libproto/maildir/mbox.c
+++ b/libproto/maildir/mbox.c
@@ -84,19 +84,24 @@ struct _maildir_message
 
 
 /* Attribute handling.
-   FIXME: P (Passed), D (Draft) and F (Flagged) are not handled */
+   FIXME: P (Passed) is not handled */
 
 static struct info_map {
   char letter;
   int flag;
 } info_map[] = {
+  { 'D', MU_ATTRIBUTE_DRAFT },
+  { 'F', MU_ATTRIBUTE_FLAGGED },
+  { 'P', 0 }, /* (passed): the user has resent/forwarded/bounced this
+		 message to someone else. */
   { 'R', MU_ATTRIBUTE_READ },
   { 'S', MU_ATTRIBUTE_SEEN },
   { 'T', MU_ATTRIBUTE_DELETED },
+  { 'a', MU_ATTRIBUTE_ANSWERED },
 };
 #define info_map_size (sizeof (info_map) / sizeof (info_map[0]))
 
-/* NOTE: BUF must be at least 7 bytes long */
+/* NOTE: BUF must be at least info_map_size bytes long */
 static int
 flags_to_info (int flags, char *buf)
 {
@@ -254,7 +259,7 @@ maildir_mkfilename (const char *directory, const char *suffix, const char *name)
 static char *
 mk_info_filename (char *directory, char *suffix, char *name, int flags)
 {
-  char fbuf[9];
+  char fbuf[info_map_size + 1];
   char *tmp;
   int namelen;
   size_t size;
@@ -691,23 +696,6 @@ maildir_scan0 (mu_mailbox_t mailbox, size_t msgno MU_ARG_UNUSED,
   if (pcount)
     *pcount = amd->msg_count;
 
-  /* Reset the uidvalidity.  */
-  if (amd->msg_count > 0)
-    {
-      if (amd->uidvalidity == 0)
-	{
-	  amd->uidvalidity = (unsigned long) time (NULL);
-	  /* FIXME amd->uidnext = amd->msg_count + 1;*/
-	  /* Tell that we have been modified for expunging.  */
-	  if (amd->msg_count)
-	    {
-	      amd_message_stream_open (amd->msg_array[0]);
-	      amd_message_stream_close (amd->msg_array[0]);
-	      amd->msg_array[0]->attr_flags |= MU_ATTRIBUTE_MODIFIED;
-	    }
-	}
-    }
-
   /* Clean up the things */
   amd_cleanup (mailbox);
   return status;
@@ -773,6 +761,42 @@ maildir_remove (struct _amd_data *amd)
   return rc;
 }
 
+
+static int
+maildir_chattr_msg (struct _amd_message *amsg, int expunge)
+{
+  struct _maildir_message *mp = (struct _maildir_message *) amsg;
+  struct _amd_data *amd = amsg->amd;
+  int rc;
+  char *new_name;
+  
+  rc = amd->new_msg_file_name (amsg, amsg->attr_flags, expunge, &new_name);
+  if (rc)
+    return rc;
+  if (!new_name)
+    {
+      if (unlink (mp->file_name))
+	rc = errno;
+    }
+  else
+    {
+      char *cur_name;
+      
+      rc = maildir_cur_message_name (amsg, &cur_name);
+      if (rc)
+	{
+	  free (new_name);
+	  return rc;
+	}
+      if (rename (cur_name, new_name))
+	rc = errno;
+      free (cur_name);
+    }
+
+  free (new_name);
+  return rc;
+}
+
      
 int
 _mailbox_maildir_init (mu_mailbox_t mailbox)
@@ -797,6 +821,8 @@ _mailbox_maildir_init (mu_mailbox_t mailbox)
   amd->message_uid = maildir_message_uid;
   amd->next_uid = maildir_next_uid;
   amd->remove = maildir_remove;
+  amd->chattr_msg = maildir_chattr_msg;
+  amd->capabilities = MU_AMD_STATUS;
   
   /* Set our properties.  */
   {
diff --git a/libproto/mh/folder.c b/libproto/mh/folder.c
index 87b94d4..66e02cf 100644
--- a/libproto/mh/folder.c
+++ b/libproto/mh/folder.c
@@ -121,11 +121,9 @@ _mh_is_scheme (mu_record_t record, mu_url_t url, int flags)
 static int
 _mh_list_p (mu_record_t record, const char *name, int flags MU_ARG_UNUSED)
 {
-  int len;
-  
-  if (strcmp (name, MU_AMD_SIZE_FILE_NAME) == 0
-      || name[0] == ','
-      || (((len = strlen (name)) > 3) && memcmp (name, ".mh", 3) == 0))
+  if (name[0] == ',' ||
+      ((strlen (name) > 3) &&
+       (memcmp (name, ".mh", 3) == 0 || memcmp (name, ".mu", 3) == 0)))
     return 0;
 
   for (; *name; name++)
diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c
index 5a51ba1..6ffa958 100644
--- a/libproto/mh/mbox.c
+++ b/libproto/mh/mbox.c
@@ -278,22 +278,6 @@ mh_scan0 (mu_mailbox_t mailbox, size_t msgno MU_ARG_UNUSED, size_t *pcount,
 
       if (pcount)
 	*pcount = amd->msg_count;
-
-      /* Reset the uidvalidity.  */
-      if (amd->msg_count > 0)
-	{
-	  if (amd->uidvalidity == 0)
-	    {
-	      amd->uidvalidity = (unsigned long)time (NULL);
-	      /* Tell that we have been modified for expunging.  */
-	      if (amd->msg_count)
-		{
-		  amd_message_stream_open (amd->msg_array[0]);
-		  amd_message_stream_close (amd->msg_array[0]);
-		  amd->msg_array[0]->attr_flags |= MU_ATTRIBUTE_MODIFIED;
-		}
-	    }
-	}
     }
   /* Clean up the things */
 
diff --git a/maidag/forward.c b/maidag/forward.c
index dd02164..a1b8697 100644
--- a/maidag/forward.c
+++ b/maidag/forward.c
@@ -213,10 +213,10 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile)
     mu_list_create (&idlist);
 
   rc = mu_file_safety_check (filename, forward_file_checks,
-				  auth, idlist);
+			     auth, idlist);
   if (rc == 0)
     result = process_forward (msg, filename, auth->name);
-  else if (rc)
+  else if (rc == MU_ERR_EXISTS)
     mu_diag_output (MU_DIAG_NOTICE,
 		    _("skipping forward file %s: already processed"),
 		    filename);
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 6c6af88..348c6da 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -348,9 +348,15 @@ cb2_forward_file_checks (const char *name, void *data)
     name++;
 
   if (strcmp (name, "none") == 0)
-    forward_file_checks = MU_FILE_SAFETY_NONE;
+    {
+      forward_file_checks = negate ? MU_FILE_SAFETY_ALL : MU_FILE_SAFETY_NONE;
+      return 0;
+    }
   else if (strcmp (name, "all") == 0)
-    forward_file_checks = MU_FILE_SAFETY_ALL;
+    {
+      forward_file_checks = negate ? MU_FILE_SAFETY_NONE : MU_FILE_SAFETY_ALL;
+      return 0;
+    }
   else if (strcmp (name, "default") == 0)
     forward_file_checks = FORWARD_FILE_PERM_CHECK;
   else if (mu_file_safety_name_to_code (name, &val))
diff --git a/mh/tests/folder.at b/mh/tests/folder.at
index 8d89d9e..6b616aa 100644
--- a/mh/tests/folder.at
+++ b/mh/tests/folder.at
@@ -87,7 +87,7 @@ do
   mv Mail/inbox/$i Mail/inbox/${i}0
 done
 folder -pack || exit $?
-find Mail/inbox | sort
+find Mail/inbox -not -name '.mu-prop' | sort
 ],
 [0],
 [Mail/inbox
@@ -105,7 +105,7 @@ do
   mv Mail/inbox/$i Mail/inbox/${i}0
 done
 folder --pack=1 || exit $?
-find Mail/inbox | sort
+find Mail/inbox -not -name '.mu-prop' | sort
 ],
 [0],
 [Mail/inbox


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Oct 21 07:26:23 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RHDF1-00042w-Gm
	for mharc-commit-mailutils@gnu.org; Fri, 21 Oct 2011 07:26:23 -0400
Received: from eggs.gnu.org ([140.186.70.92]:47667)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHDEw-0003pV-38
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 07:26:21 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHDEt-0007qh-2Y
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 07:26:18 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:53507)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHDEs-0007qd-PZ
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 07:26:14 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHDEq-00059d-4t
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 11:26:14 +0000
Date: Fri, 21 Oct 2011 11:26:12 +0000
Message-Id: <E1RHDEq-00059d-4t@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-401-gaccf1d9
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: fa3be4baf0edf9c9df06ca272a19fae88c71d88b
X-Git-Newrev: accf1d99e04d805b959df61c72ac62fb0b039059
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 21 Oct 2011 11:26:21 -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=accf1d99e04d805b959df61c72ac62fb0b039059

The branch, master has been updated
       via  accf1d99e04d805b959df61c72ac62fb0b039059 (commit)
       via  38ff031904226ea8ccace1a6a9dc8d8b0f6367fe (commit)
       via  f5703c2608a90cb12b39a8194c6257f91fc09d65 (commit)
      from  fa3be4baf0edf9c9df06ca272a19fae88c71d88b (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 accf1d99e04d805b959df61c72ac62fb0b039059
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 21 14:20:15 2011 +0300

    Fix locking in pop3 and imap4d.  This complements d0769b4f.
    
    * lib/manlock.c (mailbox_open_and_lock): Open mailbox before retrieving
    its locker, otherwise it is always NULL.
    * pop3d/pop3d.c (main): Enforce mandatory locking.

commit 38ff031904226ea8ccace1a6a9dc8d8b0f6367fe
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 21 12:36:36 2011 +0300

    Testsuite: add banners before groups of related tests.

commit f5703c2608a90cb12b39a8194c6257f91fc09d65
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 21 12:03:20 2011 +0300

    amd: report MU_EVT_MAILBOX_CORRUPT if unable to rename message file due to ENOENT
    
    * libmailutils/base/amd.c
    * libproto/maildir/mbox.c

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

Summary of changes:
 lib/manlock.c                   |   14 +++++++++-----
 libmailutils/base/amd.c         |   33 +++++++++++++++++++++++++++++----
 libmailutils/tests/address.at   |    2 ++
 libmailutils/tests/list.at      |    2 ++
 libmailutils/tests/mailcap.at   |    2 ++
 libmailutils/tests/prop.at      |    2 ++
 libmailutils/tests/testsuite.at |   10 ++++++++--
 libmailutils/tests/url.at       |    2 ++
 libmailutils/tests/wicket.at    |    2 ++
 libmailutils/tests/wordsplit.at |    2 ++
 libproto/maildir/mbox.c         |   14 +++++++++++++-
 mh/tests/ali.at                 |    1 +
 mh/tests/anno.at                |    1 +
 mh/tests/burst.at               |    1 +
 mh/tests/comp.at                |    1 +
 mh/tests/folder.at              |    1 +
 mh/tests/forw.at                |    1 +
 mh/tests/inc.at                 |    1 +
 mh/tests/install-mh.at          |    1 +
 mh/tests/mark.at                |    1 +
 mh/tests/mhl.at                 |    1 +
 mh/tests/mhn.at                 |    1 +
 mh/tests/mhparam.at             |    1 +
 mh/tests/mhpath.at              |    1 +
 mh/tests/mhseq.at               |    1 +
 mh/tests/pick.at                |    1 +
 mh/tests/refile.at              |    1 +
 mh/tests/repl.at                |    2 ++
 mh/tests/rmf.at                 |    2 ++
 mh/tests/rmm.at                 |    2 ++
 mh/tests/scan.at                |    2 ++
 mh/tests/send.at                |    2 ++
 mh/tests/sortm.at               |    2 ++
 pop3d/pop3d.c                   |    1 +
 sieve/tests/testsuite.at        |   20 +++++++++++++++-----
 35 files changed, 117 insertions(+), 17 deletions(-)

diff --git a/lib/manlock.c b/lib/manlock.c
index 33ecc3f..9d824e6 100644
--- a/lib/manlock.c
+++ b/lib/manlock.c
@@ -110,6 +110,15 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags)
   mu_mailbox_get_url (mbox, &url);
   urlstr = mu_url_to_string (url);
   
+  if ((status = mu_mailbox_open (mbox, flags)) != 0)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", urlstr, status);
+      return MU_ERR_FAILURE;
+    }
+  /* This is a mild race condition: mailbox needs to be opened in order to
+     obtain its locker.  Other process can acquire the lock in the meantime,
+     but that's not critical, because manlock_lock below will fail if unable
+     to lock the mailbox anyway. */
   status = mu_mailbox_get_locker (mbox, &lock);
   if (status)
     {
@@ -145,11 +154,6 @@ mailbox_open_and_lock (mu_mailbox_t mbox, int flags)
       mu_mailbox_set_locker (mbox, lock);
     }
 
-  if ((status = mu_mailbox_open (mbox, flags)) != 0)
-    {
-      mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_open", urlstr, status);
-      return MU_ERR_FAILURE;
-    }
   return manlock_lock (mbox);
 }
 
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index a5685d9..d60903f 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -967,7 +967,19 @@ _amd_message_save (struct _amd_data *amd, struct _amd_message *mhm,
   if (status == 0)
     {
       if (rename (name, msg_name))
-	status = errno;
+	{
+	  if (errno == ENOENT)
+	    mu_observable_notify (amd->mailbox->observable,
+				  MU_EVT_MAILBOX_CORRUPT,
+				  amd->mailbox);
+	  else
+	    {
+	      status = errno;
+	      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+			("renaming %s to %s failed: %s",
+			 name, msg_name, mu_strerror (status)));
+	    }
+	}
       else
 	{
 	  mode_t perms;
@@ -1372,9 +1384,22 @@ amd_expunge (mu_mailbox_t mailbox)
 		     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);
+		  if (strcmp (old_name, new_name) &&
+		      /* Rename original message */
+		      rename (old_name, new_name))
+		    {
+		      if (errno == ENOENT)
+			mu_observable_notify (mailbox->observable,
+					      MU_EVT_MAILBOX_CORRUPT,
+					      mailbox);
+		      else
+			{
+			  rc = errno;
+			  mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+				    ("renaming %s to %s failed: %s",
+				     old_name, new_name, mu_strerror (rc)));
+			}
+		    }
 		}
 	      else
 		/* Unlink original file */
diff --git a/libmailutils/tests/address.at b/libmailutils/tests/address.at
index 8e5b03c..cbf546c 100644
--- a/libmailutils/tests/address.at
+++ b/libmailutils/tests/address.at
@@ -15,6 +15,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/>.
 
+AT_BANNER(Email address)
+
 dnl ------------------------------------------------------------
 dnl TESTADDR(ADDR, [KW = `'], [STATUS = `0'], [STDOUT = `'],
 dnl          [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
diff --git a/libmailutils/tests/list.at b/libmailutils/tests/list.at
index 393c4fa..eab485b 100644
--- a/libmailutils/tests/list.at
+++ b/libmailutils/tests/list.at
@@ -15,6 +15,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/>.
 
+AT_BANNER(List)
+
 dnl ------------------------------------------------------------
 dnl TESTLIST([NAME], [KW = `'], [INPUT], [STDOUT = `'],
 dnl          [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
diff --git a/libmailutils/tests/mailcap.at b/libmailutils/tests/mailcap.at
index a9a9baf..b16dfc3 100644
--- a/libmailutils/tests/mailcap.at
+++ b/libmailutils/tests/mailcap.at
@@ -15,6 +15,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/>.
 
+AT_BANNER(Mailcap)
+
 dnl ------------------------------------------------------------
 dnl MAILCAP([NAME], [KW = `'], [INPUT], [STDOUT = `'],
 dnl         [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
diff --git a/libmailutils/tests/prop.at b/libmailutils/tests/prop.at
index c87717d..74ad13a 100644
--- a/libmailutils/tests/prop.at
+++ b/libmailutils/tests/prop.at
@@ -15,6 +15,8 @@
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 # This file is part of Mailfromd testsuite. 
 
+AT_BANNER(Property)
+
 dnl ------------------------------------------------------------------
 dnl TESTPROP([NAME], [KW = `'], [PROG], [STDOUT = `'], [STDERR = `'])
 dnl
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 46629dd..31b0821 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -59,13 +59,19 @@ m4_include([address.at])
 m4_include([wordsplit.at])
 m4_include([url.at])
 m4_include([mailcap.at])
+m4_include([wicket.at])
+m4_include([prop.at])
+
+AT_BANNER(Base64)
 m4_include([base64e.at])
 m4_include([base64d.at])
+
+AT_BANNER(RFC 2047)
 m4_include([decode2047.at])
 m4_include([encode2047.at])
+
+AT_BANNER(Filters)
 m4_include([fromflt.at])
-m4_include([wicket.at])
-m4_include([prop.at])
 m4_include([inline-comment.at])
 m4_include([hdrflt.at])
 m4_include([linecon.at])
diff --git a/libmailutils/tests/url.at b/libmailutils/tests/url.at
index c0669e2..bfb8db6 100644
--- a/libmailutils/tests/url.at
+++ b/libmailutils/tests/url.at
@@ -15,6 +15,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/>.
 
+AT_BANNER(URL)
+
 dnl ------------------------------------------------------------
 dnl TESTURL([NAME], [KW = `'], [INPUT], [STDOUT = `'],
 dnl         [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
diff --git a/libmailutils/tests/wicket.at b/libmailutils/tests/wicket.at
index e049ebe..9b1fb3c 100644
--- a/libmailutils/tests/wicket.at
+++ b/libmailutils/tests/wicket.at
@@ -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/>.
 
+AT_BANNER(Wicket)
+
 dnl ------------------------------------------------------------
 dnl TESTWICKET(URL, [KW = `'], [STDOUT = `'],
 dnl            [STDERR = `'], [RUN-IF-FAIL], [RUN-IF-PASS])
diff --git a/libmailutils/tests/wordsplit.at b/libmailutils/tests/wordsplit.at
index bedb51f..8625f95 100644
--- a/libmailutils/tests/wordsplit.at
+++ b/libmailutils/tests/wordsplit.at
@@ -15,6 +15,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/>.
 
+AT_BANNER(Wordsplit)
+
 dnl ------------------------------------------------------------
 dnl TESTWSP([NAME], [KW = `'], [OPTS], [INPUT], [STDOUT = `'],
 dnl         [STDERR = `'], [ENV])
diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c
index acf8f9b..298bdfd 100644
--- a/libproto/maildir/mbox.c
+++ b/libproto/maildir/mbox.c
@@ -789,7 +789,19 @@ maildir_chattr_msg (struct _amd_message *amsg, int expunge)
 	  return rc;
 	}
       if (rename (cur_name, new_name))
-	rc = errno;
+	{
+	  if (errno == ENOENT)
+	    mu_observable_notify (amd->mailbox->observable,
+				  MU_EVT_MAILBOX_CORRUPT,
+				  amd->mailbox);
+	  else
+	    {
+	      rc = errno;
+	      mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+			("renaming %s to %s failed: %s",
+			 cur_name, new_name, mu_strerror (rc)));
+	    }
+	}
       free (cur_name);
     }
 
diff --git a/mh/tests/ali.at b/mh/tests/ali.at
index 8b640c7..4686aa8 100644
--- a/mh/tests/ali.at
+++ b/mh/tests/ali.at
@@ -14,6 +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/>.
 
+AT_BANNER(ali)
 m4_pushdef([MH_KEYWORDS],[ali])
 
 MH_CHECK([ali: simple aliases],[ali00],[
diff --git a/mh/tests/anno.at b/mh/tests/anno.at
index 3256f6b..25bed09 100644
--- a/mh/tests/anno.at
+++ b/mh/tests/anno.at
@@ -14,6 +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/>.
 
+AT_BANNER(anno)
 m4_pushdef([MH_KEYWORDS],[anno])
 
 MH_CHECK([anno],[anno00],[
diff --git a/mh/tests/burst.at b/mh/tests/burst.at
index f244fdf..302688c 100644
--- a/mh/tests/burst.at
+++ b/mh/tests/burst.at
@@ -14,6 +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/>.
 
+AT_BANNER(burst)
 m4_pushdef([MH_KEYWORDS],[burst])
 
 MH_CHECK([burst digest],[burst00 burst-digest],[
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index 30af571..b264f25 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -14,6 +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/>.
 
+AT_BANNER(comp)
 m4_pushdef([MH_KEYWORDS],[comp])
 m4_pushdef([compcmd],[comp -editor $abs_top_srcdir/mh/tests/mhed])
 
diff --git a/mh/tests/folder.at b/mh/tests/folder.at
index 6b616aa..a637200 100644
--- a/mh/tests/folder.at
+++ b/mh/tests/folder.at
@@ -14,6 +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/>.
 
+AT_BANNER(folder)
 m4_pushdef([MH_KEYWORDS],[folder])
 
 MH_CHECK([folder],[folder00 folder-print],[
diff --git a/mh/tests/forw.at b/mh/tests/forw.at
index cd8ad73..29f83b7 100644
--- a/mh/tests/forw.at
+++ b/mh/tests/forw.at
@@ -14,6 +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/>.
 
+AT_BANNER(forw)
 m4_pushdef([MH_KEYWORDS],[forw])
 m4_pushdef([forwcmd],[forw -editor $abs_top_srcdir/mh/tests/mhed])
 
diff --git a/mh/tests/inc.at b/mh/tests/inc.at
index 1003acd..83a651a 100644
--- a/mh/tests/inc.at
+++ b/mh/tests/inc.at
@@ -14,6 +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/>.
 
+AT_BANNER(inc)
 m4_pushdef([MH_KEYWORDS],[inc])
 
 MH_CHECK([inc -notruncate],[inc00 inc-notruncate],[
diff --git a/mh/tests/install-mh.at b/mh/tests/install-mh.at
index e5be717..9853f01 100644
--- a/mh/tests/install-mh.at
+++ b/mh/tests/install-mh.at
@@ -14,6 +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/>.
 
+AT_BANNER(install-mh)
 AT_SETUP([install-mh -auto])
 AT_KEYWORDS([install-mh install-mh00])
 
diff --git a/mh/tests/mark.at b/mh/tests/mark.at
index 531c355..3646e6c 100644
--- a/mh/tests/mark.at
+++ b/mh/tests/mark.at
@@ -14,6 +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/>.
 
+AT_BANNER(mark)
 m4_pushdef([MH_KEYWORDS],[mark])
 
 MH_CHECK([mark -add],[mark00 mark-add],[
diff --git a/mh/tests/mhl.at b/mh/tests/mhl.at
index c136a66..501c8af 100644
--- a/mh/tests/mhl.at
+++ b/mh/tests/mhl.at
@@ -14,6 +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/>.
 
+AT_BANNER(mhl)
 m4_pushdef([MH_KEYWORDS],[mhl])
 
 MH_CHECK([mhl],[mhl00],[
diff --git a/mh/tests/mhn.at b/mh/tests/mhn.at
index 95caed9..d55d4e7 100644
--- a/mh/tests/mhn.at
+++ b/mh/tests/mhn.at
@@ -14,6 +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/>.
 
+AT_BANNER(mhn)
 m4_pushdef([MH_KEYWORDS],[mhn])
 
 dnl -------------------------------------------------------------------
diff --git a/mh/tests/mhparam.at b/mh/tests/mhparam.at
index 9720dd0..6d40e8a 100644
--- a/mh/tests/mhparam.at
+++ b/mh/tests/mhparam.at
@@ -14,6 +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/>.
 
+AT_BANNER(mhparam)
 m4_pushdef([MH_KEYWORDS],[mhparam])
 
 MH_CHECK([mhparam -all],[mhparam00 mhparam-all],[
diff --git a/mh/tests/mhpath.at b/mh/tests/mhpath.at
index 57b8fd5..439d00f 100644
--- a/mh/tests/mhpath.at
+++ b/mh/tests/mhpath.at
@@ -14,6 +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/>.
 
+AT_BANNER(mhpath)
 m4_pushdef([MH_KEYWORDS],[mhpath])
 
 MH_CHECK([mhpath],[mhpath00],[
diff --git a/mh/tests/mhseq.at b/mh/tests/mhseq.at
index 8ca1596..ed5ca8f 100644
--- a/mh/tests/mhseq.at
+++ b/mh/tests/mhseq.at
@@ -14,6 +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/>.
 
+AT_BANNER(mhseq)
 m4_pushdef([MH_KEYWORDS],[mhseq mh-sequences])
 
 dnl ---------------------------------------------------------------
diff --git a/mh/tests/pick.at b/mh/tests/pick.at
index b6efebd..726b4bd 100644
--- a/mh/tests/pick.at
+++ b/mh/tests/pick.at
@@ -14,6 +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/>.
 
+AT_BANNER(pick)
 m4_pushdef([MH_KEYWORDS],[pick])
 
 MH_CHECK([pick -from],[pick00 pick-from],[
diff --git a/mh/tests/refile.at b/mh/tests/refile.at
index e8a35c8..17d8568 100644
--- a/mh/tests/refile.at
+++ b/mh/tests/refile.at
@@ -14,6 +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/>.
 
+AT_BANNER(refile)
 m4_pushdef([MH_KEYWORDS],[refile])
 
 MH_CHECK([refile],[refile00],[
diff --git a/mh/tests/repl.at b/mh/tests/repl.at
index d3879e0..a70a4da 100644
--- a/mh/tests/repl.at
+++ b/mh/tests/repl.at
@@ -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/>.
 
+AT_BANNER(repl)
+
 m4_pushdef([MH_KEYWORDS],[repl])
 m4_pushdef([replcmd],[repl dnl
 -editor $abs_top_srcdir/mh/tests/mhed])
diff --git a/mh/tests/rmf.at b/mh/tests/rmf.at
index 34b864c..c348e0f 100644
--- a/mh/tests/rmf.at
+++ b/mh/tests/rmf.at
@@ -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/>.
 
+AT_BANNER(rmf)
+
 m4_pushdef([MH_KEYWORDS],[rmf])
 
 MH_CHECK([rmf +folder],[rmf00 rmf+folder],[
diff --git a/mh/tests/rmm.at b/mh/tests/rmm.at
index 310cd39..1977532 100644
--- a/mh/tests/rmm.at
+++ b/mh/tests/rmm.at
@@ -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/>.
 
+AT_BANNER(rmm)
+
 m4_pushdef([MH_KEYWORDS],[rmm])
 
 MH_CHECK([rmm msg],[rmm00 rmm-msg],[
diff --git a/mh/tests/scan.at b/mh/tests/scan.at
index a5aabff..782f996 100644
--- a/mh/tests/scan.at
+++ b/mh/tests/scan.at
@@ -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/>.
 
+AT_BANNER(scan)
+
 m4_pushdef([MH_KEYWORDS],[scan])
 
 MH_CHECK([scan],[scan00],[
diff --git a/mh/tests/send.at b/mh/tests/send.at
index ad5154d..e9a405d 100644
--- a/mh/tests/send.at
+++ b/mh/tests/send.at
@@ -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/>.
 
+AT_BANNER(send)
+
 m4_pushdef([MH_KEYWORDS],[send])
 
 MH_CHECK([send file],[send00 send-file],[
diff --git a/mh/tests/sortm.at b/mh/tests/sortm.at
index c0af3bb..bdf2f8c 100644
--- a/mh/tests/sortm.at
+++ b/mh/tests/sortm.at
@@ -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/>.
 
+AT_BANNER(sortm)
+
 m4_pushdef([MH_KEYWORDS],[sortm])
 m4_pushdef([scancmd],[scan -format '%4(msg)%<(cur)+%| %> %02(mon{date})/%02(mday{date}) %24(friendly{from}) %{subject}'])
 
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 043e2f1..9a5f47d 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -340,6 +340,7 @@ main (int argc, char **argv)
   mu_alloc_die_hook = pop3d_alloc_die;
 
   mu_log_syslog = 1;
+  manlock_mandatory_locking = 1;
   
   if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, 
 		   argc, argv, 0, NULL, server))
diff --git a/sieve/tests/testsuite.at b/sieve/tests/testsuite.at
index d2c4426..c5bceae 100644
--- a/sieve/tests/testsuite.at
+++ b/sieve/tests/testsuite.at
@@ -114,25 +114,35 @@ AT_INIT
 AT_TESTED([sieve])
 
 m4_include([version.at])
+
+AT_BANNER(Compilation)
 m4_include([compile.at])
+
+AT_BANNER(Actions)
 m4_include([false.at])
 m4_include([true.at])
 m4_include([not.at])
 m4_include([action.at])
+m4_include([redirect.at])
+m4_include([reject.at])
+
+AT_BANNER(Tests)
 m4_include([address.at])
 m4_include([allof.at])
 m4_include([anyof.at])
 m4_include([envelope.at])
 m4_include([exists.at])
 m4_include([header.at])
+m4_include([relational.at])
+m4_include([size.at])
+m4_include([mul-addr.at])
+
+AT_BANNER(Comparators)
 m4_include([i-casemap.at])
 m4_include([i-numeric.at])
 m4_include([i-octet.at])
-m4_include([mul-addr.at])
-m4_include([relational.at])
-m4_include([size.at])
-m4_include([redirect.at])
-m4_include([reject.at])
+
+AT_BANNER(Extensions)
 m4_include([ext.at])
 m4_include([moderator.at])
 m4_include([pipeact.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Oct 21 20:45:39 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RHPiV-0007R4-10
	for mharc-commit-mailutils@gnu.org; Fri, 21 Oct 2011 20:45:39 -0400
Received: from eggs.gnu.org ([140.186.70.92]:51702)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHPiR-0007Qd-Ax
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 20:45:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHPiO-0007Fh-8T
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 20:45:35 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:53048)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHPiO-0007Fd-3j
	for commit-mailutils@gnu.org; Fri, 21 Oct 2011 20:45:32 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RHPiN-0000tH-G0
	for commit-mailutils@gnu.org; Sat, 22 Oct 2011 00:45:31 +0000
Date: Sat, 22 Oct 2011 00:45:31 +0000
Message-Id: <E1RHPiN-0000tH-G0@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-403-g09372dd
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: accf1d99e04d805b959df61c72ac62fb0b039059
X-Git-Newrev: 09372ddfbaeb45facface67dea795f8e9059d899
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Oct 2011 00:45: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=09372ddfbaeb45facface67dea795f8e9059d899

The branch, master has been updated
       via  09372ddfbaeb45facface67dea795f8e9059d899 (commit)
       via  2f34f8ae2c0f9207d94629d94f664f728094e990 (commit)
      from  accf1d99e04d805b959df61c72ac62fb0b039059 (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 09372ddfbaeb45facface67dea795f8e9059d899
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Oct 22 03:16:00 2011 +0300

    Fixes in the testsuite & some minor fixes.
    
    * comsat/comsat.c (main): Use real UID to determine user name. Don't
    rely on environment variables.
    * maidag/util.c (maidag_error): Re-initialize va_list before reusing it.
    * mh/ali.c (ali_print_name_list): Change printing loop to correctly
    handle empty lists.
    * mh/mh_whatnow.c (quit): Print newline before returning.
    
    * comsat/tests/testsuite.at: Skip tests if run as root.
    * maidag/tests/forward.at: Skip test if run as root.
    * mh/tests/ali.at: Ignore comment lines in /etc/passwd and /etc/group.
    Make sure awk is run with a valid stdin.  Some implementations
    (true awk, in particular) try to close stdin even if it is not used and
    bail out if unable to do so.
    * mh/tests/atlocal.in (mimeflt): Make sure awk is run with a valid
    stdin (see above).
    * mh/tests/anno.at: Always use semicolon before closing curly brace in
    sed expressions.
    * mh/tests/mark.at: Likewise.
    * mh/tests/pick.at: Likewise.
    * testsuite/testsuite.inc: Likewise.
    * mh/tests/comp.at: Reflect changes to mh_whatnow.c.
    * mh/tests/mhn.at: Don't rely on a particular tar output format.

commit 2f34f8ae2c0f9207d94629d94f664f728094e990
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Oct 22 03:11:55 2011 +0300

    Make all status flags permanent.
    
    * include/mailutils/attribute.h (MU_STATUS_BUF_SIZE): Add more status letters.
    * libmailutils/mailbox/attribute.c (flagtrans): Keep the same ordering as
    in attribute.h.  Add missing attributes.
    
    * imap4d/select.c (imap4d_select_status): All flags are now permanent.
    * imap4d/testsuite/imap4d/IDEF0955.exp: Reflect changes in PERMANENTFLAGS.
    * imap4d/testsuite/imap4d/IDEF0956.exp: Likewise.
    * imap4d/testsuite/imap4d/append.exp: Likewise.
    * imap4d/testsuite/imap4d/create.exp: Likewise.
    * imap4d/testsuite/imap4d/examine.exp: Likewise.
    * imap4d/testsuite/imap4d/expunge.exp: Likewise.
    * imap4d/testsuite/imap4d/fetch.exp: Likewise.
    * imap4d/testsuite/imap4d/search.exp: Likewise.

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

Summary of changes:
 comsat/comsat.c                      |   19 ++++++-------------
 comsat/tests/testsuite.at            |    5 ++++-
 imap4d/select.c                      |    3 +--
 imap4d/testsuite/imap4d/IDEF0955.exp |    2 +-
 imap4d/testsuite/imap4d/IDEF0956.exp |    2 +-
 imap4d/testsuite/imap4d/append.exp   |    2 +-
 imap4d/testsuite/imap4d/create.exp   |    2 +-
 imap4d/testsuite/imap4d/examine.exp  |    2 +-
 imap4d/testsuite/imap4d/expunge.exp  |    4 ++--
 imap4d/testsuite/imap4d/fetch.exp    |    2 +-
 imap4d/testsuite/imap4d/search.exp   |    2 +-
 include/mailutils/attribute.h        |    2 +-
 libmailutils/mailbox/attribute.c     |    5 +++--
 maidag/tests/forward.at              |    3 ++-
 maidag/util.c                        |    2 ++
 mh/ali.c                             |   15 +++++++--------
 mh/mh_whatnow.c                      |    4 ++--
 mh/tests/ali.at                      |   12 +++++-------
 mh/tests/anno.at                     |    8 ++++----
 mh/tests/atlocal.in                  |    2 +-
 mh/tests/comp.at                     |    3 ++-
 mh/tests/mark.at                     |   12 ++++++------
 mh/tests/mhn.at                      |   18 +++++++++---------
 mh/tests/pick.at                     |    2 +-
 testsuite/testsuite.inc              |    2 +-
 25 files changed, 66 insertions(+), 69 deletions(-)

diff --git a/comsat/comsat.c b/comsat/comsat.c
index 9592e48..e9a5a22 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -578,6 +578,7 @@ main (int argc, char **argv)
 
   if (test_mode)
     {
+      struct passwd *pw;
       char *user;
       
       argc -= ind;
@@ -591,21 +592,13 @@ main (int argc, char **argv)
 	  exit (EXIT_FAILURE);
 	}
 
-      user = getenv ("LOGNAME");
-      if (!user)
+      pw = getpwuid (getuid ());
+      if (!pw)
 	{
-	  user = getenv ("USER");
-	  if (!user)
-	    {
-	      struct passwd *pw = getpwuid (getuid ());
-	      if (!pw)
-		{
-		  mu_error (_("cannot determine user name"));
-		  exit (EXIT_FAILURE);
-		}
-	      user = pw->pw_name;
-	    }
+	  mu_error (_("cannot determine user name"));
+	  exit (EXIT_FAILURE);
 	}
+      user = pw->pw_name;
 
       if (biffrc[0] == '.' && (biffrc[1] == '/' ||
 			       (biffrc[1] == '.' && biffrc[2] == '/')))
diff --git a/comsat/tests/testsuite.at b/comsat/tests/testsuite.at
index c61308c..4ccda9a 100644
--- a/comsat/tests/testsuite.at
+++ b/comsat/tests/testsuite.at
@@ -29,11 +29,14 @@ m4_pushdef([comsatcmd],[comsatd --no-site --no-user --file ./biff.rc dnl
 dnl ------------------------------------------------------------
 dnl BIFFTEST(DESCR, KW, DATA, CMDLINE, [STDOUT = `'], [STDERR = `'])
 dnl
+dnl NOTE: The test is skipped if run as root, because .biffrc is
+dnl ignored for root (see open_rc() in action.c
+dnl
 m4_pushdef([BIFFTEST],[
 AT_SETUP([comsatd: $1])
 AT_KEYWORDS([comsatd $2])
 $3
-AT_CHECK([$4],[0],[$5],[$6])
+AT_CHECK([test -w / && AT_SKIP_TEST; $4],[0],[$5],[$6])
 AT_CLEANUP])
 
 AT_INIT
diff --git a/imap4d/select.c b/imap4d/select.c
index 4a928c4..166e0d7 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -116,7 +116,6 @@ int
 imap4d_select_status ()
 {
   const char *mflags = "\\Answered \\Flagged \\Deleted \\Seen \\Draft";
-  const char *pflags = "\\Answered \\Deleted \\Seen";
   unsigned long uidvalidity = 0;
   size_t count = 0, recent = 0, unseen = 0, uidnext = 0;
   int status = 0;
@@ -148,7 +147,7 @@ imap4d_select_status ()
     io_untagged_response (RESP_OK, "[PERMANENTFLAGS ()] No Permanent flags");
   else
     io_untagged_response (RESP_OK, "[PERMANENTFLAGS (%s)] Permanent flags",
-                          pflags);
+                          mflags);
 
   return 0;
 }
diff --git a/imap4d/testsuite/imap4d/IDEF0955.exp b/imap4d/testsuite/imap4d/IDEF0955.exp
index 52fad3d..06629c5 100644
--- a/imap4d/testsuite/imap4d/IDEF0955.exp
+++ b/imap4d/testsuite/imap4d/IDEF0955.exp
@@ -33,7 +33,7 @@ if { $MU_ULONG_MAX > 0 } {
 	"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" \
+	"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags" \
 	"OK"
 
     set limit [expr $MU_ULONG_MAX - 1]
diff --git a/imap4d/testsuite/imap4d/IDEF0956.exp b/imap4d/testsuite/imap4d/IDEF0956.exp
index 169a512..9a22815 100644
--- a/imap4d/testsuite/imap4d/IDEF0956.exp
+++ b/imap4d/testsuite/imap4d/IDEF0956.exp
@@ -31,7 +31,7 @@ if { $MU_ULONG_MAX > 0 } {
 	"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" \
+	"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags" \
 	"OK"
 
     set limit [expr $MU_ULONG_MAX - 1]
diff --git a/imap4d/testsuite/imap4d/append.exp b/imap4d/testsuite/imap4d/append.exp
index e90968f..6289964 100644
--- a/imap4d/testsuite/imap4d/append.exp
+++ b/imap4d/testsuite/imap4d/append.exp
@@ -66,7 +66,7 @@ imap4d_test "SELECT mbox"\
 "OK \[UIDNEXT 4\] Predicted next uid"\
 "OK \[UNSEEN 1\] first unseen messsage"\
 "FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
-"OK \[PERMANENTFLAGS (\\Answered \\Deleted \\Seen)\] Permanent flags"\
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags"\
 "OK"
 
 imap4d_test "FETCH 2:3 BODY\[\]"\
diff --git a/imap4d/testsuite/imap4d/create.exp b/imap4d/testsuite/imap4d/create.exp
index a0d0e0f..0ca83b7 100644
--- a/imap4d/testsuite/imap4d/create.exp
+++ b/imap4d/testsuite/imap4d/create.exp
@@ -59,7 +59,7 @@ imap4d_test "SELECT en/to/tre"\
 "OK \[UIDNEXT 2\] Predicted next uid"\
 "OK \[UNSEEN 1\] first unseen messsage"\
 "FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
-"OK \[PERMANENTFLAGS (\\Answered \\Deleted \\Seen)\] Permanent flags"\
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags"\
 "OK \[READ-WRITE\] SELECT Completed"
 
 imap4d_test "FETCH 1 ALL"\
diff --git a/imap4d/testsuite/imap4d/examine.exp b/imap4d/testsuite/imap4d/examine.exp
index d80e24b..64dcc15 100644
--- a/imap4d/testsuite/imap4d/examine.exp
+++ b/imap4d/testsuite/imap4d/examine.exp
@@ -35,7 +35,7 @@ imap4d_test "SELECT INBOX"\
 "OK \[UIDNEXT 96\] Predicted next uid"\
 "OK \[UNSEEN 1\] first unseen messsage "\
 "FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
-"OK \[PERMANENTFLAGS (\\Answered \\Deleted \\Seen)\] Permanent flags"\
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags"\
 "OK \[READ-WRITE\] SELECT Completed"
 
 imap4d_test "STATUS INBOX (MESSAGES RECENT UNSEEN UIDVALIDITY UIDNEXT)" \
diff --git a/imap4d/testsuite/imap4d/expunge.exp b/imap4d/testsuite/imap4d/expunge.exp
index 37fcd14..2d0e745 100644
--- a/imap4d/testsuite/imap4d/expunge.exp
+++ b/imap4d/testsuite/imap4d/expunge.exp
@@ -38,7 +38,7 @@ imap4d_test "SELECT mbox1" \
 "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" \
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags" \
 "OK"
 
 imap4d_test "STORE 2:* +FLAGS (\\Deleted)"\
@@ -66,7 +66,7 @@ imap4d_test "SELECT mbox1" \
 "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" \
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags" \
 "OK"
 
 imap4d_stop
diff --git a/imap4d/testsuite/imap4d/fetch.exp b/imap4d/testsuite/imap4d/fetch.exp
index 33f5131..dedcc5d 100644
--- a/imap4d/testsuite/imap4d/fetch.exp
+++ b/imap4d/testsuite/imap4d/fetch.exp
@@ -37,7 +37,7 @@ imap4d_test "SELECT mbox1" \
 "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" \
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags" \
 "OK"
 
 # FLAGS          The flags that are set for this message.
diff --git a/imap4d/testsuite/imap4d/search.exp b/imap4d/testsuite/imap4d/search.exp
index 47acab3..dc55e9a 100644
--- a/imap4d/testsuite/imap4d/search.exp
+++ b/imap4d/testsuite/imap4d/search.exp
@@ -40,7 +40,7 @@ imap4d_test "SELECT INBOX"\
 "OK \[UIDNEXT 9\] Predicted next uid"\
 "OK \[UNSEEN 4\] first unseen messsage "\
 "FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)"\
-"OK \[PERMANENTFLAGS (\\Answered \\Deleted \\Seen)\] Permanent flags"\
+"OK \[PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)\] Permanent flags"\
 "OK \[READ-WRITE\] SELECT Completed"
 
 # <message set>  Messages with message sequence numbers
diff --git a/include/mailutils/attribute.h b/include/mailutils/attribute.h
index 5b0f296..3bd0a33 100644
--- a/include/mailutils/attribute.h
+++ b/include/mailutils/attribute.h
@@ -97,7 +97,7 @@ extern int mu_attribute_is_equal        (mu_attribute_t, mu_attribute_t att2);
 extern int mu_attribute_copy            (mu_attribute_t, mu_attribute_t);
 
 /* Maximum size of buffer for mu_attribute_to_string call, including nul */
-#define MU_STATUS_BUF_SIZE sizeof("OAFRd")
+#define MU_STATUS_BUF_SIZE sizeof("AFDdOR")
   
 extern int mu_attribute_to_string       (mu_attribute_t, char *, size_t, size_t *);
 extern int mu_string_to_flags           (const char *, int *);
diff --git a/libmailutils/mailbox/attribute.c b/libmailutils/mailbox/attribute.c
index 321491e..8f9b979 100644
--- a/libmailutils/mailbox/attribute.c
+++ b/libmailutils/mailbox/attribute.c
@@ -396,11 +396,12 @@ struct flagtrans
 #define mu_verify(R) extern int (* verify_function__ (void)) [mu_verify_true (R)]
 
 static struct flagtrans flagtrans[] = {
-  { MU_ATTRIBUTE_SEEN, 'O' },
   { MU_ATTRIBUTE_ANSWERED, 'A' },
   { MU_ATTRIBUTE_FLAGGED, 'F' },
+  { MU_ATTRIBUTE_DELETED, 'D' },
+  { MU_ATTRIBUTE_DRAFT, 'd' },
+  { MU_ATTRIBUTE_SEEN, 'O' },
   { MU_ATTRIBUTE_READ, 'R' },
-  { MU_ATTRIBUTE_DELETED, 'd' },
   { 0 }
 };
 
diff --git a/maidag/tests/forward.at b/maidag/tests/forward.at
index bed72d7..5413d60 100644
--- a/maidag/tests/forward.at
+++ b/maidag/tests/forward.at
@@ -23,8 +23,9 @@ m4_pushdef([FORWARD_OPTIONS],[dnl
  --set "^forward-file-checks=none"])
 
 AT_CHECK([
+test -w / && AT_SKIP_TEST
 forward=`pwd`/my.forward
-namelist=`sed 's/:.*//;3,$d' /etc/passwd 2>/dev/null`
+namelist=`sed '/^#/d;s/:.*//' /etc/passwd | sed '3,$d'`
 test -n "$namelist" || AT_SKIP_TEST
 
 cat > my.forward <<EOT
diff --git a/maidag/util.c b/maidag/util.c
index 4064882..8d46dcc 100644
--- a/maidag/util.c
+++ b/maidag/util.c
@@ -73,6 +73,8 @@ maidag_error (const char *fmt, ...)
       vfprintf (stderr, fmt, ap);
       fputc ('\n', stderr);
     }
+  va_end (ap);
+  va_start (ap, fmt);
   mu_verror (fmt, ap);
   va_end (ap);
 }
diff --git a/mh/ali.c b/mh/ali.c
index 3f0bbab..facbef6 100644
--- a/mh/ali.c
+++ b/mh/ali.c
@@ -128,24 +128,23 @@ ali_print_name_list (mu_list_t list, int off)
     {
       int ncol = getcols ();
       int n = off;
+      int i = 0;
       
-      mu_iterator_first (itr);
-
-      for (;;)
+      for (mu_iterator_first (itr), i = 0;
+	   !mu_iterator_is_done (itr);
+	   mu_iterator_next (itr), i++)
 	{
 	  int len;
 
+	  if (i > 0)
+	    n += printf (", ");
+	  
 	  mu_iterator_current (itr, (void **)&item);
 	  len = strlen (item) + 2;
 	  if (n + len > ncol)
 	    n = printf ("\n ");
 
 	  len = printf ("%s", item);
-	  mu_iterator_next (itr);
-	  if (!mu_iterator_is_done (itr))
-	    len += printf (", ");
-	  else
-	    break;
 	  n += len;
 	}
       printf ("\n");
diff --git a/mh/mh_whatnow.c b/mh/mh_whatnow.c
index 85a13d6..ad27490 100644
--- a/mh/mh_whatnow.c
+++ b/mh/mh_whatnow.c
@@ -427,12 +427,12 @@ quit (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
 	unlink (wh->draftfile);
       else
 	{
-	  mu_printf (_("draft left on \"%s\".\n"), wh->draftfile);
+	  mu_printf (_("draft left on \"%s\"."), wh->draftfile);
 	  if (strcmp (wh->file, wh->draftfile))
 	    rename (wh->file, wh->draftfile);
 	}
     }
-
+  mu_printf ("\n");
   return 1;
 }
 
diff --git a/mh/tests/ali.at b/mh/tests/ali.at
index 4686aa8..21372a2 100644
--- a/mh/tests/ali.at
+++ b/mh/tests/ali.at
@@ -75,7 +75,7 @@ ali: mh_aliases2:2: `mh_aliases' already included at top level
 ])
 
 MH_CHECK([ali: group name],[ali04 ali-group-name],[
-awk -F : '$4!="" { print $1; print $4; exit 0 }' /etc/group > tmpout
+cat /etc/group | awk -F : '/^#/ { next } $4!="" { print $1; print $4; exit 0 }' > tmpout
 test -s tmpout || AT_SKIP_TEST
 sed -n '1s/.*/korzen: =&/p' tmpout > mh_aliases
 sed '1d' tmpout | tr -d ' ' > expout
@@ -85,14 +85,12 @@ ali -a ./mh_aliases korzen | tr -d ' '
 [expout])
 
 MH_CHECK([ali: group id],[ali05 ali-group-id ali-gid],[
-awk -F : '$4==0 { print $1 }' /etc/passwd > expout
+cat /etc/passwd | awk -F : '/^#/ { next } $4==0 { print $1 }' > expout
 test -s expout || AT_SKIP_TEST
-name=`awk -F : '$3==0 { print $1 }' /etc/group`
+name=`awk -F : '/^#/ { next } $3==0 { print $1 }' /etc/group < /dev/null`
 test -z "$name" && AT_SKIP_TEST
 
-AT_DATA([mh_aliases],[
-korzen: +root
-])
+echo "korzen: +$name" > mh_aliases
 # FIXME: Do I need to sort the output?
 ali -list -a ./mh_aliases korzen
 ],
@@ -100,7 +98,7 @@ ali -list -a ./mh_aliases korzen
 [expout])
 
 MH_CHECK([ali: everybody],[ali06 ali-everybody],[
-awk -F : '$3>200 { print $1 }' /etc/passwd > expout
+cat /etc/passwd | awk -F : '/^#/ { next } $3>200 { print $1 }' > expout
 test -s expout || AT_SKIP_TEST
 AT_DATA([mh_aliases],[
 everybody: *
diff --git a/mh/tests/anno.at b/mh/tests/anno.at
index 25bed09..a6d97ad 100644
--- a/mh/tests/anno.at
+++ b/mh/tests/anno.at
@@ -22,7 +22,7 @@ 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
+sed -n '1{s/Replied: .*/REPLIED/p;}' Mail/inbox/1
 ],
 [0],
 [REPLIED
@@ -32,7 +32,7 @@ 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
+sed -n '1{s/Replied: .*/REPLIED/p;}' Mail/inbox/1
 ],
 [0],
 [REPLIED
@@ -42,7 +42,7 @@ 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
+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
@@ -53,7 +53,7 @@ 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
+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
diff --git a/mh/tests/atlocal.in b/mh/tests/atlocal.in
index 6a38c2b..18e9d84 100644
--- a/mh/tests/atlocal.in
+++ b/mh/tests/atlocal.in
@@ -35,5 +35,5 @@ awk '
   } else
     print
 }
-' $*
+' $* </dev/null
 }
diff --git a/mh/tests/comp.at b/mh/tests/comp.at
index b264f25..88f423d 100644
--- a/mh/tests/comp.at
+++ b/mh/tests/comp.at
@@ -49,7 +49,8 @@ cc:
 Subject:
 --------
 -- Input file end
-What now?])
+What now?
+])
 
 MH_CHECK([comp file],[comp02 comp_file],[
 echo 'quit' | compcmd file | remove_curdir | sed 's/ *$//'
diff --git a/mh/tests/mark.at b/mh/tests/mark.at
index 3646e6c..8072dc7 100644
--- a/mh/tests/mark.at
+++ b/mh/tests/mark.at
@@ -22,7 +22,7 @@ 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
+sed -n '/^andro:/{s/  */ /g;s/ $//;p;}' Mail/inbox/.mh_sequences
 ],
 [0],
 [andro: 2 3 4 5
@@ -32,9 +32,9 @@ 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
+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
+sed -n '/^andro:/{s/  */ /g;s/ $//;p;}' Mail/inbox/.mh_sequences
 ],
 [0],
 [andro: 2
@@ -45,7 +45,7 @@ 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
-sed -n '/^atr-andro/{s/  */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p}' Mail/context
+sed -n '/^atr-andro/{s/  */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p;}' Mail/context
 ],
 [0],
 [atr-andro: 1 2 3
@@ -56,7 +56,7 @@ 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
+sed -n '/^andro:/{s/  */ /g;s/ $//;p;}' Mail/inbox/.mh_sequences
 ],
 [0],
 [andro: 2 4 5
@@ -70,7 +70,7 @@ 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
+sed -n '/^atr-andro/{s/  */ /g;s/ $//;s/^[[^:]]*:/atr-andro:/;p;}' Mail/context
 ],
 [0],
 [atr-andro: 2 4 5
diff --git a/mh/tests/mhn.at b/mh/tests/mhn.at
index d55d4e7..74b96db 100644
--- a/mh/tests/mhn.at
+++ b/mh/tests/mhn.at
@@ -337,7 +337,7 @@ MH_CHECK([mhn-show type=tar],[mhn13 mhn-show-type=tar],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 AT_DATA([filter.awk],[
 /^X-IMAPbase/ { next }
-/^-rw-r--r--/ { print $1, $2, $3, $6; next }
+/^-rw-r--r--/ { print $NF; next }
 { print }
 ])
 mhn -show 2 | awk -f filter.awk
@@ -355,8 +355,8 @@ X-Envelope-Sender: gray@example.net
 part     1 text/plain               15
 Initial text.
 
--rw-r--r-- gray/staff 1418 Father_William
--rw-r--r-- gray/staff 937 Jabberwocky
+Father_William
+Jabberwocky
 ])
 
 # FIXME: What about exit code?
@@ -388,7 +388,7 @@ MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 echo "mhn-show-application/x-tar: %ltar tvf '%F'" >> $MH
 AT_DATA([filter.awk],[
 /^X-IMAPbase/ { next }
-/^-rw-r--r--/ { print $1, $2, $3, $6; next }
+/^-rw-r--r--/ { print $NF; next }
 { sub(/  *$/,"");  print }
 ])
 mhn -show 1 | awk -f filter.awk
@@ -407,8 +407,8 @@ part     1 text/plain               15
 Initial text.
 
 part     2 application/x-tar        13835
--rw-r--r-- gray/staff 1418 Father_William
--rw-r--r-- gray/staff 937 Jabberwocky
+Father_William
+Jabberwocky
 ])
 
 MH_CHECK([mhn-show- variable (without subtype)],
@@ -417,7 +417,7 @@ MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mime,[Mail/inbox],[700])
 echo "mhn-show-application: %ltar tvf '%F'" >> $MH
 AT_DATA([filter.awk],[
 /^X-IMAPbase/ { next }
-/^-rw-r--r--/ { print $1, $2, $3, $6; next }
+/^-rw-r--r--/ { print $NF; next }
 { sub(/  *$/,"");  print }
 ])
 mhn -show 1 | awk -f filter.awk
@@ -436,8 +436,8 @@ part     1 text/plain               15
 Initial text.
 
 part     2 application/x-tar        13835
--rw-r--r-- gray/staff 1418 Father_William
--rw-r--r-- gray/staff 937 Jabberwocky
+Father_William
+Jabberwocky
 ])
 
 dnl -------------------------------------------------------------------
diff --git a/mh/tests/pick.at b/mh/tests/pick.at
index 726b4bd..81ffe75 100644
--- a/mh/tests/pick.at
+++ b/mh/tests/pick.at
@@ -46,7 +46,7 @@ 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
+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
diff --git a/testsuite/testsuite.inc b/testsuite/testsuite.inc
index 64407a0..02c89a0 100644
--- a/testsuite/testsuite.inc
+++ b/testsuite/testsuite.inc
@@ -27,7 +27,7 @@ dnl
 m4_define([MUT_VERSION],[
 AT_SETUP([$1 version])
 
-AT_CHECK([$1 --version | sed '1{s/ *[\[.*\]]//;q}' ],
+AT_CHECK([$1 --version | sed '1{s/ *[\[.*\]]//;q;}' ],
          [0],
          [$1 (AT_PACKAGE_NAME) AT_PACKAGE_VERSION
 ],


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Oct 23 17:22:00 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RI5UW-0001b7-6M
	for mharc-commit-mailutils@gnu.org; Sun, 23 Oct 2011 17:22:00 -0400
Received: from eggs.gnu.org ([140.186.70.92]:46742)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RI5UT-0001af-34
	for commit-mailutils@gnu.org; Sun, 23 Oct 2011 17:21:58 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RI5UQ-0000ST-LL
	for commit-mailutils@gnu.org; Sun, 23 Oct 2011 17:21:56 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:33589)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RI5UQ-0000SO-Jk
	for commit-mailutils@gnu.org; Sun, 23 Oct 2011 17:21:54 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RI5UQ-0003Su-0o
	for commit-mailutils@gnu.org; Sun, 23 Oct 2011 21:21:54 +0000
Date: Sun, 23 Oct 2011 21:21:54 +0000
Message-Id: <E1RI5UQ-0003Su-0o@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-405-gab65195
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 09372ddfbaeb45facface67dea795f8e9059d899
X-Git-Newrev: ab651950ab94c6c8e228b42897abb38a83351b23
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 23 Oct 2011 21:21:58 -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=ab651950ab94c6c8e228b42897abb38a83351b23

The branch, master has been updated
       via  ab651950ab94c6c8e228b42897abb38a83351b23 (commit)
       via  39b00209c02e1ff1b96b2fc12cbc5b1684e25374 (commit)
      from  09372ddfbaeb45facface67dea795f8e9059d899 (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 ab651950ab94c6c8e228b42897abb38a83351b23
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 24 00:20:49 2011 +0300

    imap4d: fix reading multi-line literals
    
    * imap4d/io.c (imap4d_tokbuf_decrlf): New function.
    (imap4d_tokbuf_expand): Call imap4d_tokbuf_decrlf for
    literals.

commit 39b00209c02e1ff1b96b2fc12cbc5b1684e25374
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 24 00:19:09 2011 +0300

    Minor change.
    
    * mh/tests/atlocal.in (mimeflt): ignore stderr, instead of reading input
    from /dev/null, because this function can theoretically be used as a filter.

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

Summary of changes:
 imap4d/io.c         |   20 ++++++++++++++++++++
 mh/tests/atlocal.in |    7 ++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/imap4d/io.c b/imap4d/io.c
index 6c1c375..4fad3c3 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -416,6 +416,25 @@ imap4d_tokbuf_unquote (struct imap4d_tokbuf *tok, size_t *poff, size_t *plen)
 }
 
 static void
+imap4d_tokbuf_decrlf (struct imap4d_tokbuf *tok, size_t off, size_t *plen)
+{
+  char *buf = tok->buffer + off;
+  size_t len = *plen;
+  char *p, *end = buf + len;
+
+  for (p = end - 1; p > buf; p--)
+    {
+      if (*p == '\n' && p > buf && p[-1] == '\r')
+	{
+	  memmove (p - 1, p, end - p);
+	  end--;
+	  p--;
+	}
+    }
+  *plen = end - buf;
+}	  
+
+static void
 imap4d_tokbuf_expand (struct imap4d_tokbuf *tok, size_t size)
 {
   if (tok->size - tok->level < size)	       
@@ -596,6 +615,7 @@ imap4d_readline (struct imap4d_tokbuf *tok)
             }
 	  check_input_err (rc, len);
 	  imap4d_tokbuf_unquote (tok, &off, &len);
+	  imap4d_tokbuf_decrlf (tok, off, &len);
 	  tok->level += len;
 	  tok->buffer[tok->level++] = 0;
 	  tok->argp[tok->argc - 1] = off;
diff --git a/mh/tests/atlocal.in b/mh/tests/atlocal.in
index 18e9d84..e21d477 100644
--- a/mh/tests/atlocal.in
+++ b/mh/tests/atlocal.in
@@ -11,6 +11,11 @@ remove_curdir() {
 # If FILE is not given, filter stdin.
 # "Variable information" means part boundary and Content-ID header values.
 # These elements are likely to change between invocations of mhn -build.
+#
+# Stderr is redirected to /dev/null because "one true awk" (used, in
+# particular, on FreeBSD) complains when closing stdin fails, even if
+# it did not use it at all (it fails because stdin is closed earlier by
+# MH_SETUP).
 mimeflt() {
 awk '
 /^Content-Type:/ {
@@ -35,5 +40,5 @@ awk '
   } else
     print
 }
-' $* </dev/null
+' $* 2>/dev/null
 }


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 24 03:49:16 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RIFHY-0001bl-BX
	for mharc-commit-mailutils@gnu.org; Mon, 24 Oct 2011 03:49:16 -0400
Received: from eggs.gnu.org ([140.186.70.92]:53176)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIFHV-0001az-Nb
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 03:49:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIFHU-00084a-6T
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 03:49:13 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:41076)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIFHU-00084W-4G
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 03:49:12 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIFHS-0003wO-VB
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 07:49:11 +0000
Date: Mon, 24 Oct 2011 07:49:11 +0000
Message-Id: <E1RIFHS-0003wO-VB@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-406-g1e9173d
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: ab651950ab94c6c8e228b42897abb38a83351b23
X-Git-Newrev: 1e9173dfbe7a22b8073fe2a5f6559612d24f67e6
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 24 Oct 2011 07:49:15 -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=1e9173dfbe7a22b8073fe2a5f6559612d24f67e6

The branch, master has been updated
       via  1e9173dfbe7a22b8073fe2a5f6559612d24f67e6 (commit)
      from  ab651950ab94c6c8e228b42897abb38a83351b23 (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 1e9173dfbe7a22b8073fe2a5f6559612d24f67e6
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 24 10:23:55 2011 +0300

    Complement 1e33c774.
    
    * mh/comp.c: Open mailbox in read-only mode.

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

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

diff --git a/mh/comp.c b/mh/comp.c
index 9d08e1f..336b348 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -276,7 +276,7 @@ main (int argc, char **argv)
       mh_msgset_t msgset;
       mu_mailbox_t mbox;
       
-      mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
+      mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
       mh_msgset_parse (mbox, &msgset, argc - index, argv + index, "cur");
       if (msgset.count != 1)
 	{


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 24 15:44:19 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RIQRX-00050R-BT
	for mharc-commit-mailutils@gnu.org; Mon, 24 Oct 2011 15:44:19 -0400
Received: from eggs.gnu.org ([140.186.70.92]:32807)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIQRO-0004cL-PZ
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 15:44:17 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIQRH-0003LV-3q
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 15:44:10 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:46856)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIQRG-0003LQ-Mu
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 15:44:02 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIQRG-0006bR-5y
	for commit-mailutils@gnu.org; Mon, 24 Oct 2011 19:44:02 +0000
Date: Mon, 24 Oct 2011 19:44:02 +0000
Message-Id: <E1RIQRG-0006bR-5y@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-407-gf70ebb8
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 1e9173dfbe7a22b8073fe2a5f6559612d24f67e6
X-Git-Newrev: f70ebb8c1d67d70222768b34ce7568b78fe191de
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 24 Oct 2011 19:44:17 -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=f70ebb8c1d67d70222768b34ce7568b78fe191de

The branch, master has been updated
       via  f70ebb8c1d67d70222768b34ce7568b78fe191de (commit)
      from  1e9173dfbe7a22b8073fe2a5f6559612d24f67e6 (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 f70ebb8c1d67d70222768b34ce7568b78fe191de
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 24 11:38:42 2011 +0300

    Simplify mu_file_safety_check call.
    
    * include/mailutils/util.h (mu_file_safety_check): Change type
    of the 3rd argument to uid_t.
    * libmailutils/base/filesafety.c: Likewise.  All uses updated.

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

Summary of changes:
 include/mailutils/util.h       |    4 +---
 libmailutils/base/filesafety.c |    6 ++----
 libmu_auth/tls.c               |    6 +++---
 maidag/forward.c               |    2 +-
 4 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index a1d4159..fcc11ac 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -220,10 +220,8 @@ int mu_onexit (mu_onexit_t func, void *data);
   MU_FILE_SAFETY_DIR_IWOTH      )
   
 
-struct mu_auth_data;
-
 int mu_file_safety_check (const char *filename, int mode,
-			  struct mu_auth_data *auth,
+			  uid_t uid,
 			  mu_list_t idlist);
 int mu_file_safety_name_to_code (const char *name, int *pcode);
 int mu_file_safety_name_to_error (const char *name, int *pcode);  
diff --git a/libmailutils/base/filesafety.c b/libmailutils/base/filesafety.c
index 5bf2820..6de1e9a 100644
--- a/libmailutils/base/filesafety.c
+++ b/libmailutils/base/filesafety.c
@@ -191,7 +191,7 @@ mu_file_safety_name_to_error (const char *name, int *pcode)
 
 int
 mu_file_safety_check (const char *filename, int mode,
-		      struct mu_auth_data *auth,
+		      uid_t uid,
 		      mu_list_t idlist)
 {
   struct file_check_buffer buf;
@@ -209,9 +209,7 @@ mu_file_safety_check (const char *filename, int mode,
 	    return MU_ERR_EXISTS;
 	}
 
-      if ((mode & MU_FILE_SAFETY_OWNER_MISMATCH) &&
-	  auth &&
-	  auth->uid != buf.filst.st_uid)
+      if ((mode & MU_FILE_SAFETY_OWNER_MISMATCH) && uid != buf.filst.st_uid)
 	return MU_ERR_PERM_OWNER_MISMATCH;
 
       for (pck = file_safety_check_tab; pck->flag; pck++)
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index d140cb7..b225921 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -74,7 +74,7 @@ mu_check_tls_environment (void)
     {
       int rc = mu_file_safety_check (mu_tls_module_config.ssl_cert,
 				     mu_tls_module_config.ssl_cert_safety_checks,
-				     NULL, NULL);
+				     -1, NULL);
       if (rc)
 	{
 	  mu_error ("%s: %s", mu_tls_module_config.ssl_cert, 
@@ -83,7 +83,7 @@ mu_check_tls_environment (void)
 	}
       rc = mu_file_safety_check (mu_tls_module_config.ssl_key,
 				 mu_tls_module_config.ssl_key_safety_checks,
-				 NULL, NULL);
+				 -1, NULL);
       if (rc)
 	{
 	  mu_error ("%s: %s", mu_tls_module_config.ssl_key, 
@@ -93,7 +93,7 @@ mu_check_tls_environment (void)
 
       rc = mu_file_safety_check (mu_tls_module_config.ssl_cafile,
 				 mu_tls_module_config.ssl_cafile_safety_checks,
-				 NULL, NULL);
+				 -1, NULL);
       if (rc)
 	{
 	  mu_error ("%s: %s", mu_tls_module_config.ssl_cafile, 
diff --git a/maidag/forward.c b/maidag/forward.c
index a1b8697..5dfdc41 100644
--- a/maidag/forward.c
+++ b/maidag/forward.c
@@ -213,7 +213,7 @@ maidag_forward (mu_message_t msg, struct mu_auth_data *auth, char *fwfile)
     mu_list_create (&idlist);
 
   rc = mu_file_safety_check (filename, forward_file_checks,
-			     auth, idlist);
+			     auth->uid, idlist);
   if (rc == 0)
     result = process_forward (msg, filename, auth->name);
   else if (rc == MU_ERR_EXISTS)


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Oct 25 14:28:39 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RIljr-0002A6-JT
	for mharc-commit-mailutils@gnu.org; Tue, 25 Oct 2011 14:28:39 -0400
Received: from eggs.gnu.org ([140.186.70.92]:32861)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIljf-00029d-Mf
	for commit-mailutils@gnu.org; Tue, 25 Oct 2011 14:28:37 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIljU-0000Lx-TY
	for commit-mailutils@gnu.org; Tue, 25 Oct 2011 14:28:27 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:36670)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIljU-0000Lr-Nx
	for commit-mailutils@gnu.org; Tue, 25 Oct 2011 14:28:16 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RIljF-0003hP-0D
	for commit-mailutils@gnu.org; Tue, 25 Oct 2011 18:28:12 +0000
Date: Tue, 25 Oct 2011 18:28:01 +0000
Message-Id: <E1RIljF-0003hP-0D@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-409-g442711b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: f70ebb8c1d67d70222768b34ce7568b78fe191de
X-Git-Newrev: 442711bcda49eeca667d15c509d200995379c832
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Tue, 25 Oct 2011 18:28: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=442711bcda49eeca667d15c509d200995379c832

The branch, master has been updated
       via  442711bcda49eeca667d15c509d200995379c832 (commit)
       via  0cb608de0ac37bfe71e06f4d592c232c78ac4db1 (commit)
      from  f70ebb8c1d67d70222768b34ce7568b78fe191de (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 442711bcda49eeca667d15c509d200995379c832
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Oct 25 21:27:45 2011 +0300

    Use MU_CTYPE_ENDLN to trim \r\n.

commit 0cb608de0ac37bfe71e06f4d592c232c78ac4db1
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Oct 25 15:19:46 2011 +0300

    Reimplement DBM support.
    
    * lib/mu_dbm.c: Remove.
    * lib/mu_dbm.h: Remove.
    * lib/Makefile.am: Remove mu_dbm.[ch].
    * include/mailutils/sys/dbm.h: New file.
    * include/mailutils/sys/Makefile.am: Add dbm.h
    * include/mailutils/dbm.h: New file.
    * include/mailutils/Makefile.am (pkginclude_HEADERS): Add dbm.h.
    * include/mailutils/types.hin (mu_dbm_file_t): New data type.
    
    * libmu_dbm/Makefile.am: New file.
    * libmu_dbm/berkeley.c: New file.
    * libmu_dbm/close.c: New file.
    * libmu_dbm/create.c: New file.
    * libmu_dbm/datumfree.c: New file.
    * libmu_dbm/dbm.c: New file.
    * libmu_dbm/delete.c: New file.
    * libmu_dbm/destroy.c: New file.
    * libmu_dbm/errstr.c: New file.
    * libmu_dbm/fetch.c: New file.
    * libmu_dbm/firstkey.c: New file.
    * libmu_dbm/gdbm.c: New file.
    * libmu_dbm/mudbm.h: New file.
    * libmu_dbm/ndbm.c: New file.
    * libmu_dbm/nextkey.c: New file.
    * libmu_dbm/open.c: New file.
    * libmu_dbm/safety.c: New file.
    * libmu_dbm/store.c: New file.
    
    * Makefile.am [MU_COND_DBM]: Define LIBMU_DBM_DIR
    (SUBDIRS): Add $(LIBMU_DBM_DIR)
    * configure.ac: Revamp DBM support: several database types can
    be specified at once.
    (AC_CONFIG_FILES): Build libmu_dbm/Makefile
    
    * libmu_sieve/extensions/vacation.c: Remove inclusion of mu_dbm.h.
    * maidag/Makefile.am (maidag_LDADD): Add DBM libraries.
    * maidag/maidag.c: ENABLE_DBM instead of USE_DBM
    * maidag/maidag.h: Include <mailutils/dbm.h> instead of mu_dbm.h.
    * maidag/mailquota.c (dbm_retrieve_quota): Rewrite using libmu_dbm
    library calls.
    * mu/Makefile.am [MU_COND_DBM]: Define DBM_C.
    (MODULES): Add $(DBM_C).
    (AM_CPPFLAGS): Define DBMLIBS.
    * mu/ldflags.c (NEEDAUTH): Change definition.
    (lib_descr) <weight>: New member. All uses changed.
    (add_entry): Null arguments ignored.
    (mutool_ldflags): Rewrite traversal of lib_descr.
    * mu/dbm.c: New file.
    
    * pop3d/Makefile.am (pop3d_LDADD, popauth_LDADD): Add DBM libraries.
    * pop3d/apop.c: Rewrite using libmu_dbm library calls.
    * pop3d/bulletin.c: Likewise.
    * pop3d/logindelay.c: Likewise.
    * pop3d/pop3d.c: Change USE_DBM to ENABLE_DBM.
    * pop3d/pop3d.h: Include mailutils/dbm.h instead of mu_dbm.h
    * pop3d/popauth.c: Rewrite using libmu_dbm library calls.
    
    * include/mailutils/cctype.h (MU_CTYPE_ENDLN): New character class.
    (mu_isendln): New macro.
    * libmailutils/string/muctype.c (mu_c_tab): Mark \r and \n as
    MU_CTYPE_ENDLN.

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

Summary of changes:
 Makefile.am                                        |    5 +
 configure.ac                                       |  322 +++++----
 imap4d/io.c                                        |    2 +-
 imap4d/preauth.c                                   |    2 +-
 include/mailutils/Makefile.am                      |    1 +
 include/mailutils/cctype.h                         |    2 +
 include/mailutils/dbm.h                            |   77 ++
 include/mailutils/sys/Makefile.am                  |    1 +
 include/mailutils/{radius.h => sys/dbm.h}          |   26 +-
 include/mailutils/types.hin                        |    4 +-
 lib/Makefile.am                                    |    2 -
 lib/mu_dbm.c                                       |  575 ---------------
 lib/mu_dbm.h                                       |   89 ---
 libmailutils/string/muctype.c                      |    4 +-
 {libproto/imap => libmu_dbm}/Makefile.am           |   50 +-
 libmu_dbm/berkeley.c                               |  340 +++++++++
 lib/argp_base.c => libmu_dbm/close.c               |   19 +-
 libproto/imap/capatst.c => libmu_dbm/create.c      |   22 +-
 libmailutils/cidr/match.c => libmu_dbm/datumfree.c |   24 +-
 libmu_dbm/dbm.c                                    |  265 +++++++
 libmailutils/cidr/match.c => libmu_dbm/delete.c    |   25 +-
 libmailutils/cidr/match.c => libmu_dbm/destroy.c   |   27 +-
 .../sockaddr/unlink.c => libmu_dbm/errstr.c        |   34 +-
 libproto/imap/capatst.c => libmu_dbm/fetch.c       |   21 +-
 libmailutils/cidr/match.c => libmu_dbm/firstkey.c  |   24 +-
 libmu_dbm/gdbm.c                                   |  290 ++++++++
 libmailutils/cidr/match.c => libmu_dbm/getfd.c     |   24 +-
 libproto/nntp/url.c => libmu_dbm/mudbm.h           |   54 +-
 libmu_dbm/ndbm.c                                   |  244 +++++++
 libmailutils/cidr/match.c => libmu_dbm/nextkey.c   |   24 +-
 libmailutils/cidr/match.c => libmu_dbm/open.c      |   26 +-
 libproto/imap/create.c => libmu_dbm/safety.c       |   69 +-
 libproto/imap/capatst.c => libmu_dbm/store.c       |   20 +-
 libmu_sieve/extensions/spamd.c                     |    2 +-
 libmu_sieve/extensions/vacation.c                  |    1 -
 libproto/mailer/smtp_io.c                          |    4 +-
 libproto/mbox/mbox.c                               |    5 +-
 libproto/pop/mbox.c                                |    2 +-
 maidag/Makefile.am                                 |    2 +
 maidag/lmtp.c                                      |    2 +-
 maidag/maidag.c                                    |    2 +-
 maidag/maidag.h                                    |    5 +-
 maidag/mailquota.c                                 |   78 ++-
 mu/Makefile.am                                     |   12 +-
 mu/dbm.c                                           |  751 ++++++++++++++++++++
 mu/ldflags.c                                       |   82 ++--
 pop3d/Makefile.am                                  |   20 +-
 pop3d/apop.c                                       |   66 ++-
 pop3d/bulletin.c                                   |  142 ++--
 pop3d/logindelay.c                                 |  103 ++-
 pop3d/pop3d.c                                      |    4 +-
 pop3d/pop3d.h                                      |    4 +-
 pop3d/popauth.c                                    |  378 +++++++----
 53 files changed, 2981 insertions(+), 1398 deletions(-)
 create mode 100644 include/mailutils/dbm.h
 copy include/mailutils/{radius.h => sys/dbm.h} (60%)
 delete mode 100644 lib/mu_dbm.c
 delete mode 100644 lib/mu_dbm.h
 copy {libproto/imap => libmu_dbm}/Makefile.am (56%)
 create mode 100644 libmu_dbm/berkeley.c
 copy lib/argp_base.c => libmu_dbm/close.c (72%)
 copy libproto/imap/capatst.c => libmu_dbm/create.c (66%)
 copy libmailutils/cidr/match.c => libmu_dbm/datumfree.c (69%)
 create mode 100644 libmu_dbm/dbm.c
 copy libmailutils/cidr/match.c => libmu_dbm/delete.c (71%)
 copy libmailutils/cidr/match.c => libmu_dbm/destroy.c (70%)
 copy libmailutils/sockaddr/unlink.c => libmu_dbm/errstr.c (67%)
 copy libproto/imap/capatst.c => libmu_dbm/fetch.c (70%)
 copy libmailutils/cidr/match.c => libmu_dbm/firstkey.c (71%)
 create mode 100644 libmu_dbm/gdbm.c
 copy libmailutils/cidr/match.c => libmu_dbm/getfd.c (71%)
 copy libproto/nntp/url.c => libmu_dbm/mudbm.h (52%)
 create mode 100644 libmu_dbm/ndbm.c
 copy libmailutils/cidr/match.c => libmu_dbm/nextkey.c (71%)
 copy libmailutils/cidr/match.c => libmu_dbm/open.c (71%)
 copy libproto/imap/create.c => libmu_dbm/safety.c (52%)
 copy libproto/imap/capatst.c => libmu_dbm/store.c (68%)
 create mode 100644 mu/dbm.c

diff --git a/Makefile.am b/Makefile.am
index 33f8fcf..8d2f5ab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -83,6 +83,10 @@ if MU_COND_SUPPORT_CXX
   LIBMU_CPP_DIR = libmu_cpp
 endif
 
+if MU_COND_DBM
+  LIBMU_DBM_DIR = libmu_dbm
+endif
+
 SUBDIRS = . \
  mu-aux\
  include\
@@ -99,6 +103,7 @@ SUBDIRS = . \
  $(LIBMU_CPP_DIR)\
  $(GINT_DIR)\
  $(LIBMU_SCM_DIR)\
+ $(LIBMU_DBM_DIR)\
  libmu_sieve\
  $(PYTHON_DIR)\
  doc\
diff --git a/configure.ac b/configure.ac
index 8adfb8d..eaaea12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,7 +88,7 @@ AM_PROG_LIBTOOL
 ## Predefine several variables used to display configuration status
 status_pam=no
 status_ltdl=no
-status_dbm=no
+status_dbm=
 status_gsasl=no
 status_mysql=no
 status_pgsql=no
@@ -354,22 +354,31 @@ AH_BOTTOM(
 # define MU_PATH_MAILDIR PATH_MAILDIR "/"
 #endif])
 
-use_dbm=no
+##################################
+# DBM Support
+##################################
+AC_SUBST(DBMLIBS)
+AC_SUBST(DBMLIB_DEPENDENCY)
+AC_SUBST(DBMINCLUDES)
+
+enable_dbm=no
+disable_dbm=no
+
 AC_ARG_WITH([gdbm],
             AC_HELP_STRING([--with-gdbm],
                            [use GNU DBM]),
             [
 case "${withval}" in
-  yes) use_dbm=GDBM ;;
-  no)  use_dbm=no ;;
+  yes) enable_dbm="$enable_dbm GDBM";;
+  no)  disable_dbm="$disable_dbm GDBM";;
   *)   AC_MSG_ERROR(bad value ${withval} for --with-gdbm) ;;
 esac])
 
 ## Support --with-db2 for backward compatibility
 if test "${with_db2+set}" = set; then
   case "${with_db2}" in
-  yes) use_dbm=BDB2 ;;
-  no)  use_dbm=no ;;
+  yes) enable_dbm="$enable_dbm BDB2";;
+  no)  disable_dbm="$disable_dbm BDB2";;
   *)   AC_MSG_ERROR(bad value ${with_db2} for --with-db2) ;;
   esac
 fi
@@ -379,9 +388,9 @@ AC_ARG_WITH([berkeley-db],
                            [use Berkeley DB]),
             [
 case "${withval}" in
-  yes) use_dbm=BDB ;;
-  no)  use_dbm=no ;;
-  *)   use_dbm=BDB="${withval}";;
+  yes) enable_dbm="$enable_dbm BDB";;
+  no)  disable_dbm="$disable_dbm BDB";;
+  *)   enable_dbm="$enable_dbm BDB=${withval}";;
 esac])
 
 AC_ARG_WITH([ndbm],
@@ -389,8 +398,8 @@ AC_ARG_WITH([ndbm],
                            [use NDBM]),
             [
 case "${withval}" in
-  yes) use_dbm=NDBM ;;
-  no)  use_dbm=no ;;
+  yes) enable_dbm="$enable_dbm NDBM";;
+  no)  disable_dbm="$disable_dbm NDBM";;
   *)   AC_MSG_ERROR(bad value ${withval} for --with-ndbm) ;;
 esac])
 
@@ -399,11 +408,174 @@ AC_ARG_WITH([tokyocabinet],
                            [use Tokyo Cabinet]),
             [
 case "${withval}" in
-  yes) use_dbm=TC ;;
-  no)  use_dbm=no ;;
+  yes) enable_dbm="$enable_dbm TC";;
+  no)  disable_dbm="$disable_dbm TC";;
   *)   AC_MSG_ERROR(bad value ${withval} for --with-tokyocabinet) ;;
 esac])
 
+dnl Check for DBM
+
+AH_TEMPLATE([WITH_BDB],
+            [Define to the major version of Berkeley DB library to use])
+
+status_bdb=no
+
+## Set the variable status_bdb to $1 if:
+##
+##  1. Function $3 is defined in the library $2
+##  2. Header file db.h is available
+##
+## Then check if the major version, minor version and patchlevel of the
+## library matches those from the header. If so, define WITH_BDB
+## to the version (i.e. $1 with all dots removed). Otherwise, report
+## an error and stop.
+##
+check_bdb() {
+        ver=`echo $1 | tr -d '.'`
+	major=`expr $ver : '\(.\).*'`
+	status_bdb=no
+	AC_CHECK_LIB($2, $3,
+                     [AC_CHECK_HEADERS(db.h)
+                      if test $ac_cv_header_db_h = yes; then
+                        DBMLIBS="$DBMLIBS -l$2"
+                        MU_DB2_CURSOR
+                        status_bdb="$1"
+                      fi])
+	if test "$status_bdb" = no; then
+		:
+	else
+	  save_LIBS=$LIBS
+	  LIBS="$LIBS $DBMLIBS"
+	  AC_RUN_IFELSE(
+           [AC_LANG_PROGRAM([#include "db.h"],
+            [int v_major, v_minor, v_patch;
+             db_version(&v_major, &v_minor, &v_patch);
+             return !(DB_VERSION_MAJOR == $major
+                       && v_major == DB_VERSION_MAJOR
+                       && v_minor == DB_VERSION_MINOR
+                       && v_patch == DB_VERSION_PATCH);
+            ])],
+           [],
+           [status_bdb=no])
+	   LIBS=$save_LIBS
+           if test "$status_bdb" != no; then
+	     AC_DEFINE_UNQUOTED(WITH_BDB,$ver)
+           fi
+	fi
+}
+
+## Check for the Berkeley DB library version $1, assuming Slackware-like
+## installation layout (header files in /usr/incude/db$vn and library named
+## libdb-$version.so, where $version is the library version and $vn is
+## $version with all dots removed.
+##
+check_slackware_bdb() {
+	dir=db`echo $1|tr -d '.'`
+	save_CPPFLAGS=$CPPFLAGS
+	CPPFLAGS="$CPPFLAGS -I/usr/include/$dir"
+	check_bdb "$1" db-$1 db_create
+	CPPFLAGS=$save_CPPFLAGS
+	if test "$status_bdb" = "$1"; then
+	    DBMINCLUDES="$DBMINCLUDES -I/usr/include/$dir"
+            status_dbm="$status_dbm,Berkeley DB v. $status_bdb"
+	fi
+}
+
+check_dbm_impl() {
+  case "$1" in
+  GDBM)
+	AC_CHECK_LIB(gdbm, gdbm_open,
+                     [AC_CHECK_HEADERS(gdbm.h,
+                                       AC_DEFINE(WITH_GDBM,1,
+                                                 [Enable use of GNU DBM library]))
+                     DBMLIBS="$DBMLIBS -lgdbm"
+                     status_dbm="$status_dbm,GDBM"]);;
+
+  BDB2)   check_bdb 2 db db_open
+          test -n "$status_bdb" && status_dbm="$status_dbm,Berkeley DB v. $status_bdb";;
+
+  BDB)    for version in 4 3 2
+	  do
+		case $version in
+		4|3) func=db_create;;
+		2)   func=db_open;;
+		esac
+		check_bdb $version db $func
+		if test "$status_bdb" != no; then
+	           status_dbm="$status_dbm,Berkeley DB v. $status_bdb"
+		   break;
+		fi
+	  done;;
+
+  BDB=*)
+	  name=`expr $use_dbm : 'BDB=\(.*\)'`
+  	  case $name in
+	  [[0-9]]*)  check_slackware_bdb $name;;
+	  *)	     for version in 4 3 2
+	             do
+			case $version in
+			4|3) func=db_create;;
+			2)   func=db_open;;
+			esac
+			check_bdb $version $name $func
+			if test "$status_bdb" != no; then
+		           status_dbm="$status_dbm,Berkeley DB v. $status_bdb"
+			   break;
+			fi
+		     done
+		     ;;
+ 	  esac
+          ;;
+
+  NDBM)
+          has_ndbm=no        
+	  AC_CHECK_HEADERS(ndbm.h,[has_ndbm=yes])
+	  if test $has_ndbm = yes; then
+	    AC_CHECK_FUNC(dbm_open,:,[has_ndbm=no])
+	    if test $has_ndbm = no; then
+	      AC_CHECK_LIB(ndbm, dbm_open,
+                           [DBMLIBS="$DBMLIBS -lndbm"])
+	    fi  		    
+          fi
+	  if test $has_ndbm = yes; then
+	    AC_DEFINE(WITH_NDBM,1,[Enable use of NDBM])
+            status_dbm="$status_dbm,NDBM"
+	  fi
+	  ;;
+
+  TC)
+	  AC_CHECK_LIB(tokyocabinet, tchdbnew,
+                       [AC_CHECK_HEADERS(tchdb.h,
+                                         AC_DEFINE(WITH_TOKYOCABINET,1,
+                                                 [Enable use of Tokyo Cabinet]))
+		       DBMLIB_DEPENDENCY="$DBMLIB_DEPENDENCY -lz -lbz2 -lrt"
+                       DBMLIBS="$DBMLIBS -ltokyocabinet"
+                       status_dbm="$status_dbm,Tokyo Cabinet"]);;
+  esac
+}
+
+if test "$enable_dbm" = no; then
+  enable_dbm="GDBM BDB TC NDBM"
+fi
+
+for impl in $enable_dbm
+do
+  if echo "$disable_dbm" | grep $impl >/dev/null; then
+    : # skip it
+  else
+    check_dbm_impl $impl
+  fi
+done
+
+if test -z "$status_dbm"; then
+  status_dbm=no
+else
+  status_dbm=`echo "$status_dbm" | sed 's/^,//'`
+  AC_DEFINE([ENABLE_DBM], 1, [Define if DBM interface is compiled])
+fi
+AM_CONDITIONAL([MU_COND_DBM], [test "$status_dbm" != no])
+
+####################
 AC_MSG_CHECKING(for log facility)
 log_facility="LOG_MAIL"
 AC_ARG_WITH([log-facility],
@@ -938,129 +1110,6 @@ AH_BOTTOM([
 # define rl_completion_matches completion_matches
 #endif])
 
-dnl Check for DBM
-
-AH_TEMPLATE([WITH_BDB],
-            [Define to the major version of Berkeley DB library to use])
-
-## Set the variable status_dbm to $1 if:
-##
-##  1. Function $3 is defined in the library $2
-##  2. Header file db.h is available
-##
-## Then check if the major version, minor version and patchlevel of the
-## library matches those from the header. If so, define WITH_BDB
-## to the version (i.e. $1 with all dots removed). Otherwise, report
-## an error and stop.
-##
-check_bdb() {
-        ver=`echo $1 | tr -d '.'`
-	major=`expr $ver : '\(.\).*'`
-	AC_CHECK_LIB($2, $3,
-                     [AC_CHECK_HEADERS(db.h)
-                      if test $ac_cv_header_db_h = yes; then
-                        LIBS="$LIBS -l$2"
-                        MU_DB2_CURSOR
-                        status_dbm=$1
-                      fi])
-	if test "$status_dbm" = no; then
-		:
-	else
-	  AC_RUN_IFELSE(
-           [AC_LANG_PROGRAM([#include "db.h"],
-            [int v_major, v_minor, v_patch;
-             db_version(&v_major, &v_minor, &v_patch);
-             return !(DB_VERSION_MAJOR == $major
-                       && v_major == DB_VERSION_MAJOR
-                       && v_minor == DB_VERSION_MINOR
-                       && v_patch == DB_VERSION_PATCH);
-            ])],
-           [],
-           [status_dbm=no])
-           if test "$status_dbm" != no; then
-	     AC_DEFINE_UNQUOTED(WITH_BDB,$ver)
-           fi
-	fi
-}
-
-## Check for the Berkeley DB library version $1, assuming Slackware-like
-## installation layout (header files in /usr/incude/db$vn and library named
-## libdb-$version.so, where $version is the library version and $vn is
-## $version with all dots removed.
-##
-check_slackware_bdb() {
-	dir=db`echo $1|tr -d '.'`
-	save_CPPFLAGS=$CPPFLAGS
-	CPPFLAGS="$CPPFLAGS -I/usr/include/$dir"
-	check_bdb "$1" db-$1 db_create
-	CPPFLAGS=$save_CPPFLAGS
-	if test "$status_dbm" = "$1"; then
-	    MU_COMMON_INCLUDES="$MU_COMMON_INCLUDES -I/usr/include/$dir"
-	fi
-}
-
-case "$use_dbm" in
-GDBM)
-	AC_CHECK_LIB(gdbm, gdbm_open,
-                     [AC_CHECK_HEADERS(gdbm.h,
-                                       AC_DEFINE(WITH_GDBM,1,
-                                                 [Enable use of GNU DBM library]))
-                     LIBS="$LIBS -lgdbm"
-                     status_dbm="GDBM"]);;
-
-BDB2)   check_bdb 2 db db_open
-        test -n "$status_dbm" && status_dbm="Berkeley DB v. $status_dbm";;
-
-BDB)    for version in 4 3 2
-	do
-		case $version in
-		4|3) func=db_create;;
-		2)   func=db_open;;
-		esac
-		check_bdb $version db $func
-		if test "$status_dbm" != no; then
-                   status_dbm="Berkeley DB v. $status_dbm"
-		   break;
-		fi
-	done;;
-
-BDB=*)
-	name=`expr $use_dbm : 'BDB=\(.*\)'`
-	case $name in
-	[[0-9]]*)  check_slackware_bdb $name;;
-	*)	   for version in 4 3 2
-	           do
-			case $version in
-			4|3) func=db_create;;
-			2)   func=db_open;;
-			esac
-			check_bdb $version $name $func
-			if test "$status_dbm" != no; then
-		           status_dbm="Berkeley DB v. $status_dbm"
-			   break;
-			fi
-		   done
-		   ;;
-	esac
-        ;;
-
-NDBM)
-	AC_CHECK_LIB(ndbm, dbm_open,
-                     [AC_CHECK_HEADERS(ndbm.h,
-                                       AC_DEFINE(WITH_NDBM,1,
-                                                 [Enable use of NDBM]))
-                     LIBS="$LIBS -lndbm"
-                     status_dbm="NDBM"]);;
-
-TC)
-	AC_CHECK_LIB(tokyocabinet, tchdbnew,
-                     [AC_CHECK_HEADERS(tchdb.h,
-                                       AC_DEFINE(WITH_TOKYOCABINET,1,
-                                                 [Enable use of Tokyo Cabinet]))
-                     LIBS="$LIBS -ltokyocabinet -lz -lbz2 -lrt"
-                     status_dbm="Tokyo Cabinet"]);;
-esac
-
 AC_SUBST(POPAUTH)
 if test "$status_dbm" != no; then
   POPAUTH='popauth$(EXEEXT)'
@@ -1397,6 +1446,7 @@ AC_CONFIG_FILES([
  libmu_cpp/Makefile
  libmu_scm/Makefile
  libmu_scm/mailutils/Makefile
+ libmu_dbm/Makefile
  libmu_sieve/Makefile
  libmu_sieve/extensions/Makefile
  libproto/Makefile
diff --git a/imap4d/io.c b/imap4d/io.c
index 4fad3c3..2033638 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -319,7 +319,7 @@ io_getline (char **pbuf, size_t *psize, size_t *pnbytes)
           imap4d_bye (ERR_NO_IFILE);
           /*FIXME rc = ECONNABORTED;*/
         }
-      len = mu_rtrim_cset (s, "\r\n");
+      len = mu_rtrim_class (s, MU_CTYPE_ENDLN);
       if (pnbytes)
 	*pnbytes = len;
     }
diff --git a/imap4d/preauth.c b/imap4d/preauth.c
index 5e145e3..43cd6b2 100644
--- a/imap4d/preauth.c
+++ b/imap4d/preauth.c
@@ -463,7 +463,7 @@ do_preauth_program (struct sockaddr *pcs, struct sockaddr *sa)
     }
   else
     {
-      mu_rtrim_cset (buf, "\r\n");
+      mu_rtrim_class (buf, MU_CTYPE_ENDLN);
       return buf;
     }
   return NULL;
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 1e21894..6682884 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -39,6 +39,7 @@ pkginclude_HEADERS = \
  cidr.h\
  cstr.h\
  daemon.h\
+ dbm.h\
  debug.h\
  diag.h\
  envelope.h\
diff --git a/include/mailutils/cctype.h b/include/mailutils/cctype.h
index 8953b34..f56dfc0 100644
--- a/include/mailutils/cctype.h
+++ b/include/mailutils/cctype.h
@@ -35,6 +35,7 @@ extern "C" {
 #define MU_CTYPE_PUNCT   0x100
 #define MU_CTYPE_SPACE   0x200
 #define MU_CTYPE_XLETR   0x400
+#define MU_CTYPE_ENDLN   0x800
 
 #define MU_C_TAB_MAX     128
 
@@ -56,6 +57,7 @@ extern int mu_c_tab[MU_C_TAB_MAX];
 #define mu_isalnum(c) mu_c_is_class (c, MU_CTYPE_ALPHA|MU_CTYPE_DIGIT)
 #define mu_isascii(c) (((unsigned)c) < MU_C_TAB_MAX)
 #define mu_isblank(c) ((c) == ' ' || (c) == '\t')
+#define mu_isendln(c) mu_c_is_class (c, MU_CTYPE_ENDLN)
 
 #define mu_tolower(c)					\
   ({ int __c = (c);					\
diff --git a/include/mailutils/dbm.h b/include/mailutils/dbm.h
new file mode 100644
index 0000000..0d194f6
--- /dev/null
+++ b/include/mailutils/dbm.h
@@ -0,0 +1,77 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011
+   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_DBM_H
+#define _MAILUTILS_DBM_H
+
+#include <mailutils/types.h>
+
+struct mu_dbm_datum
+{
+  char *mu_dptr;               /* Data pointer */
+  size_t mu_dsize;             /* Data size */
+  void *mu_data;               /* Implementation-dependent data */
+  struct mu_dbm_impl *mu_sys;  /* Pointer to implementation */
+};
+
+struct mu_dbm_impl
+{
+  char *_dbm_name;
+  int (*_dbm_file_safety) (mu_dbm_file_t db, int mode, uid_t owner);
+  int (*_dbm_get_fd) (mu_dbm_file_t db, int *pag, int *dir);
+  int (*_dbm_open) (mu_dbm_file_t db, int flags, int mode);
+  int (*_dbm_close) (mu_dbm_file_t db);
+  int (*_dbm_fetch) (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+		     struct mu_dbm_datum *ret);
+  int (*_dbm_store) (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+		     struct mu_dbm_datum const *contents, int replace);
+  int (*_dbm_delete) (mu_dbm_file_t db,
+		      struct mu_dbm_datum const *key);
+  int (*_dbm_firstkey) (mu_dbm_file_t db, struct mu_dbm_datum *ret);
+  int (*_dbm_nextkey) (mu_dbm_file_t db, struct mu_dbm_datum *ret);
+  void (*_dbm_datum_free) (struct mu_dbm_datum *datum);
+  char const *(*_dbm_strerror) (mu_dbm_file_t db);
+};
+
+extern mu_url_t mu_dbm_hint;
+
+int mu_dbm_register (struct mu_dbm_impl *impl);
+int mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db);
+int mu_dbm_create (char *name, mu_dbm_file_t *db);
+int mu_dbm_close (mu_dbm_file_t db);
+void mu_dbm_datum_free (struct mu_dbm_datum *datum);
+int mu_dbm_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key);
+void mu_dbm_destroy (mu_dbm_file_t *pdb);
+int mu_dbm_fetch (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+		  struct mu_dbm_datum *ret);
+int mu_dbm_store (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+		  struct mu_dbm_datum const *contents, int replace);
+int mu_dbm_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret);
+int mu_dbm_nextkey (mu_dbm_file_t db, struct mu_dbm_datum *ret);
+int mu_dbm_open (mu_dbm_file_t db, int flags, int mode);
+int mu_dbm_safety_get_owner (mu_dbm_file_t db, uid_t *uid);
+int mu_dbm_safety_get_flags (mu_dbm_file_t db, int *flags);
+int mu_dbm_safety_set_owner (mu_dbm_file_t db, uid_t uid);
+int mu_dbm_safety_set_flags (mu_dbm_file_t db, int flags);
+int mu_dbm_safety_check (mu_dbm_file_t db);
+char const *mu_dbm_strerror (mu_dbm_file_t db);
+int mu_dbm_get_fd (mu_dbm_file_t db, int *pag, int *dir);
+
+int mu_dbm_impl_iterator (mu_iterator_t *itr);
+
+#endif
diff --git a/include/mailutils/sys/Makefile.am b/include/mailutils/sys/Makefile.am
index 56942cf..e46a294 100644
--- a/include/mailutils/sys/Makefile.am
+++ b/include/mailutils/sys/Makefile.am
@@ -21,6 +21,7 @@ sysinclude_HEADERS = \
  attribute.h\
  auth.h\
  body.h\
+ dbm.h\
  debcat.h\
  envelope.h\
  file_stream.h\
diff --git a/include/mailutils/radius.h b/include/mailutils/sys/dbm.h
similarity index 60%
copy from include/mailutils/radius.h
copy to include/mailutils/sys/dbm.h
index c538a14..bf1d8d5 100644
--- a/include/mailutils/radius.h
+++ b/include/mailutils/sys/dbm.h
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2008, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 2011 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
@@ -16,18 +15,23 @@
    Public License along with this library.  If not, see
    <http://www.gnu.org/licenses/>. */
 
-#ifndef _MAILUTILS_RADIUS_H
-#define _MAILUTILS_RADIUS_H
-#include <mailutils/types.h>
+#ifndef _MAILUTILS_SYS_DBM_H
+# define _MAILUTILS_SYS_DBM_H
 
-struct mu_radius_module_data
+union _mu_dbm_errno
 {
-  char *config_dir;
-  char *auth_request;
-  char *getpwnam_request;
-  char *getpwuid_request;
+  int n;
+  void *p;
 };
 
-extern int mu_radius_module_init (enum mu_gocs_op, void *data);
+struct _mu_dbm_file
+{
+  char *db_name;              /* Database name */
+  void *db_descr;             /* Database descriptor */
+  int db_safety_flags;        /* Safety checks */
+  uid_t db_owner;             /* Database owner UID */
+  struct mu_dbm_impl *db_sys; /* Pointer to the database implementation */
+  union _mu_dbm_errno db_errno;
+};
 
 #endif
diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin
index bf81756..c1f4b44 100644
--- a/include/mailutils/types.hin
+++ b/include/mailutils/types.hin
@@ -75,7 +75,8 @@ struct _mu_assoc;
 struct _mu_acl;  
 struct _mu_server;
 struct _mu_tcp_server;
-
+struct _mu_dbm_file;
+  
 struct mu_sockaddr; /* defined in mailutils/sockaddr.h */  
 struct mu_cidr;     /* defined in mailutils/cidr.h */  
   
@@ -121,6 +122,7 @@ typedef struct _mu_opool *mu_opool_t;
 typedef struct _mu_progmailer *mu_progmailer_t;
 typedef struct _mu_secret *mu_secret_t;
 typedef struct _mu_mime_io_buffer *mu_mime_io_buffer_t;
+typedef struct _mu_dbm_file *mu_dbm_file_t;
 
 typedef void (*mu_onexit_t) (void*);
 typedef unsigned int mu_debug_handle_t;
diff --git a/lib/Makefile.am b/lib/Makefile.am
index c53879f..8901769 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -24,7 +24,6 @@ libmuaux_a_SOURCES += \
  daemon.c\
  mailcap.c\
  manlock.c\
- mu_dbm.c\
  signal.c\
  strexit.c\
  tcpwrap.c\
@@ -34,7 +33,6 @@ libmuaux_a_SOURCES += \
 noinst_HEADERS +=\
  mailcap.h\
  muaux.h\
- mu_dbm.h\
  tcpwrap.h
 
 EXTRA_DIST += utmp.c
diff --git a/lib/mu_dbm.c b/lib/mu_dbm.c
deleted file mode 100644
index ec270f0..0000000
--- a/lib/mu_dbm.c
+++ /dev/null
@@ -1,575 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2006, 2007, 2009, 2010, 2011
-   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 <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
-#include <errno.h>
-#include <mailutils/errno.h>
-#include <mailutils/stream.h>
-#include <mu_dbm.h>
-#include <xalloc.h>
-
-int
-mu_fcheck_perm (int fd, int mode)
-{
-  struct stat st;
-
-  if (mode == 0)
-    return 0;
-  if (fstat (fd, &st) == -1)
-    {
-      if (errno == ENOENT)
-	return 0;
-      else
-	return 1;
-    }
-  if ((st.st_mode & 0777) != mode)
-    {
-      errno = MU_ERR_UNSAFE_PERMS;
-      return 1;
-    }
-  return 0;
-}
-
-int
-mu_check_perm (const char *name, int mode)
-{
-  struct stat st;
-
-  if (mode == 0)
-    return 0;
-  if (stat (name, &st) == -1)
-    {
-      if (errno == ENOENT)
-	return 0;
-      else
-	return 1;
-    }
-  if ((st.st_mode & 0777) != mode)
-    {
-      errno = MU_ERR_UNSAFE_PERMS;
-      return 1;
-    }
-  return 0;
-}
-
-static char *
-make_db_name (const char *name, const char *suffix)
-{
-  int nlen = strlen (name);
-  int slen = strlen (suffix);
-  char *p;
-  
-  if (nlen > slen && strcmp (name + nlen - slen, suffix) == 0)
-    p = xstrdup (name);
-  else
-    {
-      p = xmalloc (strlen (name) + slen + 1);
-      strcat (strcpy (p, name), suffix);
-    }
-  return p;
-}
-
-#if defined(WITH_GDBM)
-
-#define DB_SUFFIX ".db"
-
-int
-mu_dbm_stat (char *name, struct stat *sb)
-{
-  int rc;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-  rc = stat (pfname, sb);
-  free (pfname);
-  return rc;
-}
-
-int
-mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode)
-{
-  int f;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-
-  if (mu_check_perm (pfname, mode))
-    {
-      free (pfname);
-      return -1;
-    }
-
-  switch (flags)
-    {
-    case MU_STREAM_CREAT:
-      f = GDBM_NEWDB;
-      break;
-      
-    case MU_STREAM_READ:
-      f = GDBM_READER;
-      break;
-      
-    case MU_STREAM_RDWR:
-      f = GDBM_WRCREAT;
-      break;
-      
-    default:
-      free (pfname);
-      errno = EINVAL;
-      return 1;
-    }
-  *db = gdbm_open (pfname, 512, f, mode, NULL);
-  free (pfname);
-  return *db == NULL;
-}
-
-int
-mu_dbm_close (DBM_FILE db)
-{
-  gdbm_close(db);
-  return 0;
-}
-
-int
-mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret)
-{
-  *ret = gdbm_fetch (db, key);
-  return ret->dptr == NULL;
-}
-
-int
-mu_dbm_delete (DBM_FILE db, DBM_DATUM key)
-{
-  return gdbm_delete (db, key);
-}
-
-int
-mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace)
-{
-  return gdbm_store (db, key, contents,
-		     replace ? GDBM_REPLACE : GDBM_INSERT);
-}
-
-DBM_DATUM
-mu_dbm_firstkey (DBM_FILE db)
-{
-  return gdbm_firstkey (db);
-}
-
-DBM_DATUM
-mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key)
-{
-  return gdbm_nextkey (db, key);
-}
-
-void
-mu_dbm_datum_free (DBM_DATUM *datum)
-{
-  void *ptr = MU_DATUM_PTR (*datum);
-  if (ptr)
-    free (ptr);
-  MU_DATUM_PTR (*datum) = 0;
-}
-
-#elif defined(WITH_BDB)
-
-#define DB_SUFFIX ".db"
-
-int
-mu_dbm_stat (char *name, struct stat *sb)
-{
-  int rc;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-  rc = stat (pfname, sb);
-  free (pfname);
-  return rc;
-}
-
-int
-mu_dbm_open (char *name, DBM_FILE *dbm, int flags, int mode)
-{
-  int f, rc;
-  DB *db;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-
-  if (mu_check_perm (pfname, mode))
-    {
-      free (pfname);
-      errno = MU_ERR_UNSAFE_PERMS;
-      return -1;
-    }
-
-  switch (flags)
-    {
-    case MU_STREAM_CREAT:
-      f = DB_CREATE|DB_TRUNCATE;
-      break;
-      
-    case MU_STREAM_READ:
-      f = DB_RDONLY;
-      break;
-      
-    case MU_STREAM_RDWR:
-      f = DB_CREATE;
-      break;
-      
-    default:
-      free (pfname);
-      errno = EINVAL;
-      return -1;
-    }
-
-#if WITH_BDB == 2  
-  rc = db_open (pfname, DB_HASH, f, mode, NULL, NULL, &db);
-#else
-  rc = db_create (&db, NULL, 0);
-  if (rc != 0 || db == NULL)
-    return rc;
-# if DB_VERSION_MAJOR == 3
-  rc = db->open (db, pfname, NULL, DB_HASH, f, mode);
-# else
-  rc = db->open (db, NULL, pfname, NULL, DB_HASH, f, mode);
-# endif
-#endif
-  
-  free (pfname);
-  if (rc)
-    return -1;
-
-  *dbm = malloc (sizeof **dbm);
-  if (!*dbm)
-    {
-      db->close (db, 0);
-      errno = ENOMEM;
-      return -1;
-    }
-  (*dbm)->db = db;
-  (*dbm)->dbc = NULL;
-  return 0;
-}
-
-int
-mu_dbm_close (DBM_FILE db)
-{
-  db->db->close (db->db, 0);
-  free (db);
-  return 0;
-}
-
-int
-mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret)
-{
-  return db->db->get (db->db, NULL, &key, ret, 0);
-}
-
-int
-mu_dbm_delete (DBM_FILE db, DBM_DATUM key)
-{
-  return db->db->del (db->db, NULL, &key, 0);
-}
-
-int
-mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace)
-{
-  /*FIXME: replace unused*/
-  return db->db->put (db->db, NULL, &key, &contents, 0);
-}
-
-DBM_DATUM
-mu_dbm_firstkey (DBM_FILE db)
-{
-  DBT key, data;
-  int ret;
-
-  memset (&key, 0, sizeof key);
-  memset (&data, 0, sizeof data);
-
-  if (!db->dbc)
-    {
-      if (db->db->cursor (db->db, NULL, &db->dbc BDB2_CURSOR_LASTARG) != 0)
-	return key;
-    }
-
-  if ((ret = db->dbc->c_get (db->dbc, &key, &data, DB_FIRST)) != 0)
-    {
-      key.data = NULL;
-      key.size = 0;
-      if (ret == DB_NOTFOUND)
-	errno = MU_ERR_NOENT;
-      else
-	errno = ret;
-    }
-  return key;
-}
-
-DBM_DATUM
-mu_dbm_nextkey (DBM_FILE db, DBM_DATUM pkey /*unused*/)
-{
-  DBT key, data;
-  int ret;
-
-  memset (&key, 0, sizeof key);
-  memset (&data, 0, sizeof data);
-
-  if (!db->dbc)
-    return key;
-
-  if ((ret = db->dbc->c_get (db->dbc, &key, &data, DB_NEXT)) != 0)
-    {
-      key.data = NULL;
-      key.size = 0;
-      if (ret == DB_NOTFOUND)
-	errno = MU_ERR_NOENT;
-      else
-	errno = ret;
-    }
-  return key;
-}
-
-void
-mu_dbm_datum_free (DBM_DATUM *datum)
-{
-  /* empty */
-}
-
-#elif defined(WITH_NDBM)
-
-#define DB_SUFFIX ".pag"
-
-int
-mu_dbm_stat (char *name, struct stat *sb)
-{
-  int rc;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-  rc = stat (pfname, sb);
-  free (pfname);
-  return rc;
-}
-
-int
-mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode)
-{
-  int f;
-  char *pfname;
-
-  switch (flags)
-    {
-    case MU_STREAM_CREAT:
-      f = O_CREAT|O_TRUNC|O_RDWR;
-      break;
-      
-    case MU_STREAM_READ:
-      f = O_RDONLY;
-      break;
-      
-    case MU_STREAM_RDWR:
-      f = O_CREAT|O_RDWR;
-      break;
-      
-    default:
-      errno = EINVAL;
-      return -1;
-    }
-  pfname = strip_suffix (name, DB_SUFFIX);
-  *db = dbm_open (pfname, f, mode);
-  free (pfname);
-  if (!*db)
-    return -1;
-
-  if (mu_fcheck_perm (dbm_dirfno (*db), mode)
-      || mu_fcheck_perm (dbm_pagfno (*db), mode))
-    {
-      dbm_close (*db);
-      return 1;
-    }
-
-  return 0;
-}
-
-int
-mu_dbm_close (DBM_FILE db)
-{
-  dbm_close (db);
-  return 0;
-}
-
-int
-mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret)
-{
-  *ret = dbm_fetch (db, key);
-  return ret->dptr == NULL;
-}
-
-int
-mu_dbm_delete (DBM_FILE db, DBM_DATUM key)
-{
-  return dbm_delete (db, key);
-}
-
-int
-mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace)
-{
-  return dbm_store (db, key, contents, replace ? DBM_REPLACE : DBM_INSERT);
-}
-
-DBM_DATUM
-mu_dbm_firstkey (DBM_FILE db)
-{
-  return dbm_firstkey (db);
-}
-
-DBM_DATUM
-mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key)
-{
-  return dbm_nextkey (db, key);
-}
-
-void
-mu_dbm_datum_free (DBM_DATUM *datum)
-{
-  /* empty */
-}
-
-#elif defined(WITH_TOKYOCABINET)
-
-#define DB_SUFFIX ".tch"
-
-int
-mu_dbm_stat (char *name, struct stat *sb)
-{
-  int rc;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-  rc = stat (pfname, sb);
-  free (pfname);
-  return rc;
-}
-
-int
-mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode)
-{
-  int f, ecode;
-  char *pfname = make_db_name (name, DB_SUFFIX);
-
-  if (mu_check_perm (pfname, mode))
-    {
-      free (pfname);
-      return -1;
-    }
-
-  switch (flags)
-    {
-    case MU_STREAM_CREAT:
-      f = HDBOWRITER | HDBOCREAT;
-      break;
-      
-    case MU_STREAM_READ:
-      f = HDBOREADER;
-      break;
-      
-    case MU_STREAM_RDWR:
-      f = HDBOREADER | HDBOWRITER;
-      break;
-      
-    default:
-      free (pfname);
-      errno = EINVAL;
-      return 1;
-    }
-
-  *db = malloc (sizeof **db);
-  if (!*db)
-    {
-      errno = ENOMEM;
-      return -1;
-    }
-  (*db)->hdb = tchdbnew ();
-
-  if (!tchdbopen ((*db)->hdb, pfname, f))
-    ecode = tchdbecode ((*db)->hdb);
-
-  free (pfname);
-  return 0;
-}
-
-int
-mu_dbm_close (DBM_FILE db)
-{
-  tchdbclose (db->hdb);
-  tchdbdel (db->hdb);
-  return 0;
-}
-
-int
-mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret)
-{
-  ret->data = tchdbget (db->hdb, key.data, key.size, &ret->size);
-  return ret->data == NULL;
-}
-
-int
-mu_dbm_delete (DBM_FILE db, DBM_DATUM key)
-{
-  return !tchdbout (db->hdb, key.data, key.size);
-}
-
-int
-mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace)
-{
-  if (replace)
-    return !tchdbput (db->hdb, key.data, key.size, contents.data, contents.size);
-  else
-    return !tchdbputkeep (db->hdb, key.data, key.size,
-			  contents.data, contents.size);
-}
-
-DBM_DATUM
-mu_dbm_firstkey (DBM_FILE db)
-{
-  DBM_DATUM key;
-  memset (&key, 0, sizeof key);
-
-  tchdbiterinit (db->hdb);
-  key.data = tchdbiternext (db->hdb, &key.size);
-  return key;
-}
-
-DBM_DATUM
-mu_dbm_nextkey (DBM_FILE db, DBM_DATUM unused)
-{
-  DBM_DATUM key;
-  memset (&key, 0, sizeof key);
-
-  key.data = tchdbiternext (db->hdb, &key.size);
-  return key;
-}
-
-void
-mu_dbm_datum_free (DBM_DATUM *datum)
-{
-  /* empty */
-}
-
-#endif
-
diff --git a/lib/mu_dbm.h b/lib/mu_dbm.h
deleted file mode 100644
index fee27e4..0000000
--- a/lib/mu_dbm.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2007, 2009, 2010, 2011
-   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(WITH_GDBM)
-
-#include <gdbm.h>
-#define USE_DBM
-typedef GDBM_FILE DBM_FILE;
-typedef datum DBM_DATUM;
-#define MU_DATUM_SIZE(d) (d).dsize
-#define MU_DATUM_PTR(d) (d).dptr
-
-#elif defined(WITH_BDB)
-
-#include <db.h>
-#define USE_DBM
-
-struct db2_file
-{
-  DB *db;
-  DBC *dbc;
-};
-
-typedef struct db2_file *DBM_FILE;
-typedef DBT DBM_DATUM;
-#define MU_DATUM_SIZE(d) (d).size
-#define MU_DATUM_PTR(d) (d).data
-
-#elif defined(WITH_NDBM)
-
-#include <ndbm.h>
-#define USE_DBM
-typedef DBM *DBM_FILE;
-typedef datum DBM_DATUM;
-#define MU_DATUM_SIZE(d) (d).dsize
-#define MU_DATUM_PTR(d) (d).dptr
-
-#elif defined(WITH_TOKYOCABINET)
-
-#include <tcutil.h>
-#include <tchdb.h>
-#define USE_DBM
-
-struct tokyocabinet_file
-{
-  TCHDB *hdb;
-};
-
-struct tokyocabinet_datum {
-  void *data;
-  int size;
-};
-
-typedef struct tokyocabinet_file *DBM_FILE;
-typedef struct tokyocabinet_datum DBM_DATUM;
-#define MU_DATUM_SIZE(d) (d).size
-#define MU_DATUM_PTR(d) (d).data
-
-#endif
-
-#ifdef USE_DBM
-struct stat;
-int mu_dbm_stat (char *name, struct stat *sb);
-int mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode);
-int mu_dbm_close (DBM_FILE db);
-int mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret);
-int mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace);
-int mu_dbm_delete (DBM_FILE db, DBM_DATUM key);
-DBM_DATUM mu_dbm_firstkey (DBM_FILE db);
-DBM_DATUM mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key);
-void mu_dbm_datum_free(DBM_DATUM *datum);
-#endif /* USE_DBM */
-
-int mu_fcheck_perm (int fd, int mode);
-int mu_check_perm (const char *name, int mode);
diff --git a/libmailutils/string/muctype.c b/libmailutils/string/muctype.c
index b2a831a..669c40a 100644
--- a/libmailutils/string/muctype.c
+++ b/libmailutils/string/muctype.c
@@ -31,10 +31,10 @@ int mu_c_tab[MU_C_TAB_MAX] = {
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
+  MU_CTYPE_CNTRL|MU_CTYPE_SPACE|MU_CTYPE_ENDLN,
   MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
   MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
-  MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
-  MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
+  MU_CTYPE_CNTRL|MU_CTYPE_SPACE|MU_CTYPE_ENDLN,
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
diff --git a/libproto/imap/Makefile.am b/libmu_dbm/Makefile.am
similarity index 56%
copy from libproto/imap/Makefile.am
copy to libmu_dbm/Makefile.am
index c280042..93335d7 100644
--- a/libproto/imap/Makefile.am
+++ b/libmu_dbm/Makefile.am
@@ -1,6 +1,5 @@
 ## This file is part of GNU Mailutils.
-## Copyright (C) 2003, 2005, 2006, 2007, 2010, 2011 Free Software
-## Foundation, Inc.
+## Copyright (C) 2011 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
@@ -15,32 +14,31 @@
 ## You should have received a copy of the GNU General Public License
 ## along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
+INCLUDES = @MU_LIB_COMMON_INCLUDES@ @DBMINCLUDES@
 
-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@ 
+lib_LTLIBRARIES = libmu_dbm.la
 
-# FIXME: Put these back when ready
-
-#  folder.c\
-#  mbox.c\
-#  url.c
-libmu_imap_la_SOURCES = \
- fake-folder.c\
- capability.c\
- capatst.c\
- carrier.c\
- connect.c\
+libmu_dbm_la_SOURCES = \
+ close.c\
  create.c\
+ datumfree.c\
+ dbm.c\
+ delete.c\
  destroy.c\
- disconnect.c\
- err.c\
- id.c\
- login.c\
- logout.c\
- response.c\
- state.c\
- tag.c\
- trace.c
+ errstr.c\
+ fetch.c\
+ firstkey.c\
+ getfd.c\
+ nextkey.c\
+ open.c\
+ safety.c\
+ store.c\
+ berkeley.c\
+ gdbm.c\
+ ndbm.c
+
+noinst_HEADERS = mudbm.h
 
+libmu_dbm_la_LIBADD = ${MU_LIB_MAILUTILS} @MU_AUTHLIBS@ @DBMLIBS@ @LTLIBINTL@
+libmu_dbm_la_LDFLAGS = -version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
+libmu_dbm_la_DEPENDENCIES = @DBMLIB_DEPENDENCY@ 
diff --git a/libmu_dbm/berkeley.c b/libmu_dbm/berkeley.c
new file mode 100644
index 0000000..884a326
--- /dev/null
+++ b/libmu_dbm/berkeley.c
@@ -0,0 +1,340 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 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/types.h>
+#include <mailutils/dbm.h>
+#include <mailutils/util.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/stream.h>
+#include "mudbm.h"
+
+#if defined(WITH_BDB)
+#include <db.h>
+
+struct bdb_file
+{
+  DB *db;
+  DBC *dbc;
+};
+
+static int
+_bdb_file_safety (mu_dbm_file_t db, int mode, uid_t owner)
+{
+  return mu_file_safety_check (db->db_name, mode, owner, NULL);
+}
+
+static int
+_bdb_get_fd (mu_dbm_file_t db, int *pag, int *dir)
+{
+  struct bdb_file *bdb_file = db->db_descr;
+  int rc = bdb_file->db->fd (bdb_file->db, pag);
+  if (rc)
+    {
+      db->db_errno.n = rc;
+      return MU_ERR_FAILURE;
+    }
+  if (dir)
+    *dir = *pag;
+  return 0;
+}
+  
+static int
+_bdb_open (mu_dbm_file_t mdb, int flags, int mode)
+{
+  struct bdb_file *bdb_file;
+  int f, rc;
+  DB *db;
+
+  switch (flags)
+    {
+    case MU_STREAM_CREAT:
+      f = DB_CREATE|DB_TRUNCATE;
+      break;
+      
+    case MU_STREAM_READ:
+      f = DB_RDONLY;
+      break;
+      
+    case MU_STREAM_RDWR:
+      f = DB_CREATE;
+      break;
+      
+    default:
+      return EINVAL;
+    }
+
+#if WITH_BDB == 2  
+  rc = db_open (db->db_name, DB_HASH, f, mode, NULL, NULL, &db);
+#else
+  rc = db_create (&db, NULL, 0);
+  if (rc != 0 || db == NULL)
+    return MU_ERR_FAILURE;
+# if DB_VERSION_MAJOR == 3
+  rc = db->open (db, mdb->db_name, NULL, DB_HASH, f, mode);
+# else
+  rc = db->open (db, NULL, mdb->db_name, NULL, DB_HASH, f, mode);
+# endif
+#endif
+  
+  if (rc)
+    return MU_ERR_FAILURE;
+
+  bdb_file = malloc (sizeof *bdb_file);
+  if (!bdb_file)
+    {
+      db->close (db, 0);
+      return ENOMEM;
+    }
+  bdb_file->db = db;
+  bdb_file->dbc = NULL;
+
+  mdb->db_descr = bdb_file;
+  
+  return 0;
+}
+
+static int
+_bdb_close (mu_dbm_file_t db)
+{
+  if (db->db_descr)
+    {
+      struct bdb_file *bdb_file = db->db_descr;
+      bdb_file->db->close (bdb_file->db, 0);
+      free (bdb_file);
+      db->db_descr = NULL;
+    }
+  return 0;
+}
+
+static int
+_bdb_fetch (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+	    struct mu_dbm_datum *ret)
+{
+  DBT keydat, content;
+  struct bdb_file *bdb_file = db->db_descr;
+  int rc;
+
+  memset (&keydat, 0, sizeof keydat);
+  keydat.data = key->mu_dptr;
+  keydat.size = key->mu_dsize;
+  memset (&content, 0, sizeof content);
+  content.flags = DB_DBT_MALLOC;
+  rc = bdb_file->db->get (bdb_file->db, NULL, &keydat, &content, 0);
+  mu_dbm_datum_free (ret);
+  switch (rc)
+    {
+    case 0:
+      ret->mu_dptr = content.data;
+      ret->mu_dsize = content.size;
+      ret->mu_sys = db->db_sys;
+      break;
+
+    case DB_NOTFOUND:
+      db->db_errno.n = rc;
+      rc = MU_ERR_NOENT;
+      break;
+
+    default:
+      db->db_errno.n = rc;
+      rc = MU_ERR_FAILURE;
+    }
+  return rc;
+}
+
+static int
+_bdb_store (mu_dbm_file_t db,
+	    struct mu_dbm_datum const *key,
+	    struct mu_dbm_datum const *contents,
+	    int replace)
+{
+  struct bdb_file *bdb_file = db->db_descr;
+  int rc;
+  DBT keydat, condat;
+
+  memset (&keydat, 0, sizeof keydat);
+  keydat.data = key->mu_dptr;
+  keydat.size = key->mu_dsize;
+
+  memset (&condat, 0, sizeof condat);
+  condat.data = contents->mu_dptr;
+  condat.size = contents->mu_dsize;
+
+  rc = bdb_file->db->put (bdb_file->db, NULL, &keydat, &condat,
+			  replace ? 0 : DB_NOOVERWRITE);
+  db->db_errno.n = rc;
+  switch (rc)
+    {
+    case 0:
+      break;
+
+    case DB_KEYEXIST:
+      rc = MU_ERR_EXISTS;
+      break;
+
+    default:
+      rc = MU_ERR_FAILURE;
+      break;
+    }
+  return rc;
+}
+
+static int
+_bdb_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key)
+{
+  DBT keydat;
+  struct bdb_file *bdb_file = db->db_descr;
+  int rc;
+
+  memset (&keydat, 0, sizeof keydat);
+  keydat.data = key->mu_dptr;
+  keydat.size = key->mu_dsize;
+  rc = bdb_file->db->del (bdb_file->db, NULL, &keydat, 0);
+  switch (rc)
+    {
+    case 0:
+      break;
+
+    case DB_NOTFOUND:
+      db->db_errno.n = rc;
+      rc = MU_ERR_NOENT;
+      break;
+
+    default:
+      db->db_errno.n = rc;
+      rc = MU_ERR_FAILURE;
+    }
+  return rc;
+}
+
+static int
+_bdb_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
+{
+  struct bdb_file *bdb_file = db->db_descr;
+  int rc;
+  DBT key, dbt;
+
+  if (!bdb_file->dbc)
+    {
+      rc = bdb_file->db->cursor (bdb_file->db, NULL, &bdb_file->dbc
+				 BDB2_CURSOR_LASTARG);
+      if (rc)
+	{
+	  db->db_errno.n = rc;
+	  return MU_ERR_FAILURE;
+	}
+    }
+  memset (&key, 0, sizeof key);
+  key.flags = DB_DBT_MALLOC;
+  
+  memset (&dbt, 0, sizeof dbt);
+  dbt.flags = DB_DBT_MALLOC;
+  rc = bdb_file->dbc->c_get (bdb_file->dbc, &key, &dbt, DB_FIRST);
+  mu_dbm_datum_free (ret);
+  switch (rc)
+    {
+    case 0:
+      free (dbt.data); /* FIXME: cache it for the eventual fetch that can
+			  follow */
+      ret->mu_dptr = key.data;
+      ret->mu_dsize = key.size;
+      ret->mu_sys = db->db_sys;
+      break;
+
+    case DB_NOTFOUND:
+      db->db_errno.n = rc;
+      rc = MU_ERR_NOENT;
+      break;
+
+    default:
+      db->db_errno.n = rc;
+      rc = MU_ERR_FAILURE;
+    }
+  return rc;
+}
+
+static int
+_bdb_nextkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
+{
+  struct bdb_file *bdb_file = db->db_descr;
+  int rc;
+  DBT key, dbt;
+
+  if (!bdb_file->dbc)
+    return MU_ERR_SEQ;
+
+  memset (&key, 0, sizeof key);
+  key.flags = DB_DBT_MALLOC;
+  
+  memset (&dbt, 0, sizeof dbt);
+  dbt.flags = DB_DBT_MALLOC;
+  rc = bdb_file->dbc->c_get (bdb_file->dbc, &key, &dbt, DB_NEXT);
+  mu_dbm_datum_free (ret);
+  switch (rc)
+    {
+    case 0:
+      free (dbt.data); /* FIXME: cache it for the eventual fetch that can
+			  follow */
+      ret->mu_dptr = key.data;
+      ret->mu_dsize = key.size;
+      ret->mu_sys = db->db_sys;
+      break;
+
+    case DB_NOTFOUND:
+      db->db_errno.n = rc;
+      rc = MU_ERR_NOENT;
+      break;
+
+    default:
+      db->db_errno.n = rc;
+      rc = MU_ERR_FAILURE;
+    }
+  return rc;
+}
+
+static void
+_bdb_datum_free (struct mu_dbm_datum *datum)
+{
+  free (datum->mu_dptr);
+}
+
+static char const *
+_bdb_strerror (mu_dbm_file_t db)
+{
+  return db_strerror (db->db_errno.n);
+}
+
+struct mu_dbm_impl _mu_dbm_bdb = {
+  "bdb",
+  _bdb_file_safety,
+  _bdb_get_fd,
+  _bdb_open,
+  _bdb_close,
+  _bdb_fetch,
+  _bdb_store,
+  _bdb_delete,
+  _bdb_firstkey,
+  _bdb_nextkey,
+  _bdb_datum_free,
+  _bdb_strerror
+};
+#endif
diff --git a/lib/argp_base.c b/libmu_dbm/close.c
similarity index 72%
copy from lib/argp_base.c
copy to libmu_dbm/close.c
index e2f00f8..a84574a 100644
--- a/lib/argp_base.c
+++ b/libmu_dbm/close.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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,13 +18,18 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <unistd.h>
-#include <string.h>
 
-char *
-__argp_base_name (const char *arg)
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
+#include <mailutils/errno.h>
+#include "mudbm.h"
+
+int
+mu_dbm_close (mu_dbm_file_t db)
 {
-  char *p = strrchr (arg, '/');
-  return (char *)(p ? p + 1 : arg);
+  DBMSYSCK (db, _dbm_close);
+  if (!db->db_descr)
+    return 0;
+  return db->db_sys->_dbm_close (db);
 }
 
diff --git a/libproto/imap/capatst.c b/libmu_dbm/create.c
similarity index 66%
copy from libproto/imap/capatst.c
copy to libmu_dbm/create.c
index 90db663..c1915a7 100644
--- a/libproto/imap/capatst.c
+++ b/libmu_dbm/create.c
@@ -1,5 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011
+   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,18 +19,27 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#include <unistd.h>
+#include <stdlib.h>
 #include <mailutils/types.h>
 #include <mailutils/list.h>
-#include <mailutils/sys/imap.h>
+#include <mailutils/url.h>
+#include <mailutils/dbm.h>
+#include <mailutils/errno.h>
+#include <mailutils/util.h>
+#include "mudbm.h"
 
 int
-mu_imap_capability_test (mu_imap_t imap, const char *name, const char **pret)
+mu_dbm_create (char *name, mu_dbm_file_t *db)
 {
   int rc;
+  mu_url_t url;
 
-  rc = mu_imap_capability (imap, 0, NULL);
+  _mu_dbm_init ();
+  rc = mu_url_create_hint (&url, name, 0, mu_dbm_hint);
   if (rc)
     return rc;
-  return mu_list_locate (imap->capa, (void*) name, (void**)pret);
+  rc = mu_dbm_create_from_url (url, db);
+  mu_url_destroy (&url);
+  return rc;
 }
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/datumfree.c
similarity index 69%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/datumfree.c
index dff9194..c11db26 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/datumfree.c
@@ -12,27 +12,25 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+#include <stdlib.h>
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
-int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+void
+mu_dbm_datum_free (struct mu_dbm_datum *datum)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
+  if (datum && datum->mu_data &&
+      datum->mu_sys && datum->mu_sys->_dbm_datum_free)
     {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
+      datum->mu_sys->_dbm_datum_free (datum);
+      datum->mu_data = NULL;
     }
-  return 0;
 }
-  
diff --git a/libmu_dbm/dbm.c b/libmu_dbm/dbm.c
new file mode 100644
index 0000000..e09cbbc
--- /dev/null
+++ b/libmu_dbm/dbm.c
@@ -0,0 +1,265 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 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 <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/list.h>
+#include <mailutils/url.h>
+#include <mailutils/dbm.h>
+#include <mailutils/util.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/nls.h>
+#include <mailutils/mu_auth.h>
+#include "mudbm.h"
+
+static mu_list_t implist;
+mu_url_t mu_dbm_hint;
+
+static void
+_implist_free (void *p)
+{
+  struct mu_dbm_impl *impl = p;
+
+  free (impl->_dbm_name);
+  free (impl);
+}
+
+static int
+_implist_cmp (const void *a, const void *b)
+{
+  struct mu_dbm_impl const *ia = a;
+  struct mu_dbm_impl const *ib = b;
+
+  return strcmp (ia->_dbm_name, ib->_dbm_name);
+}
+
+void
+_mu_dbm_init ()
+{
+  int rc;
+
+  if (implist)
+    return;
+  
+  rc = mu_list_create (&implist);
+  if (rc)
+    {
+      mu_error (_("cannot initialize DBM subsystem: %s"),
+		mu_strerror (rc));
+      abort ();
+    }
+  mu_list_set_destroy_item (implist, _implist_free);
+  mu_list_set_comparator (implist, _implist_cmp);
+  /* Add built-in entries */
+#ifdef WITH_GDBM
+  mu_dbm_register (&_mu_dbm_gdbm);
+#endif
+#ifdef WITH_BDB
+  mu_dbm_register (&_mu_dbm_bdb);
+#endif
+#ifdef WITH_NDBM
+  mu_dbm_register (&_mu_dbm_ndbm);
+#endif
+#ifdef WITH_TOKYOCABINET
+  mu_dbm_register (&_mu_dbm_tokyokabinet);
+#endif
+  if (!mu_dbm_hint)
+    {
+      struct mu_dbm_impl *impl;
+      char *urlbuf;
+      
+      rc = mu_list_get (implist, 0, (void**) &impl);
+      if (rc)
+	{
+	  mu_error (_("cannot initialize DBM hint: %s"),
+		    mu_strerror (rc));
+	  abort ();
+	}
+      urlbuf = malloc (strlen (impl->_dbm_name) + 4);
+      if (urlbuf)
+	{
+	  strcpy (urlbuf, impl->_dbm_name);
+	  strcat (urlbuf, "://");
+	  rc = mu_url_create (&mu_dbm_hint, urlbuf);
+	  free (urlbuf);
+	}
+      else
+	rc = ENOMEM;
+	  
+      if (rc)
+	{
+	  mu_error (_("cannot initialize DBM hint: %s"),
+		      mu_strerror (rc));
+	  abort ();
+	}
+    }
+}
+
+int
+mu_dbm_register (struct mu_dbm_impl *impl)
+{
+  int rc;
+  struct mu_dbm_impl *ptr;
+
+  _mu_dbm_init ();
+  ptr = calloc (1, sizeof (*ptr));
+  if (!ptr)
+    return ENOMEM;
+  *ptr = *impl;
+  ptr->_dbm_name = strdup (impl->_dbm_name);
+  if (!ptr->_dbm_name)
+    {
+      free (ptr);
+      return ENOMEM;
+    }
+  rc = mu_list_append (implist, ptr);
+  if (rc)
+    _implist_free (ptr);
+  return rc;
+}
+
+int
+mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db)
+{
+  mu_dbm_file_t p;
+  int flags;
+  int rc;
+  const char *db_name;
+  struct mu_dbm_impl impl_key;
+  struct mu_dbm_impl *impl;
+  struct mu_auth_data *auth;
+  int safety_flags = 0;
+  uid_t owner_uid = getuid ();
+
+  _mu_dbm_init ();
+  
+  mu_url_get_flags (url, &flags);
+  if ((flags & (MU_URL_HOST | MU_URL_PATH)) == (MU_URL_HOST | MU_URL_PATH))
+    return MU_ERR_URL_EXTRA_PARTS;
+  if (flags & MU_URL_HOST)
+    rc = mu_url_sget_host (url, &db_name);
+  else
+    rc = mu_url_sget_path (url, &db_name);
+  if (rc)
+    return rc;
+  
+  rc = mu_url_sget_scheme (url, (const char**)&impl_key._dbm_name);
+  if (rc)
+    return rc;
+  
+  rc = mu_list_locate (implist, (void *) &impl_key, (void **) &impl);
+  if (rc)
+    return rc;
+
+  if (flags & MU_URL_PARAM)
+    {
+      size_t fvc, i;
+      char **fvp;
+
+      mu_url_sget_fvpairs (url, &fvc, &fvp);
+      for (i = 0; i < fvc; i++)
+	{
+	  const char *name = fvp[i];
+	  int negate = 0;
+	  int val;
+
+	  if (*name == '-')
+	    {
+	      negate = 1;
+	      name++;
+	    }
+	  else if (*name == '+')
+	    name++;
+
+	  if (strncmp (name, "owner", 5) == 0)
+	    {
+	      val = MU_FILE_SAFETY_OWNER_MISMATCH;
+	      if (name[5] == '=')
+		{
+		  auth = mu_get_auth_by_name (name + 6);
+		  if (!auth)
+		    {
+		      char *end;
+		      unsigned long uid;
+
+		      errno = 0;
+		      uid = strtoul (name + 6, &end, 0);
+		      if (*end || errno)
+			return MU_ERR_NO_SUCH_USER;
+		      auth = mu_get_auth_by_uid (uid);
+		      if (!auth)
+			return MU_ERR_NO_SUCH_USER;
+		      owner_uid = auth->uid;
+		      mu_auth_data_free (auth);
+		    }
+		}
+	      else if (name[5])
+		return MU_ERR_URL_EXTRA_PARTS;//FIXME: better error code
+	    }
+	  else if (strcmp (name, "none") == 0)
+	    {
+	      safety_flags = negate ? MU_FILE_SAFETY_ALL : MU_FILE_SAFETY_NONE;
+	      continue;
+	    }
+	  else if (strcmp (name, "all") == 0)
+	    {
+	      safety_flags = negate ? MU_FILE_SAFETY_NONE : MU_FILE_SAFETY_ALL;
+	      continue;
+	    }
+	  else if (strcmp (name, "default") == 0)
+	    {
+	      val = DEFAULT_DBM_SAFETY_FLAGS;
+	    }
+	  else if (mu_file_safety_name_to_code (name, &val))
+	    return MU_ERR_URL_EXTRA_PARTS;//FIXME: better error code
+
+	  if (negate)
+	    safety_flags &= ~val;
+	  else
+	    safety_flags |= val;
+	}
+    }
+
+  p = calloc (1, sizeof (*p));
+  if (!p)
+    return ENOMEM;
+  p->db_name = strdup (db_name);
+  if (!p->db_name)
+    {
+      free (p);
+      return ENOMEM;
+    }
+  p->db_safety_flags = safety_flags;
+  p->db_owner = owner_uid;
+  p->db_sys = impl;
+
+  *db = p;
+  return 0;
+}
+
+int
+mu_dbm_impl_iterator (mu_iterator_t *itr)
+{
+  _mu_dbm_init ();
+  return mu_list_get_iterator (implist, itr);
+}
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/delete.c
similarity index 71%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/delete.c
index dff9194..f36f875 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/delete.c
@@ -12,27 +12,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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+mu_dbm_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
-    {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
-    }
-  return 0;
+  DBMSYSCK (db, _dbm_delete);
+  if (!db->db_descr)
+    return EINVAL;
+  return db->db_sys->_dbm_delete (db, key);
 }
-  
+
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/destroy.c
similarity index 70%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/destroy.c
index dff9194..c96966d 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/destroy.c
@@ -12,27 +12,28 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+#include <stdlib.h>
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
-int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+void
+mu_dbm_destroy (mu_dbm_file_t *pdb)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
+  if (pdb && *pdb)
     {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
+      mu_dbm_file_t db = *pdb;
+      if (db->db_descr)
+	mu_dbm_close (db);
+      free (db->db_name);
+      free (db);
+      *pdb = NULL;
     }
-  return 0;
 }
-  
diff --git a/libmailutils/sockaddr/unlink.c b/libmu_dbm/errstr.c
similarity index 67%
copy from libmailutils/sockaddr/unlink.c
copy to libmu_dbm/errstr.c
index 65808f5..f1cb372 100644
--- a/libmailutils/sockaddr/unlink.c
+++ b/libmu_dbm/errstr.c
@@ -12,34 +12,26 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
 #include <stdlib.h>
-#include <mailutils/sockaddr.h>
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
+#include <mailutils/errno.h>
+#include "mudbm.h"
 
-struct mu_sockaddr *
-mu_sockaddr_unlink (struct mu_sockaddr *addr)
+char const *
+mu_dbm_strerror (mu_dbm_file_t db)
 {
-  struct mu_sockaddr *p;
-
-  if (!addr)
+  if (!db)
     return NULL;
-
-  p = addr->prev;
-  if (p)
-    p->next = addr->next;
-  
-  p = addr->next;
-  if (p)
-    p->prev = addr->prev;
-
-  addr->prev = addr->next = NULL;
-  
-  return p;
+  if (!db->db_sys || !db->db_sys->_dbm_strerror)
+    return NULL;
+  if (!db->db_descr)
+    return mu_strerror (MU_ERR_NOT_OPEN);
+  return db->db_sys->_dbm_strerror (db);
 }
-
diff --git a/libproto/imap/capatst.c b/libmu_dbm/fetch.c
similarity index 70%
copy from libproto/imap/capatst.c
copy to libmu_dbm/fetch.c
index 90db663..772bb97 100644
--- a/libproto/imap/capatst.c
+++ b/libmu_dbm/fetch.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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,16 +20,17 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/list.h>
-#include <mailutils/sys/imap.h>
+#include <mailutils/dbm.h>
+#include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_imap_capability_test (mu_imap_t imap, const char *name, const char **pret)
+mu_dbm_fetch (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+	      struct mu_dbm_datum *ret)
 {
-  int rc;
-
-  rc = mu_imap_capability (imap, 0, NULL);
-  if (rc)
-    return rc;
-  return mu_list_locate (imap->capa, (void*) name, (void**)pret);
+  DBMSYSCK (db, _dbm_fetch);
+  if (!db->db_descr)
+    return EINVAL;
+  return db->db_sys->_dbm_fetch (db, key, ret);
 }
+
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/firstkey.c
similarity index 71%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/firstkey.c
index dff9194..d45f9c8 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/firstkey.c
@@ -12,27 +12,23 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+mu_dbm_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
-    {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
-    }
-  return 0;
+  DBMSYSCK (db, _dbm_firstkey);
+  if (!db->db_descr)
+    return EINVAL;
+  return db->db_sys->_dbm_firstkey (db, ret);
 }
-  
diff --git a/libmu_dbm/gdbm.c b/libmu_dbm/gdbm.c
new file mode 100644
index 0000000..84defcc
--- /dev/null
+++ b/libmu_dbm/gdbm.c
@@ -0,0 +1,290 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 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/types.h>
+#include <mailutils/dbm.h>
+#include <mailutils/util.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/stream.h>
+#include "mudbm.h"
+
+#if defined(WITH_GDBM)
+#include <gdbm.h>
+
+struct gdbm_descr
+{
+  GDBM_FILE file;           /* GDBM file */
+  datum prev;               /* Previous key for sequential access */
+};
+
+static int
+_gdbm_file_safety (mu_dbm_file_t db, int mode, uid_t owner)
+{
+  return mu_file_safety_check (db->db_name, mode, owner, NULL);
+}
+
+int
+_gdbm_get_fd (mu_dbm_file_t db, int *pag, int *dir)
+{
+  struct gdbm_descr *gd = db->db_descr;
+  *pag = gdbm_fdesc (gd->file);
+  if (dir)
+    *dir = *pag;
+  return 0;
+}
+
+static int
+_gdbm_open (mu_dbm_file_t db, int flags, int mode)
+{
+  int f;
+  struct gdbm_descr *gd;
+  GDBM_FILE file;
+  
+  switch (flags)
+    {
+    case MU_STREAM_CREAT:
+      f = GDBM_NEWDB;
+      break;
+      
+    case MU_STREAM_READ:
+      f = GDBM_READER;
+      break;
+      
+    case MU_STREAM_RDWR:
+      f = GDBM_WRCREAT;
+      break;
+      
+    default:
+      return EINVAL;
+    }
+  file = gdbm_open (db->db_name, 512, f, mode, NULL);
+  if (!file)
+    return MU_ERR_FAILURE;
+  gd = calloc (1, sizeof (*gd));
+  gd->file = file;
+  db->db_descr = gd;
+  return 0;
+}
+
+static int
+_gdbm_close (mu_dbm_file_t db)
+{
+  if (db->db_descr)
+    {
+      struct gdbm_descr *gd = db->db_descr;
+      gdbm_close (gd->file);
+      free (gd);
+      db->db_descr = NULL;
+    }
+  return 0;
+}
+
+static int
+_gdbm_conv_datum (mu_dbm_file_t db, struct mu_dbm_datum *ret, datum content,
+		  int copy)
+{
+  if (copy)
+    {
+      ret->mu_dptr = malloc (content.dsize);
+      if (!ret->mu_dptr)
+	return errno;
+      memcpy (ret->mu_dptr, content.dptr, content.dsize);
+    }
+  else
+    {
+      ret->mu_dptr = content.dptr;
+    }
+  ret->mu_dsize = content.dsize;
+  ret->mu_sys = db->db_sys;
+  return 0;
+}
+
+static int
+_gdbm_fetch (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+	     struct mu_dbm_datum *ret)
+{
+  struct gdbm_descr *gd = db->db_descr;
+  int rc;
+  datum keydat, content;
+
+  keydat.dptr = key->mu_dptr;
+  keydat.dsize = key->mu_dsize;
+  gdbm_errno = 0;
+  content = gdbm_fetch (gd->file, keydat);
+  if (content.dptr == NULL)
+    {
+      if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+	return MU_ERR_NOENT;
+      else
+	{
+	  db->db_errno.n = gdbm_errno;
+	  return MU_ERR_FAILURE;
+	}
+    }
+  mu_dbm_datum_free (ret);
+  rc = _gdbm_conv_datum (db, ret, content, 1);
+  if (rc)
+    {
+      free (content.dptr);
+      return rc;
+    }
+  return 0;
+}
+
+static int
+_gdbm_store (mu_dbm_file_t db,
+	     struct mu_dbm_datum const *key,
+	     struct mu_dbm_datum const *contents,
+	     int replace)
+{
+  struct gdbm_descr *gd = db->db_descr;
+  datum keydat, condat;
+
+  keydat.dptr = key->mu_dptr;
+  keydat.dsize = key->mu_dsize;
+  condat.dptr = contents->mu_dptr;
+  condat.dsize = contents->mu_dsize;
+  switch (gdbm_store (gd->file, keydat, condat, replace))
+    {
+    case 0:
+      break;
+      
+    case 1:
+      return MU_ERR_EXISTS;
+      
+    case -1:
+      db->db_errno.n = gdbm_errno;
+      return MU_ERR_FAILURE;
+    }
+  return 0;
+}
+
+static int
+_gdbm_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key)
+{
+  struct gdbm_descr *gd = db->db_descr;
+  datum keydat;
+
+  keydat.dptr = key->mu_dptr;
+  keydat.dsize = key->mu_dsize;
+  gdbm_errno = 0;
+  if (gdbm_delete (gd->file, keydat))
+    {
+      if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+	return MU_ERR_NOENT;
+      else
+	{
+	  db->db_errno.n = gdbm_errno;
+	  return MU_ERR_FAILURE;
+	}
+    }
+  return 0;
+}
+
+static int
+_gdbm_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
+{
+  struct gdbm_descr *gd = db->db_descr;
+  int rc;
+  datum key = gdbm_firstkey (gd->file);
+  if (key.dptr == NULL)
+    {
+      if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+	return MU_ERR_NOENT;
+      else
+	{
+	  db->db_errno.n = gdbm_errno;
+	  return MU_ERR_FAILURE;
+	}
+    }
+  mu_dbm_datum_free (ret);
+  rc = _gdbm_conv_datum (db, ret, key, 0);
+  if (rc)
+    {
+      free (key.dptr);
+      return rc;
+    }
+  free (gd->prev.dptr);
+  gd->prev = key;
+  return 0;
+}
+
+static int
+_gdbm_nextkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
+{
+  struct gdbm_descr *gd = db->db_descr;
+  int rc;
+  datum key;
+
+  if (!gd->prev.dptr)
+    return MU_ERR_NOENT;
+  key = gdbm_nextkey (gd->file, gd->prev);
+  if (key.dptr == NULL)
+    {
+      if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+	return MU_ERR_NOENT;
+      else
+	{
+	  db->db_errno.n = gdbm_errno;
+	  return MU_ERR_FAILURE;
+	}
+    }
+  mu_dbm_datum_free (ret);
+  rc = _gdbm_conv_datum (db, ret, key, 0);
+  if (rc)
+    {
+      free (key.dptr);
+      return rc;
+    }
+  free (gd->prev.dptr);
+  gd->prev = key;
+  return 0;
+}
+
+static void
+_gdbm_datum_free (struct mu_dbm_datum *datum)
+{
+  free (datum->mu_dptr);
+}
+
+static char const *
+_gdbm_strerror (mu_dbm_file_t db)
+{
+  return gdbm_strerror (db->db_errno.n);
+}
+
+struct mu_dbm_impl _mu_dbm_gdbm = {
+  "gdbm",
+  _gdbm_file_safety,
+  _gdbm_get_fd,
+  _gdbm_open,
+  _gdbm_close,
+  _gdbm_fetch,
+  _gdbm_store,
+  _gdbm_delete,
+  _gdbm_firstkey,
+  _gdbm_nextkey,
+  _gdbm_datum_free,
+  _gdbm_strerror
+};
+#endif
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/getfd.c
similarity index 71%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/getfd.c
index dff9194..2eafe9e 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/getfd.c
@@ -12,27 +12,23 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+mu_dbm_get_fd (mu_dbm_file_t db, int *pag, int *dir)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
-    {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
-    }
-  return 0;
+  DBMSYSCK (db, _dbm_get_fd);
+  if (!db->db_descr || !pag)
+    return EINVAL;
+  return db->db_sys->_dbm_get_fd (db, pag, dir);
 }
-  
diff --git a/libproto/nntp/url.c b/libmu_dbm/mudbm.h
similarity index 52%
copy from libproto/nntp/url.c
copy to libmu_dbm/mudbm.h
index aab0566..98c2750 100644
--- a/libproto/nntp/url.c
+++ b/libmu_dbm/mudbm.h
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2004, 2007, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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
@@ -15,36 +15,34 @@
    Public License along with this library.  If not, see
    <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef ENABLE_NNTP
+#include <mailutils/sys/dbm.h>
 
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
+#define DBMSYSCK(db,meth) do					\
+    {								\
+      if (!(db))						\
+	return EINVAL;						\
+      if (!(db)->db_descr)					\
+	return MU_ERR_NOT_OPEN;					\
+      if (!(db)->db_sys || !(db)->db_sys->meth)			\
+	return ENOSYS;						\
+    }								\
+  while (0)
 
-#include <mailutils/nntp.h>
+#define DEFAULT_DBM_SAFETY_FLAGS MU_FILE_SAFETY_ALL
 
-#include <mailutils/sys/url.h>
-
-/*
-  POP URL:
-  nntp://<host>:<port>/<newsgroup-name>/<article-number>
-*/
+#ifdef WITH_GDBM
+extern struct mu_dbm_impl _mu_dbm_gdbm;
+#endif
+#ifdef WITH_BDB
+extern struct mu_dbm_impl _mu_dbm_bdb;
+#endif
+#ifdef WITH_NDBM
+extern struct mu_dbm_impl _mu_dbm_ndbm;
+#endif
+#ifdef WITH_TOKYOCABINET
+extern struct mu_dbm_impl _mu_dbm_tokyokabinet;
+#endif
 
-int
-_nntp_url_init (mu_url_t url)
-{
-  if (url->port == 0)
-    url->port = MU_NNTP_DEFAULT_PORT;
+void _mu_dbm_init (void);
 
-  return status;
-}
 
-#endif
diff --git a/libmu_dbm/ndbm.c b/libmu_dbm/ndbm.c
new file mode 100644
index 0000000..7ccd4cd
--- /dev/null
+++ b/libmu_dbm/ndbm.c
@@ -0,0 +1,244 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 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 <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
+#include <mailutils/util.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/stream.h>
+#include <mailutils/io.h>
+#include "mudbm.h"
+
+#if defined(WITH_NDBM)
+#include <ndbm.h>
+
+static int
+_ndbm_file_safety (mu_dbm_file_t db, int mode, uid_t owner)
+{
+  int rc;
+  char *name;
+  
+  rc = mu_asprintf (&name, "%s.pag", db->db_name);
+  if (rc)
+    return rc;
+  rc = mu_file_safety_check (name, mode, owner, NULL);
+  if (rc)
+    {
+      free (name);
+      return rc;
+    }
+
+  strcpy (name + strlen (name) - 3, "dir");
+  rc = mu_file_safety_check (name, mode, owner, NULL);
+  free (name);
+  return rc;
+}
+
+int
+_ndbm_get_fd (mu_dbm_file_t db, int *pag, int *dir)
+{
+  DBM *dbm = db->db_descr;
+  *pag = dbm_pagfno (dbm);
+  if (dir)
+    *dir = dbm_dirfno (dbm);
+  return 0;
+}
+
+static int
+_ndbm_open (mu_dbm_file_t db, int flags, int mode)
+{
+  int f;
+  DBM *dbm;
+  
+  switch (flags)
+    {
+    case MU_STREAM_CREAT:
+      f = O_CREAT|O_TRUNC|O_RDWR;
+      break;
+      
+    case MU_STREAM_READ:
+      f = O_RDONLY;
+      break;
+      
+    case MU_STREAM_RDWR:
+      f = O_CREAT|O_RDWR;
+      break;
+      
+    default:
+      errno = EINVAL;
+      return -1;
+    }
+  dbm = dbm_open (db->db_name, f, mode);
+  if (!dbm)
+    return MU_ERR_FAILURE;
+  db->db_descr = dbm;
+  return 0;
+}
+
+static int
+_ndbm_close (mu_dbm_file_t db)
+{
+  if (db->db_descr)
+    {
+      dbm_close ((DBM *) db->db_descr);
+      db->db_descr = NULL;
+    }
+  return 0;
+}
+
+static int
+_ndbm_conv_datum (mu_dbm_file_t db, struct mu_dbm_datum *ret, datum content)
+{
+  ret->mu_dptr = malloc (content.dsize);
+  if (!ret->mu_dptr)
+    return errno;
+  memcpy (ret->mu_dptr, content.dptr, content.dsize);
+  ret->mu_dsize = content.dsize;
+  ret->mu_sys = db->db_sys;
+  return 0;
+}
+
+static int
+_ndbm_fetch (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+	     struct mu_dbm_datum *ret)
+{
+  datum keydat, content;
+
+  keydat.dptr = key->mu_dptr;
+  keydat.dsize = key->mu_dsize;
+  errno = 0;
+  content = dbm_fetch (db->db_descr, keydat);
+  mu_dbm_datum_free (ret);
+  if (content.dptr == NULL)
+    return MU_ERR_NOENT;
+  return _ndbm_conv_datum (db, ret, content);
+}
+
+static int
+_ndbm_store (mu_dbm_file_t db,
+	     struct mu_dbm_datum const *key,
+	     struct mu_dbm_datum const *contents,
+	     int replace)
+{
+  DBM *dbm = db->db_descr;
+  datum keydat, condat;
+  
+  keydat.dptr = key->mu_dptr;
+  keydat.dsize = key->mu_dsize;
+  condat.dptr = contents->mu_dptr;
+  condat.dsize = contents->mu_dsize;
+  errno = 0;
+  switch (dbm_store (dbm, keydat, condat,
+		     replace ? DBM_REPLACE : DBM_INSERT))
+    {
+    case 0:
+      break;
+      
+    case 1:
+      return MU_ERR_EXISTS;
+      
+    case -1:
+      db->db_errno.n = errno;
+      return MU_ERR_FAILURE;
+    }
+  return 0;
+}
+
+static int
+_ndbm_delete (mu_dbm_file_t db, struct mu_dbm_datum const *key)
+{
+  DBM *dbm = db->db_descr;
+  datum keydat;
+
+  keydat.dptr = key->mu_dptr;
+  keydat.dsize = key->mu_dsize;
+  errno = 0;
+  switch (dbm_delete (dbm, keydat))
+    {
+    case 0:
+      break;
+      
+    case 1:
+      return MU_ERR_NOENT;
+      
+    case -1:
+      db->db_errno.n = errno;
+      return MU_ERR_FAILURE;
+    }
+  return 0;
+}
+
+static int
+_ndbm_firstkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
+{
+  DBM *dbm = db->db_descr;
+  datum keydat;
+
+  errno = 0;
+  keydat = dbm_firstkey (dbm);
+  if (keydat.dptr == NULL)
+    return MU_ERR_NOENT;
+  return _ndbm_conv_datum (db, ret, keydat);
+}
+
+static int
+_ndbm_nextkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
+{
+  DBM *dbm = db->db_descr;
+  datum keydat;
+
+  keydat = dbm_nextkey (dbm);
+  if (keydat.dptr == NULL)
+    return MU_ERR_NOENT;
+  return _ndbm_conv_datum (db, ret, keydat);
+}
+
+static void
+_ndbm_datum_free (struct mu_dbm_datum *datum)
+{
+  free (datum->mu_dptr);
+}
+
+static char const *
+_ndbm_strerror (mu_dbm_file_t db)
+{
+  return strerror (db->db_errno.n);
+}
+
+struct mu_dbm_impl _mu_dbm_ndbm = {
+  "ndbm",
+  _ndbm_file_safety,
+  _ndbm_get_fd,
+  _ndbm_open,
+  _ndbm_close,
+  _ndbm_fetch,
+  _ndbm_store,
+  _ndbm_delete,
+  _ndbm_firstkey,
+  _ndbm_nextkey,
+  _ndbm_datum_free,
+  _ndbm_strerror
+};
+  
+#endif
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/nextkey.c
similarity index 71%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/nextkey.c
index dff9194..c7a818f 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/nextkey.c
@@ -12,27 +12,23 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+mu_dbm_nextkey (mu_dbm_file_t db, struct mu_dbm_datum *ret)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
-    {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
-    }
-  return 0;
+  DBMSYSCK (db, _dbm_nextkey);
+  if (!db->db_descr)
+    return EINVAL;
+  return db->db_sys->_dbm_nextkey (db, ret);
 }
-  
diff --git a/libmailutils/cidr/match.c b/libmu_dbm/open.c
similarity index 71%
copy from libmailutils/cidr/match.c
copy to libmu_dbm/open.c
index dff9194..5dd4175 100644
--- a/libmailutils/cidr/match.c
+++ b/libmu_dbm/open.c
@@ -12,27 +12,25 @@
    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/>. */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <mailutils/cidr.h>
+
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_cidr_match (struct mu_cidr *a, struct mu_cidr *b)
+mu_dbm_open (mu_dbm_file_t db, int flags, int mode)
 {
-  int i;
-
-  if (a->family != b->family)
-    return 1;
-  for (i = 0; i < a->len; i++)
-    {
-      if (a->address[i] != (b->address[i] & a->netmask[i]))
-	return 1;
-    }
-  return 0;
+  if (!db)
+    return EINVAL;
+  if (!db->db_sys || !db->db_sys->_dbm_open)
+    return ENOSYS;
+  return db->db_sys->_dbm_open (db, flags, mode);
 }
-  
+
diff --git a/libproto/imap/create.c b/libmu_dbm/safety.c
similarity index 52%
copy from libproto/imap/create.c
copy to libmu_dbm/safety.c
index e3d9901..411a6b8 100644
--- a/libproto/imap/create.c
+++ b/libmu_dbm/safety.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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,49 +19,54 @@
 # include <config.h>
 #endif
 
-#include <stdlib.h>
-#include <errno.h>
+#include <mailutils/types.h>
+#include <mailutils/dbm.h>
 #include <mailutils/errno.h>
-#include <mailutils/sys/imap.h>
-#include <mailutils/list.h>
+#include "mudbm.h"
 
 int
-mu_imap_create (mu_imap_t *pimap)
+mu_dbm_safety_set_owner (mu_dbm_file_t db, uid_t uid)
 {
-  mu_imap_t imap;
-
-  /* Sanity check.  */
-  if (pimap == NULL)
+  if (!db)
     return EINVAL;
+  db->db_owner = uid;
+  return 0;
+}
 
-  imap = calloc (1, sizeof *imap);
-  if (imap == NULL)
-    return ENOMEM;
-
-  _mu_imap_init (imap);
+int
+mu_dbm_safety_get_owner (mu_dbm_file_t db, uid_t *uid)
+{
+  if (!db)
+    return EINVAL;
+  *uid = db->db_owner;
+  return 0;
+}
 
-  *pimap = imap;
+int
+mu_dbm_safety_set_flags (mu_dbm_file_t db, int flags)
+{
+  if (!db)
+    return EINVAL;
+  db->db_safety_flags = flags;
   return 0;
 }
 
 int
-_mu_imap_init (mu_imap_t imap)
+mu_dbm_safety_get_flags (mu_dbm_file_t db, int *flags)
 {
-  if (imap == NULL)
+  if (!db)
     return EINVAL;
-  if (imap->carrier == 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.  */
+  *flags = db->db_safety_flags;
   return 0;
 }
+  
+int
+mu_dbm_safety_check (mu_dbm_file_t db)
+{
+  if (!db)
+    return EINVAL;
+  if (!db->db_sys || !db->db_sys->_dbm_file_safety)
+    return ENOSYS;
+  return db->db_sys->_dbm_file_safety (db, db->db_safety_flags,
+				       db->db_owner);
+}
diff --git a/libproto/imap/capatst.c b/libmu_dbm/store.c
similarity index 68%
copy from libproto/imap/capatst.c
copy to libmu_dbm/store.c
index 90db663..a80a0af 100644
--- a/libproto/imap/capatst.c
+++ b/libmu_dbm/store.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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,16 +20,16 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/list.h>
-#include <mailutils/sys/imap.h>
+#include <mailutils/dbm.h>
+#include <mailutils/errno.h>
+#include "mudbm.h"
 
 int
-mu_imap_capability_test (mu_imap_t imap, const char *name, const char **pret)
+mu_dbm_store (mu_dbm_file_t db, struct mu_dbm_datum const *key,
+	      struct mu_dbm_datum const *contents, int replace)
 {
-  int rc;
-
-  rc = mu_imap_capability (imap, 0, NULL);
-  if (rc)
-    return rc;
-  return mu_list_locate (imap->capa, (void*) name, (void**)pret);
+  DBMSYSCK (db, _dbm_store);
+  if (!db->db_descr)
+    return EINVAL;
+  return db->db_sys->_dbm_store (db, key, contents, replace);
 }
diff --git a/libmu_sieve/extensions/spamd.c b/libmu_sieve/extensions/spamd.c
index 58d95ee..a5c8116 100644
--- a/libmu_sieve/extensions/spamd.c
+++ b/libmu_sieve/extensions/spamd.c
@@ -248,7 +248,7 @@ spamd_read_line (mu_sieve_machine_t mach, mu_stream_t stream,
   size_t n;
   int rc = mu_stream_getline (stream, pbuffer, psize, &n);
   if (rc == 0)
-    mu_rtrim_cset (*pbuffer, "\r\n");
+    mu_rtrim_class (*pbuffer, MU_CTYPE_ENDLN);
   else
     {
       /* FIXME: Need an 'onabort' mechanism in Sieve machine, which
diff --git a/libmu_sieve/extensions/vacation.c b/libmu_sieve/extensions/vacation.c
index c255fb4..160930f 100644
--- a/libmu_sieve/extensions/vacation.c
+++ b/libmu_sieve/extensions/vacation.c
@@ -36,7 +36,6 @@
 #include <string.h>
 #include <signal.h>
 #include <regex.h>
-#include <mu_dbm.h>
 #include <mailutils/sieve.h>
 #include <mailutils/mu_auth.h>
 
diff --git a/libproto/mailer/smtp_io.c b/libproto/mailer/smtp_io.c
index a623141..f6062ad 100644
--- a/libproto/mailer/smtp_io.c
+++ b/libproto/mailer/smtp_io.c
@@ -68,7 +68,7 @@ mu_smtp_response (mu_smtp_t smtp)
   MU_SMTP_CHECK_ERROR (smtp, rc);
   if (n == 0)
     MU_SMTP_CHECK_ERROR (smtp, EIO);
-  n = mu_rtrim_cset (smtp->rdbuf, "\r\n");
+  n = mu_rtrim_class (smtp->rdbuf, MU_CTYPE_ENDLN);
   if (n < 3 || !mu_isdigit (smtp->rdbuf[0]))
     {
       mu_diag_output (MU_DIAG_NOTICE,
@@ -101,7 +101,7 @@ mu_smtp_response (mu_smtp_t smtp)
 	  MU_SMTP_CHECK_ERROR (smtp, rc);
 	  if (n == 0)
 	    MU_SMTP_CHECK_ERROR (smtp, EIO);
-	  n = mu_rtrim_cset (smtp->rdbuf, "\r\n");
+	  n = mu_rtrim_class (smtp->rdbuf, MU_CTYPE_ENDLN);
 	  if (n < 3 || memcmp (smtp->rdbuf, smtp->replcode, 3))
 	    {
 	      mu_diag_output (MU_DIAG_NOTICE,
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index b8b13db..7e65b88 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -28,6 +28,7 @@
 #include <mailutils/cstr.h>
 #include <mailutils/io.h>
 #include <mailutils/filter.h>
+#include <mailutils/cctype.h>
 
 #define ATTRIBUTE_IS_DELETED(flag)        (flag & MU_ATTRIBUTE_DELETED)
 #define ATTRIBUTE_IS_EQUAL(flag1, flag2)  (flag1 == flag2)
@@ -381,7 +382,7 @@ mbox_envelope_date (mu_envelope_t envelope, char *buf, size_t len,
 			       &n);
   if (status)
     return status;
-  mu_rtrim_cset (buffer, "\r\n");
+  mu_rtrim_class (buffer, MU_CTYPE_ENDLN);
   
   /* Format:  "From [sender] [date]" */
   /* strlen ("From ") == 5 */
@@ -938,7 +939,7 @@ msg_envelope_to_stream (mu_stream_t out, mu_message_t msg)
       return status;
     }
 
-  mu_rtrim_cset (datestr, "\r\n");
+  mu_rtrim_class (datestr, MU_CTYPE_ENDLN);
 
   envarr[0] = "From ";
   envarr[1] = sender;
diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c
index 067d244..9ce6603 100644
--- a/libproto/pop/mbox.c
+++ b/libproto/pop/mbox.c
@@ -640,7 +640,7 @@ pop_header_blurb (mu_stream_t stream, size_t maxlines,
       
   while ((status = mu_stream_getline (stream, &buf, &size, &n)) == 0 && n > 0)
     {
-      size_t len = mu_rtrim_cset (buf, "\r\n");
+      size_t len = mu_rtrim_class (buf, MU_CTYPE_ENDLN);
       if (len == 0)
 	break;
       mu_opool_append (opool, buf, len);
diff --git a/maidag/Makefile.am b/maidag/Makefile.am
index 2d098ea..4f88238 100644
--- a/maidag/Makefile.am
+++ b/maidag/Makefile.am
@@ -46,6 +46,8 @@ maidag_LDADD = \
  @MU_AUTHLIBS@\
  ${MU_LIB_MAILUTILS} \
  @MU_COMMON_LIBRARIES@\
+ ../libmu_dbm/libmu_dbm.la\
+ @DBMLIBS@\
  @TCPWRAP_LIBRARIES@
 
 INCLUDES = -I${top_srcdir} @MU_APP_COMMON_INCLUDES@ @GUILE_INCLUDES@ \
diff --git a/maidag/lmtp.c b/maidag/lmtp.c
index f69ca24..f493b67 100644
--- a/maidag/lmtp.c
+++ b/maidag/lmtp.c
@@ -545,7 +545,7 @@ lmtp_loop (mu_stream_t iostr, unsigned int timeout)
       enum lmtp_command cmd = cp->cmd_code;
       enum lmtp_state next_state = transtab[cmd][state];
 
-      mu_rtrim_cset (sp, "\r\n");
+      mu_rtrim_class (sp, MU_CTYPE_ENDLN);
 
       if (next_state != state_none)
 	{
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 348c6da..9faa36d 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -457,7 +457,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
   { "exit-quota-tempfail", mu_cfg_bool, &ex_quota_tempfail, 0, NULL,
     N_("Indicate temporary failure if the recipient is over his mail quota.")
   },
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
   { "quota-db", mu_cfg_string, &quotadbname, 0, NULL,
     N_("Name of DBM quota database file."),
     N_("file") },
diff --git a/maidag/maidag.h b/maidag/maidag.h
index 2be3818..5125fe7 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -86,10 +86,9 @@
 #include <mailutils/server.h>
 #include <mailutils/cctype.h>
 #include <mailutils/io.h>
+#include <mailutils/dbm.h>
 
-#include <mu_dbm.h>
-
-#if defined (USE_DBM) || defined (USE_SQL)
+#if defined (ENABLE_DBM) || defined (USE_SQL)
 # define USE_MAILBOX_QUOTAS 1
 #endif
 
diff --git a/maidag/mailquota.c b/maidag/mailquota.c
index 1d196f9..216cc11 100644
--- a/maidag/mailquota.c
+++ b/maidag/mailquota.c
@@ -64,64 +64,85 @@ fail_retrieve_quota (char *name, mu_off_t *quota)
   return RETR_FAILURE;
 }
 
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
 int
 dbm_retrieve_quota (char *name, mu_off_t *quota)
 {
-  DBM_FILE db;
-  DBM_DATUM named, contentd;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum  named, contentd;
   char buffer[64];
   int unlimited = 0;
   int rc;
 
   if (!quotadbname)
     return RETR_FAILURE;
-  
-  if (mu_dbm_open (quotadbname, &db, MU_STREAM_READ, 0600))
+
+  rc = mu_dbm_create (quotadbname, &db);
+  if (rc)
+    {
+      mu_error (_("unable to create quota db"));
+      return RETR_FAILURE;
+    }
+
+  rc = mu_dbm_safety_check (db);
+  if (rc && rc != ENOENT)
     {
-      mu_error (_("cannot open file %s: %s"), quotadbname, mu_strerror (errno));
+      mu_error (_("quota db fails safety check: %s"),
+		mu_strerror (rc));
+      mu_dbm_destroy (&db);
+      return RETR_FAILURE;
+    }
+
+  rc = mu_dbm_open (db, MU_STREAM_READ, 0600);
+  if (rc)
+    {
+      mu_error (_("cannot open file %s: %s"),
+		quotadbname, mu_strerror (rc));
+      mu_dbm_destroy (&db);
       return RETR_FAILURE;
     }
   
   memset (&named, 0, sizeof named);
   memset (&contentd, 0, sizeof contentd);
-  MU_DATUM_PTR (named) = name;
-  MU_DATUM_SIZE (named) = strlen (name);
-  rc = mu_dbm_fetch (db, named, &contentd);
-  if (rc || !MU_DATUM_PTR (contentd))
+  named.mu_dptr = name;
+  named.mu_dsize = strlen (name);
+  rc = mu_dbm_fetch (db, &named, &contentd);
+  if (rc)
     {
       /* User not in database, try default quota */
-      memset (&named, 0, sizeof named);
-      MU_DATUM_PTR (named) = "DEFAULT";
-      MU_DATUM_SIZE (named) = strlen ("DEFAULT");
-      rc = mu_dbm_fetch (db, named, &contentd);
-      if (rc)
+      mu_dbm_datum_free (&named);
+      named.mu_dptr = "DEFAULT";
+      named.mu_dsize = strlen ("DEFAULT");
+      rc = mu_dbm_fetch (db, &named, &contentd);
+      if (rc == MU_ERR_NOENT)
 	{
-	  /*mu_error (_("can't fetch data: %s"), strerror (rc));*/
+	  mu_dbm_destroy (&db);
+	  return RETR_FAILURE;
+	}
+      else if (rc)
+	{
+	  mu_error (_("can't fetch data: %s"), mu_dbm_strerror (db));
+	  mu_dbm_destroy (&db);
 	  return RETR_FAILURE;
 	}
-      if (!MU_DATUM_PTR (contentd))
-	return RETR_FAILURE;
     }
 
-  if (mu_c_strncasecmp("none",
-		       MU_DATUM_PTR (contentd),
-		       MU_DATUM_SIZE (contentd)) == 0) 
+  if (mu_c_strncasecmp("none", contentd.mu_dptr, contentd.mu_dsize) == 0) 
       unlimited = 1;
-  else if (MU_DATUM_SIZE (contentd) > sizeof(buffer)-1)
+  else if (contentd.mu_dsize > sizeof (buffer) - 1)
     {
       mu_error (ngettext ("mailbox quota for `%s' is too big: %d digit",
 			  "mailbox quota for `%s' is too big: %d digits",
-			  MU_DATUM_SIZE (contentd)),
-		name, MU_DATUM_SIZE (contentd));
+			  contentd.mu_dsize),
+		name, contentd.mu_dsize);
       *quota = groupquota;
     }
   else
     {
       char *p;
 		
-      strncpy(buffer, MU_DATUM_PTR (contentd), MU_DATUM_SIZE (contentd));
-      buffer[MU_DATUM_SIZE (contentd)] = 0;
+      strncpy (buffer, contentd.mu_dptr, contentd.mu_dsize);
+      buffer[contentd.mu_dsize] = 0;
       *quota = strtoul (buffer, &p, 0);
       if (get_size (buffer, quota, &p))
 	{
@@ -129,8 +150,9 @@ dbm_retrieve_quota (char *name, mu_off_t *quota)
 	  *quota = groupquota;
 	}
     }
-
-  mu_dbm_close (db);
+  
+  mu_dbm_datum_free (&contentd);
+  mu_dbm_destroy (&db);
   
   return unlimited ? RETR_UNLIMITED : RETR_OK;
 }
diff --git a/mu/Makefile.am b/mu/Makefile.am
index 5534d03..e28b984 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -32,9 +32,17 @@ else
  IDLE_MODULES+=imap.c
 endif
 
+if MU_COND_DBM
+ DBM_C=dbm.c
+ LIBMU_DBM=../libmu_dbm/libmu_dbm.la
+else
+ IDLE_MODULES+=dbm.c
+endif
+
 MODULES = \
  acl.c\
  cflags.c\
+ $(DBM_C)\
  $(IMAP_C)\
  filter.c\
  flt2047.c\
@@ -67,6 +75,7 @@ mu_LDADD = \
  ${MU_LIB_AUTH}\
  @MU_AUTHLIBS@\
  ${MU_LIB_MAILUTILS}\
+ ${LIBMU_DBM} @DBMLIBS@\
  @READLINE_LIBS@ @MU_COMMON_LIBRARIES@
 
 INCLUDES = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@
@@ -77,7 +86,8 @@ AM_CPPFLAGS = \
   -DAUTHLIBS="\"$(MU_AUTHLIBS)\"" \
   -DGUILE_LIBS="\"$(GUILE_LIBS)\"" \
   -DPYTHON_LIBS="\"$(PYTHON_LIBS)\"" \
-  -DI18NLIBS="\"$(LIBINTL)\""
+  -DI18NLIBS="\"$(LIBINTL)\"" \
+  -DDBMLIBS="\"$(DBMLIBS)\""
 
 BUILT_SOURCES=mu-setup.c mu-setup.h
 EXTRA_DIST=mu-setup.awk mu-setup.c mu-setup.h template.c
diff --git a/mu/dbm.c b/mu/dbm.c
new file mode 100644
index 0000000..7f1014f
--- /dev/null
+++ b/mu/dbm.c
@@ -0,0 +1,751 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010, 2011 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 <sys/types.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grp.h>
+#include <sysexits.h>
+#include <fnmatch.h>
+#include <regex.h>
+#include <mailutils/mailutils.h>
+#include <mailutils/dbm.h>
+#include "argp.h"
+#include "mu.h"
+#include "xalloc.h"
+
+static char dbm_doc[] = N_("mu dbm - DBM management tool");
+char dbm_docstring[] = N_("DBM management tool");
+static char dbm_args_doc[] = N_("FILE [KEY...]");
+
+enum mode
+  {
+    mode_list,
+    mode_create,
+    mode_delete,
+    mode_add,
+    mode_replace,
+  };
+
+enum key_type
+  {
+    key_literal,
+    key_glob,
+    key_regex
+  };
+
+enum mode mode;
+char *db_name;
+char *input_file;
+int permissions = 0600;
+struct mu_auth_data *auth;
+uid_t owner_uid = -1;
+gid_t owner_gid = -1;
+int copy_permissions;
+enum key_type key_type = key_literal;
+int case_sensitive = 1;
+int include_zero = -1;
+
+void
+init_datum (struct mu_dbm_datum *key, char *str)
+{
+  memset (key, 0, sizeof *key);
+  key->mu_dptr = str;
+  key->mu_dsize = strlen (str) + !!include_zero;
+}
+
+mu_dbm_file_t
+open_db_file (int mode)
+{
+  int rc;
+  mu_dbm_file_t db;
+  
+  rc = mu_dbm_create (db_name, &db);
+  if (rc)
+    {
+      mu_diag_output (MU_DIAG_ERROR, _("unable to create database %s: %s"),
+		      db_name, mu_strerror (rc));
+      exit (EX_SOFTWARE);
+    }
+
+  rc = mu_dbm_open (db, mode, permissions);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_dbm_open", db_name, rc);
+      exit (EX_SOFTWARE);
+    }
+
+  if (mode == MU_STREAM_CREAT && (owner_uid != -1 || owner_gid != -1))
+    {
+      int dirfd, pagfd;
+      
+      rc = mu_dbm_get_fd (db, &pagfd, &dirfd);
+      if (rc)
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_dbm_get_fd", db_name, rc);
+	  exit (EX_SOFTWARE);
+	}
+      if (owner_uid == -1 || owner_gid == -1)
+	{
+	  struct stat st;
+	  
+	  if (fstat (dirfd, &st))
+	    {
+	      mu_diag_funcall (MU_DIAG_ERROR, "fstat", db_name, errno);
+	      exit (EX_SOFTWARE);
+	    }
+	  if (owner_uid == -1)
+	    owner_uid = st.st_uid;
+	  if (owner_gid == -1)
+	    owner_gid = st.st_gid;
+	}
+      if (fchown (pagfd, owner_uid, owner_gid))
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "fchown", db_name, errno);
+	  exit (EX_SOFTWARE);
+	}
+      if (pagfd != dirfd &&
+	  fchown (dirfd, owner_uid, owner_gid))
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "fchown", db_name, errno);
+	  exit (EX_SOFTWARE);
+	}
+    }
+  return db;
+}
+
+struct print_data
+{
+  mu_dbm_file_t db;
+  mu_stream_t stream;
+};
+  
+static int
+print_action (struct mu_dbm_datum const *key, void *data)
+{
+  int rc;
+  struct mu_dbm_datum contents;
+  struct print_data *pd = data;
+  size_t len;
+  
+  memset (&contents, 0, sizeof contents);
+  rc = mu_dbm_fetch (pd->db, key, &contents);
+  if (rc)
+    {
+      mu_error (_("database fetch error: %s"), mu_dbm_strerror (pd->db));
+      exit (EX_UNAVAILABLE);
+    }
+
+  len = key->mu_dsize;
+  if (key->mu_dptr[len - 1] == 0)
+    len--;
+  mu_stream_write (pd->stream, key->mu_dptr, len, NULL);
+  mu_stream_write (pd->stream, "\t", 1, NULL);
+
+  len = contents.mu_dsize;
+  if (contents.mu_dptr[len - 1] == 0)
+    len--;
+  mu_stream_write (pd->stream, contents.mu_dptr, len, NULL);
+  mu_stream_write (pd->stream, "\n", 1, NULL);
+  mu_dbm_datum_free (&contents);
+  return 0;
+}
+
+static void
+iterate_database (mu_dbm_file_t db,
+		  int (*matcher) (const char *, void *), void *matcher_data,
+		  int (*action) (struct mu_dbm_datum const *, void *),
+		  void *action_data)
+{
+  int rc;
+  struct mu_dbm_datum key;
+  char *buf = NULL;
+  size_t bufsize = 0;
+
+  memset (&key, 0, sizeof key);
+  for (rc = mu_dbm_firstkey (db, &key); rc == 0;
+       rc = mu_dbm_nextkey (db, &key))
+    {
+      if (include_zero == -1)
+	include_zero = key.mu_dptr[key.mu_dsize-1] == 0;
+
+      if (matcher)
+	{
+	  if (key.mu_dsize + 1 > bufsize)
+	    {
+	      bufsize = key.mu_dsize + 1;
+	      buf = xrealloc (buf, bufsize);
+	    }
+	  memcpy (buf, key.mu_dptr, key.mu_dsize);
+	  buf[key.mu_dsize] = 0;
+	  if (!matcher (buf, matcher_data))
+	    continue;
+	}
+      if (action (&key, action_data))
+	break;
+    }
+  free (buf);
+}
+
+static int
+match_literal (const char *str, void *data)
+{
+  char **argv = data;
+
+  for (; *argv; argv++)
+    {
+      if ((case_sensitive ? strcmp : strcasecmp) (str, *argv) == 0)
+	return 1;
+    }
+  return 0;
+}
+
+#ifndef FNM_CASEFOLD
+# define FNM_CASEFOLD 0
+#endif
+
+static int
+match_glob (const char *str, void *data)
+{
+  char **argv = data;
+  
+  for (; *argv; argv++)
+    {
+      if (fnmatch (*argv, str, case_sensitive ? FNM_CASEFOLD : 0) == 0)
+	return 1;
+    }
+  return 0;
+}
+
+struct regmatch
+{
+  int regc;
+  regex_t *regs;
+};
+  
+static int
+match_regex (const char *str, void *data)
+{
+  struct regmatch *match = data;
+  int i;
+  
+  for (i = 0; i < match->regc; i++)
+    {
+      if (regexec (&match->regs[i], str, 0, NULL, 0) == 0)
+	return 1;
+    }
+  return 0;
+}
+
+void
+compile_regexes (int argc, char **argv, struct regmatch *match)
+{
+  regex_t *regs = xcalloc (argc, sizeof (regs[0]));
+  int i;
+  int cflags = (case_sensitive ? 0: REG_ICASE) | REG_EXTENDED | REG_NOSUB;
+  int errors = 0;
+  
+  for (i = 0; i < argc; i++)
+    {
+      int rc = regcomp (&regs[i], argv[i], cflags);
+      if (rc)
+	{
+	  char errbuf[512];
+	  regerror (rc, &regs[i], errbuf, sizeof (errbuf));
+	  mu_error (_("error compiling `%s': %s"), argv[i], errbuf);
+	  errors++;
+	}
+    }
+  if (errors)
+    exit (EX_USAGE);
+  match->regc = argc;
+  match->regs = regs;
+}
+
+static void
+free_regexes (struct regmatch *match)
+{
+  int i;
+  for (i = 0; i < match->regc; i++)
+    regfree (&match->regs[i]);
+  free (match->regs);
+}
+
+static void
+list_database (int argc, char **argv)
+{
+  mu_dbm_file_t db = open_db_file (MU_STREAM_READ);
+  struct print_data pdata;
+
+  pdata.db = db;
+  pdata.stream = mu_strout;
+
+  if (argc == 0)
+    iterate_database (db, NULL, NULL, print_action, &pdata);
+  else
+    {
+      switch (key_type)
+	{
+	case key_literal:
+	  iterate_database (db, match_literal, argv, print_action, &pdata);
+	  break;
+
+	case key_glob:
+	  iterate_database (db, match_glob, argv, print_action, &pdata);
+	  break;
+
+	case key_regex:
+	  {
+	    struct regmatch m;
+	    compile_regexes (argc, argv, &m);
+	    iterate_database (db, match_regex, &m, print_action, &pdata);
+	    free_regexes (&m);
+	  }
+	}
+    }
+  mu_dbm_destroy (&db);
+}
+
+void
+add_records (int mode, int replace)
+{
+  mu_dbm_file_t db;
+  mu_stream_t input, flt;
+  const char *flt_argv[] = { "inline-comment", "#", "-S", "-i", "#", NULL };
+  char *buf = NULL;
+  size_t size = 0;
+  size_t len;
+  unsigned long line;
+  int rc;
+  
+  if (input_file)
+    {
+      rc = mu_file_stream_create (&input, input_file, MU_STREAM_READ);
+      if (rc)
+	{
+	  mu_error (_("cannot open input file %s: %s"), input_file,
+		    mu_strerror (rc));
+	  exit (EX_UNAVAILABLE);
+	}
+    }
+  else
+    input = mu_strin;
+  
+  rc = mu_filter_create_args (&flt, input, "inline-comment",
+			      MU_ARRAY_SIZE (flt_argv) - 1, flt_argv,
+			      MU_FILTER_DECODE, MU_STREAM_READ);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_filter_create_args", input_file, rc);
+      exit (EX_UNAVAILABLE);
+    }
+  mu_stream_unref (input);
+  input = flt;
+
+  db = open_db_file (mode);
+
+  line = 1;
+  if (!input_file)
+    input_file = "<stdin>";
+  while ((rc = mu_stream_getline (input, &buf, &size, &len)) == 0
+	 && len > 0)
+    {
+      struct mu_dbm_datum key, contents;
+      char *kstr, *val;
+      
+      mu_rtrim_class (buf, MU_CTYPE_ENDLN);
+      if (buf[0] == '#')
+	{
+	  line = strtoul (buf + 1, NULL, 10);
+	  continue;
+	}
+      kstr = mu_str_stripws (buf);
+      val = mu_str_skip_class_comp (kstr, MU_CTYPE_SPACE);
+      *val++ = 0;
+      val = mu_str_skip_class (val, MU_CTYPE_SPACE);
+      if (*val == 0)
+	{
+	  mu_error (_("%s:%lu: malformed line"), input_file, line);
+	  line++;
+	  continue;
+	}
+
+      init_datum (&key, kstr);
+      init_datum (&contents, val);
+
+      rc = mu_dbm_store (db, &key, &contents, replace);
+      if (rc)
+	mu_error (_("%s:%lu: cannot store datum: %s"),
+		  input_file, line,
+		  rc == MU_ERR_FAILURE ?
+		     mu_dbm_strerror (db) : mu_strerror (rc));
+      line++;
+    }
+  mu_dbm_destroy (&db);
+
+  mu_stream_unref (input);
+}
+
+static void
+create_database ()
+{
+  if (copy_permissions)
+    {
+      struct stat st;
+      
+      if (!input_file)
+	{
+	  mu_error (_("--copy-permissions used without --file"));
+	  exit (EX_USAGE);
+	}
+      if (stat (input_file, &st))
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "stat", input_file, errno);
+	  exit (EX_UNAVAILABLE);
+	}
+      owner_uid = st.st_uid;
+      owner_gid = st.st_gid;
+      permissions = st.st_mode & 0777;
+    }
+  else if (auth)
+    {
+      if (owner_uid == -1)
+	owner_uid = auth->uid;
+      if (owner_gid == -1)
+	owner_gid = auth->gid;
+    }
+  add_records (MU_STREAM_CREAT, 0);
+}
+
+static int
+store_to_list (struct mu_dbm_datum const *key, void *data)
+{
+  int rc;
+  mu_list_t list = data;
+  char *p = xmalloc (key->mu_dsize + 1);
+  memcpy (p, key->mu_dptr, key->mu_dsize);
+  p[key->mu_dsize] = 0;
+  rc = mu_list_append (list, p);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", p, rc);
+      exit (EX_SOFTWARE);
+    }
+  return 0;
+}
+
+static int
+do_delete (void *item, void *data)
+{
+  char *str = item;
+  mu_dbm_file_t db = data;
+  struct mu_dbm_datum key;
+  int rc;
+
+  init_datum (&key, str);
+  rc = mu_dbm_delete (db, &key);
+  if (rc == MU_ERR_NOENT)
+    {
+      mu_error (_("cannot remove record for %s: %s"),
+		str, mu_strerror (rc));
+    }
+  else if (rc)
+    {
+      mu_error (_("cannot remove record for %s: %s"),
+		str, mu_dbm_strerror (db));
+      if (rc != MU_ERR_NOENT)
+	exit (EX_UNAVAILABLE);
+    }
+  return 0;
+}
+
+static void
+delete_database (int argc, char **argv)
+{
+  mu_dbm_file_t db = open_db_file (MU_STREAM_RDWR);
+  mu_list_t templist = NULL;
+  int rc, i;
+  
+  if (argc == 0)
+    {
+      mu_error (_("not enough arguments for delete"));
+      exit (EX_USAGE);
+    }
+
+  /* Collect matching keys */
+  rc = mu_list_create (&templist);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_list_create", NULL, rc);
+      exit (EX_SOFTWARE);
+    }
+  mu_list_set_destroy_item (templist, mu_list_free_item);
+  switch (key_type)
+    {
+    case key_literal:
+      for (i = 0; i < argc; i++)
+	{
+	  char *p = xstrdup (argv[i]);
+	  rc = mu_list_append (templist, p);
+	  if (rc)
+	    {
+	      mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", p, rc);
+	      exit (EX_SOFTWARE);
+	    }
+	}
+      break;
+
+    case key_glob:
+      iterate_database (db, match_glob, argv,
+			store_to_list, templist);
+      break;
+
+    case key_regex:
+      {
+	struct regmatch m;
+	
+	compile_regexes (argc, argv, &m);
+	iterate_database (db, match_regex, &m, store_to_list, templist);
+	free_regexes (&m);
+      }
+    }
+  mu_list_do (templist, do_delete, db);
+  mu_list_destroy (&templist);
+  mu_dbm_destroy (&db);
+}
+
+/*
+  mu dbm --create a.db < input
+  mu dbm --list a.db
+  mu dbm --delete a.db key [key...]
+  mu dbm --add a.db < input
+  mu dbm --replace a.db < input
+ */
+
+static struct argp_option dbm_options[] = {
+  { NULL, 0, NULL, 0, N_("Operation mode"), 0},
+  { "create", 'c', NULL, 0, N_("create the database") },
+  { "list",   'l', NULL, 0, N_("list contents of the database") },
+  { "delete", 'd', NULL, 0, N_("delete specified keys from the database") },
+  { "add",    'a', NULL, 0, N_("add records to the database") },
+  { "replace",'r', NULL, 0, N_("add records replacing ones with matching keys") },
+  
+  { NULL, 0, NULL, 0, N_("Create modifiers"), 0},
+  { "file",   'f', N_("FILE"), 0,
+    N_("read input from FILE (with --create, --delete, --add and --replace)") },
+  { "permissions", 'p', N_("NUM"), 0,
+    N_("set permissions on the created database") },
+  { "user",        'u', N_("USER"), 0,
+    N_("set database owner name") },
+  { "group",       'g', N_("GROUP"), 0,
+    N_("set database owner group") },
+  { "copy-permissions", 'P', NULL, 0,
+    N_("copy database permissions and ownership from the input file") },
+  { NULL, 0, NULL, 0, N_("List and Delete modifiers"), 0},
+  { "glob",        'G', NULL, 0,
+    N_("treat keys as globbing patterns") },
+  { "regex",       'R', NULL, 0,
+    N_("treat keys as regular expressions") },
+  { "ignore-case", 'i', NULL, 0,
+    N_("case-insensitive matches") },
+  { NULL, 0, NULL, 0, N_("Data length modifiers"), 0 },
+  { "count-null",  'N', NULL, 0,
+    N_("data length accounts for terminating zero") },
+  { "no-count-null", 'n', NULL, 0,
+    N_("data length does not account for terminating zero") },
+  { NULL }
+};
+
+static error_t
+dbm_parse_opt (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+    {
+    case 'c':
+      mode = mode_create;
+      break;
+
+    case 'l':
+      mode = mode_list;
+      break;
+
+    case 'd':
+      mode = mode_delete;
+      break;
+
+    case 'a':
+      mode = mode_add;
+      break;
+
+    case 'r':
+      mode = mode_replace;
+      break;
+
+    case 'f':
+      input_file = arg;
+      break;
+
+    case 'p':
+      {
+	char *p;
+	unsigned long d = strtoul (arg, &p, 8);
+	if (*p || (d & ~0777))
+	  argp_error (state, _("invalid file mode: %s"), arg);
+	permissions = d;
+      }
+      break;
+
+    case 'P':
+      copy_permissions = 1;
+      break;
+
+    case 'u':
+      auth = mu_get_auth_by_name (arg);
+      if (!auth)
+	{
+	  char *p;
+	  unsigned long n = strtoul (arg, &p, 0);
+	  if (*p == 0)
+	    owner_uid = n;
+	  else
+	    argp_error (state, _("no such user: %s"), arg);
+	}
+      break;
+
+    case 'g':
+      {
+	struct group *gr = getgrnam (arg);
+	if (!gr)
+	  {
+	    char *p;
+	    unsigned long n = strtoul (arg, &p, 0);
+	    if (*p == 0)
+	      owner_gid = n;
+	    else
+	      argp_error (state, _("no such group: %s"), arg);
+	  }
+	else
+	  owner_gid = gr->gr_gid;
+      }
+      break;
+
+    case 'G':
+      key_type = key_glob;
+      break;
+
+    case 'R':
+      key_type = key_regex;
+      break;
+
+    case 'i':
+      case_sensitive = 0;
+      break;
+
+    case 'N':
+      include_zero = 1;
+      break;
+
+    case 'n':
+      include_zero = 0;
+      break;
+      
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+static struct argp dbm_argp = {
+  dbm_options,
+  dbm_parse_opt,
+  dbm_args_doc,
+  dbm_doc,
+  NULL,
+  NULL,
+  NULL
+};
+
+int
+mutool_dbm (int argc, char **argv)
+{
+  int index;
+  
+  if (argp_parse (&dbm_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
+    return 1;
+
+  argc -= index;
+  argv += index;
+
+  if (argc == 0)
+    {
+      mu_error (_("database name not given"));
+      exit (EX_USAGE);
+    }
+  db_name = *argv++;
+  --argc;
+
+  switch (mode)
+    {
+    case mode_list:
+      list_database (argc, argv);
+      break;
+      
+    case mode_create:
+      if (argc)
+	{
+	  mu_error (_("too many arguments for create"));
+	  exit (EX_USAGE);
+	}
+      create_database ();
+      break;
+      
+    case mode_delete:
+      delete_database (argc, argv);
+      break;
+      
+    case mode_add:
+      if (argc)
+	{
+	  mu_error (_("too many arguments for add"));
+	  exit (EX_USAGE);
+	}
+      add_records (MU_STREAM_RDWR, 0);
+      break;
+      
+    case mode_replace:
+      if (argc)
+	{
+	  mu_error (_("too many arguments for replace"));
+	  exit (EX_USAGE);
+	}
+      add_records (MU_STREAM_RDWR, 1);
+      break;
+    }
+  return 0;
+}
+
+/*
+  MU Setup: dbm
+  mu-handler: mutool_dbm
+  mu-docstring: dbm_docstring
+  End MU Setup:
+*/
+  
+
diff --git a/mu/ldflags.c b/mu/ldflags.c
index 3d838b5..0576c02 100644
--- a/mu/ldflags.c
+++ b/mu/ldflags.c
@@ -38,36 +38,52 @@ static struct argp ldflags_argp = {
 
 
 #ifdef WITH_TLS
-# define NEEDAUTH 1
+# define NEEDAUTH "-lmu_auth " AUTHLIBS
 #else
-# define NEEDAUTH 0
+# define NEEDAUTH NULL
 #endif
-#define NOTALL   2
+#define NOTALL   1
 
 struct lib_descr {
   char *name;
   char *libname;
+  int weight;
   int flags;
 } lib_descr[] = {
-  { "mbox",   "mu_mbox", 0 },
+  { "mbox",    "-lmu_mbox", 0 },
 #ifdef ENABLE_MH
-  { "mh",     "mu_mh",   0 },
+  { "mh",      "-lmu_mh",   0 },
 #endif
 #ifdef ENABLE_MAILDIR
-  { "maildir","mu_maildir", 0 },
+  { "maildir", "-lmu_maildir", 0 },
 #endif
 #ifdef ENABLE_IMAP  
-  { "imap",   "mu_imap", NEEDAUTH },
+  { "imap",    "-lmu_imap", 0 },
+  { "imap",    NEEDAUTH,    2 },
 #endif
 #ifdef ENABLE_POP  
-  { "pop",    "mu_pop",  NEEDAUTH },
+  { "pop",    "-lmu_pop",   0 },
+  { "pop",    NEEDAUTH,     2 },
 #endif
 #ifdef ENABLE_NNTP  
-  { "nntp",   "mu_nntp", 0 },
+  { "nntp",   "-lmu_nntp",  0 },
 #endif
-  { "mailer", "mu_mailer", 0 },
-  { "sieve",  "mu_sieve", NOTALL },
-  { "compat", "mu_compat" },
+#ifdef ENABLE_DBM
+  { "dbm",    "-lmu_dbm",   0 },
+  { "dbm",    DBMLIBS,      2 },
+#endif
+  { "mailer", "-lmu_mailer", 0 },
+  { "sieve",  "-lmu_sieve",  0, NOTALL },
+  { "compat", "-lmu_compat", 0 },
+  { "auth",   "-lmu_auth " AUTHLIBS, 2 },
+#ifdef WITH_GUILE	      
+  { "guile",  "-lmu_scm " GUILE_LIBS, -1, NOTALL },
+#endif
+#ifdef WITH_PYTHON
+  { "python", "-lmu_py " PYTHON_LIBS, -1, NOTALL },
+#endif
+  { "cfg",    "-lmu_cfg",  -1, NOTALL },
+  { "argp",   "-lmu_argp", -2, NOTALL },
   { NULL }
 };
 
@@ -82,6 +98,9 @@ void
 add_entry (int level, char *ptr)
 {
   int i;
+
+  if (!ptr || !*ptr)
+    return;
   if (nentry >= sizeof(lib_entry)/sizeof(lib_entry[0]))
     {
       mu_error (_("too many arguments"));
@@ -122,7 +141,6 @@ int
 mutool_ldflags (int argc, char **argv)
 {
   int i, j;
-  char *ptr;
   
   if (argp_parse (&ldflags_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
     return 1;
@@ -140,21 +158,7 @@ mutool_ldflags (int argc, char **argv)
 
   for ( ; argc > 0; argc--, argv++)
     {
-      if (strcmp (argv[0], "auth") == 0)
-	add_entry (2, "-lmu_auth " AUTHLIBS);
-#ifdef WITH_GUILE	      
-      else if (strcmp (argv[0], "guile") == 0)
-	add_entry (-1, "-lmu_scm " GUILE_LIBS);
-#endif
-#ifdef WITH_PYTHON
-      else if (strcmp (argv[0], "python") == 0)
-	add_entry (-1, "-lmu_py " PYTHON_LIBS);
-#endif
-      else if (strcmp (argv[0], "cfg") == 0)
-	add_entry (-1, "-lmu_cfg");
-      else if (strcmp (argv[0], "argp") == 0)
-	add_entry (-2, "-lmu_argp");
-      else if (strcmp (argv[0], "all") == 0)
+      if (strcmp (argv[0], "all") == 0)
 	{
 	  struct lib_descr *p;
 		  
@@ -162,28 +166,24 @@ mutool_ldflags (int argc, char **argv)
 	    {
 	      if (p->flags & NOTALL)
 		continue;
-	      mu_asprintf (&ptr, "-l%s", p->libname);
-	      add_entry (0, ptr);
-	      if (p->flags & NEEDAUTH)
-		add_entry (2, "-lmu_auth " AUTHLIBS);
+	      add_entry (p->weight, p->libname);
 	    }
 	}
       else
 	{
 	  struct lib_descr *p;
+	  int found = 0;
 	  
 	  for (p = lib_descr; p->name; p++)
-	    if (mu_c_strcasecmp (p->name, argv[0]) == 0)
-	      break;
-
-	  if (p->name)
 	    {
-	      mu_asprintf (&ptr, "-l%s", p->libname);
-	      add_entry (0, ptr);
-	      if (p->flags & NEEDAUTH)
-		add_entry (2, "-lmu_auth " AUTHLIBS);
+	      if (mu_c_strcasecmp (p->name, argv[0]) == 0)
+		{
+		  add_entry (p->weight, p->libname);
+		  found = 1;
+		}
 	    }
-	  else
+
+	  if (!found)
 	    {
 	      mu_error (_("unknown keyword: %s"), argv[0]);
 	      return 1;
diff --git a/pop3d/Makefile.am b/pop3d/Makefile.am
index 7aeae8c..b5f6add 100644
--- a/pop3d/Makefile.am
+++ b/pop3d/Makefile.am
@@ -46,6 +46,10 @@ pop3d_SOURCES =\
  uidl.c\
  user.c
 
+if MU_COND_DBM
+  LIBMU_DBM=../libmu_dbm/libmu_dbm.la
+endif
+
 pop3d_LDADD = \
  ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
@@ -54,15 +58,25 @@ pop3d_LDADD = \
  ${MU_LIB_AUTH}\
  @MU_AUTHLIBS@ \
  ${MU_LIB_MAILUTILS}\
- @MU_COMMON_LIBRARIES@ @TCPWRAP_LIBRARIES@
+ @MU_COMMON_LIBRARIES@\
+ ${LIBMU_DBM}\
+ @DBMLIBS@\
+ @TCPWRAP_LIBRARIES@
 
 popauth_SOURCES = popauth.c
-popauth_LDADD = ${MU_APP_LIBRARIES} ${MU_LIB_MAILUTILS} @MU_COMMON_LIBRARIES@
+popauth_LDADD = \
+ ${MU_APP_LIBRARIES}\
+ ${MU_LIB_MAILUTILS}\
+ @MU_COMMON_LIBRARIES@\
+ ${LIBMU_DBM}\
+ @DBMLIBS@
+
 pop3d_DEPENDENCIES = \
  @MU_AUTHLIBS_DEPENDENCY@ \
  ../lib/libmuaux.a \
  ${MU_LIB_MBOX}\
  ${MU_LIB_MH}\
  ${MU_LIB_MAILDIR}\
- ${MU_LIB_MAILUTILS}
+ ${MU_LIB_MAILUTILS}\
+ ${LIBMU_DBM}
 
diff --git a/pop3d/apop.c b/pop3d/apop.c
index 1b89ab3..7a2697f 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -43,59 +43,85 @@ pop3d_apopuser (const char *user)
 {
   char *password = NULL;
   
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
   {
     size_t len;
-    DBM_FILE db;
-    DBM_DATUM key, data;
+    mu_dbm_file_t db;
+    struct mu_dbm_datum key, data;
+    int rc;
 
-    int rc = mu_dbm_open (APOP_PASSFILE, &db, MU_STREAM_READ, 0600);
+    rc = mu_dbm_create (APOP_PASSFILE, &db);
+    if (rc)
+      {
+	mu_diag_output (MU_DIAG_ERROR, _("unable to create APOP db"));
+	return NULL;
+      }
+
+    rc = mu_dbm_safety_check (db);
+    if (rc)
+      {
+	mu_diag_output (MU_DIAG_ERROR,
+			_("APOP file %s fails safety check: %s"),
+			APOP_PASSFILE, mu_strerror (rc));
+	mu_dbm_destroy (&db);
+	return NULL;
+      }
+    
+    rc = mu_dbm_open (db, MU_STREAM_READ, 0600);
     if (rc)
       {
 	mu_diag_output (MU_DIAG_ERROR, _("unable to open APOP db: %s"),
-		mu_strerror (errno));
+			mu_strerror (rc));
 	return NULL;
       }
 
     memset (&key, 0, sizeof key);
     memset (&data, 0, sizeof data);
 
-    MU_DATUM_PTR (key) = (void*) user;
-    MU_DATUM_SIZE (key) = strlen (user);
+    key.mu_dptr = (void *)user;
+    key.mu_dsize = strlen (user);
 
-    rc = mu_dbm_fetch (db, key, &data);
-    mu_dbm_close (db);
-    if (rc)
+    rc = mu_dbm_fetch (db, &key, &data);
+    if (rc == MU_ERR_NOENT)
+      {
+	mu_dbm_destroy (&db);
+	return NULL;
+      }
+    else if (rc)
       {
 	mu_diag_output (MU_DIAG_ERROR,
-			_("cannot fetch APOP data: %s"), mu_strerror (errno));
+			_("cannot fetch APOP data: %s"),
+			mu_dbm_strerror (db));
+	mu_dbm_destroy (&db);
 	return NULL;
       }
-    len = MU_DATUM_SIZE (data);
+    mu_dbm_destroy (&db);
+    len = data.mu_dsize;
     password = malloc (len + 1);
     if (password == NULL)
       {
 	mu_dbm_datum_free (&data);
 	return NULL;
       }
-    memcpy (password, MU_DATUM_PTR (data), len);
+    memcpy (password, data.mu_dptr, len);
     password[len] = 0;
     mu_dbm_datum_free (&data);
     return password;
   }
-#else /* !USE_DBM */
+#else /* !ENABLE_DBM */
   {
     char *buf = NULL;
     size_t size = 0;
     size_t ulen;
     FILE *apop_file;
 
-    if (mu_check_perm (APOP_PASSFILE, 0600))
-      {
-	mu_diag_output (MU_DIAG_INFO,
-			_("bad permissions on APOP password file"));
-	return NULL;
-    }
+    /* FIXME */    
+/*     if (mu_check_perm (APOP_PASSFILE, 0600)) */
+/*       { */
+/* 	mu_diag_output (MU_DIAG_INFO, */
+/* 			_("bad permissions on APOP password file")); */
+/* 	return NULL; */
+/*     } */
 
     apop_file = fopen (APOP_PASSFILE, "r");
     if (apop_file == NULL)
diff --git a/pop3d/bulletin.c b/pop3d/bulletin.c
index 90aeaea..7bfd052 100644
--- a/pop3d/bulletin.c
+++ b/pop3d/bulletin.c
@@ -113,58 +113,72 @@ write_popbull_file (size_t num)
   return rc;
 }
 
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
 int
 read_bulletin_db (size_t *pnum)
 {
-  DBM_FILE db;
-  DBM_DATUM key, data;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, data;
   int rc;
   char sbuf[128];
   char *bufptr;
   char *buf = NULL;
   size_t s;
   char *p;
-  
-  rc = mu_dbm_open (bulletin_db_name, &db, MU_STREAM_READ, 0660);
+
+  rc = mu_dbm_create (bulletin_db_name, &db);
   if (rc)
     {
-      if (errno == ENOENT)
+      mu_diag_output (MU_DIAG_ERROR, _("unable to create bulletin db"));
+      return rc;
+    }
+
+  rc = mu_dbm_safety_check (db);
+  if (rc)
+    {
+      if (rc == ENOENT)
 	{
 	  *pnum = 0;
 	  return 0;
 	}
-      else
-	{
-	  mu_error (_("unable to open bulletin db for reading: %s"),
-		    mu_strerror (errno));
-	  return rc;
-	}
+      mu_diag_output (MU_DIAG_ERROR,
+		      _("bulletin db %s fails safety check: %s"),
+		      bulletin_db_name, mu_strerror (rc));
+      mu_dbm_destroy (&db);
+      return 1;
+    }
+  
+  rc = mu_dbm_open (db, MU_STREAM_READ, 0660);
+  if (rc)
+    {
+      mu_error (_("unable to open bulletin db for reading: %s"),
+		mu_strerror (rc));
+      return rc;
     }
 
   memset (&key, 0, sizeof key);
   memset (&data, 0, sizeof data);
 
-  MU_DATUM_PTR(key) = username;
-  MU_DATUM_SIZE(key) = strlen (username);
+  key.mu_dptr = username;
+  key.mu_dsize = strlen (username);
 
-  rc = mu_dbm_fetch (db, key, &data);
+  rc = mu_dbm_fetch (db, &key, &data);
 
-  if (rc)
+  if (rc == MU_ERR_NOENT)
+    {
+      *pnum = 0;
+      return 0;
+    }
+  else if (rc)
     {
-      int ec = errno;
-      if (ec == ENOENT)
-        {
-           *pnum = 0;
-           return 0;
-        }
       mu_error (_("cannot fetch bulletin db data: %s"),
-		mu_strerror (ec));
-      mu_dbm_close (db);
+		mu_dbm_strerror (db));
+      mu_dbm_destroy (&db);
       return 1;
     }
+  mu_dbm_destroy (&db);
   
-  s = MU_DATUM_SIZE (data);
+  s = data.mu_dsize;
   if (s < sizeof sbuf)
     bufptr = sbuf;
   else
@@ -172,16 +186,15 @@ read_bulletin_db (size_t *pnum)
       buf = malloc (s + 1);
       if (!buf)
 	{
-	  mu_error("%s", mu_strerror (errno));
+	  mu_error ("%s", mu_strerror (errno));
 	  return 1;
 	}
       bufptr = buf;
     }
 
-  memcpy (bufptr, MU_DATUM_PTR (data), s);
+  memcpy (bufptr, data.mu_dptr, s);
   bufptr[s] = 0;
-  mu_dbm_datum_free(&data);
-  mu_dbm_close (db);
+  mu_dbm_datum_free (&data);
 
   rc = 1;
   *pnum = strtoul (bufptr, &p, 0);
@@ -189,26 +202,8 @@ read_bulletin_db (size_t *pnum)
     rc = 0;
   else
     {
-#ifdef QPOPPER_COMPAT
-      if (s == sizeof long)
-	{
-	  long n;
-
-	  n = *(long*)MU_DATUM_PTR (data);
-	  if (n >= 0)
-	    {
-	      mu_diag_output (MU_DIAG_INFO,
-		      _("assuming bulletin database is in qpopper format"));
-	      *pnum = n;
-	      rc = 0;
-	    }
-	}
-      else
-#endif /* QPOPPER_COMPAT */
-	{
-	  mu_error (_("wrong bulletin database format for `%s'"),
-		    username);
-	}
+      mu_error (_("wrong bulletin database format for `%s'"),
+		username);
     }
   
   free (buf);
@@ -218,41 +213,60 @@ read_bulletin_db (size_t *pnum)
 int
 write_bulletin_db (size_t num)
 {
-  DBM_FILE db;
-  DBM_DATUM key, data;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, data;
   int rc;
   const char *p;
   
-  rc = mu_dbm_open (bulletin_db_name, &db, MU_STREAM_RDWR, 0660);
+  rc = mu_dbm_create (bulletin_db_name, &db);
+  if (rc)
+    {
+      mu_diag_output (MU_DIAG_ERROR, _("unable to create bulletin db"));
+      return rc;
+    }
+
+  rc = mu_dbm_safety_check (db);
+  if (rc && rc != ENOENT)
+    {
+      mu_diag_output (MU_DIAG_ERROR,
+		      _("bulletin db %s fails safety check: %s"),
+		      bulletin_db_name, mu_strerror (rc));
+      mu_dbm_destroy (&db);
+      return rc;
+    }
+
+  rc = mu_dbm_open (db, MU_STREAM_RDWR, 0660);
   if (rc)
     {
       mu_error (_("unable to open bulletin db for writing: %s"),
-		mu_strerror (errno));
+		mu_strerror (rc));
+      mu_dbm_destroy (&db);
       return rc;
     }
 
   memset (&key, 0, sizeof key);
   memset (&data, 0, sizeof data);
 
-  MU_DATUM_PTR (key) = username;
-  MU_DATUM_SIZE (key) = strlen (username);
+  key.mu_dptr = username;
+  key.mu_dsize = strlen (username);
   p = mu_umaxtostr (0, num);
-  MU_DATUM_PTR (data) = (char *) p;
-  MU_DATUM_SIZE (data) = strlen (p);
+  data.mu_dptr = (char *) p;
+  data.mu_dsize = strlen (p);
 
-  rc = mu_dbm_insert (db, key, data, 1);
+  rc = mu_dbm_store (db, &key, &data, 1);
   if (rc)
-    mu_error (_("cannot store datum in bulletin db"));
-
-  mu_dbm_close (db);
+    mu_error (_("cannot store datum in bulletin db: %s"),
+	      mu_dbm_strerror (db));
+  
+  mu_dbm_destroy (&db);
   return rc;
 }
-#endif /* USE_DBM */
+#endif /* ENABLE_DBM */
       
 int
 get_last_delivered_num (size_t *pret)
 {
-#ifdef USE_DBM  
+#ifdef ENABLE_DBM  
   if (bulletin_db_name && read_bulletin_db (pret) == 0)
     return 0;
 #endif
@@ -262,7 +276,7 @@ get_last_delivered_num (size_t *pret)
 void
 store_last_delivered_num (size_t num)
 {
-#ifdef USE_DBM  
+#ifdef ENABLE_DBM  
   if (bulletin_db_name && write_bulletin_db (num) == 0)
     return;
 #endif
diff --git a/pop3d/logindelay.c b/pop3d/logindelay.c
index d726c15..21794ca 100644
--- a/pop3d/logindelay.c
+++ b/pop3d/logindelay.c
@@ -19,27 +19,45 @@
 
 #ifdef ENABLE_LOGIN_DELAY
 
-static int
-open_stat_db (DBM_FILE *db, int mode)
+static mu_dbm_file_t
+open_stat_db (int mode)
 {
-  int rc = mu_dbm_open (login_stat_file, db, mode, 0660);
+  mu_dbm_file_t db;
+  int rc;
+
+  rc = mu_dbm_create (login_stat_file, &db);
   if (rc)
     {
-      if (rc == -1)
-	mu_diag_output (MU_DIAG_INFO, _("bad permissions on statistics db"));
-      else
-	mu_diag_output (MU_DIAG_ERROR, _("unable to open statistics db: %s"),
-		mu_strerror (rc));
+      mu_diag_output (MU_DIAG_ERROR, _("unable to create statistics db"));
+      return NULL;
+    }
+
+  rc = mu_dbm_safety_check (db);
+  if (rc)
+    {
+      mu_diag_output (MU_DIAG_ERROR,
+		      _("statistics db fails safety check: %s"),
+		      mu_strerror (rc));
+      mu_dbm_destroy (&db);
+      return NULL;
     }
-  return rc;
+  
+  rc = mu_dbm_open (db, mode, 0660);
+  if (rc)
+    {
+      mu_diag_output (MU_DIAG_ERROR, _("unable to open statistics db: %s"),
+		      mu_dbm_strerror (db));
+      mu_dbm_destroy (&db);
+    }
+  return db;
 }
 
 int
 check_login_delay (char *username)
 {
   time_t now, prev_time;
-  DBM_FILE db;
-  DBM_DATUM key, data;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, data;
   char text[64], *p;
   int rc;
 
@@ -47,42 +65,45 @@ check_login_delay (char *username)
     return 0;
   
   time (&now);
-  if (open_stat_db (&db, MU_STREAM_RDWR))
+  db = open_stat_db (MU_STREAM_READ);
+  if (!db)
     return 0;
   
   memset (&key, 0, sizeof key);
-  MU_DATUM_PTR(key) = username;
-  MU_DATUM_SIZE(key) = strlen (username);
+  key.mu_dptr = username;
+  key.mu_dsize = strlen (username);
   memset (&data, 0, sizeof data);
 
-  rc = mu_dbm_fetch (db, key, &data);
+  rc = mu_dbm_fetch (db, &key, &data);
   if (rc)
     {
-      mu_diag_output (MU_DIAG_ERROR, _("cannot fetch login delay data: %s"),
-	      mu_strerror (rc));
-      mu_dbm_close (db);
+      if (rc != MU_ERR_NOENT)
+	mu_diag_output (MU_DIAG_ERROR, _("cannot fetch login delay data: %s"),
+			mu_dbm_strerror (db));
+      mu_dbm_destroy (&db);
       return 0;
     }
 
-  if (MU_DATUM_SIZE(data) > sizeof (text) - 1)
+  if (data.mu_dsize > sizeof (text) - 1)
     {
       mu_diag_output (MU_DIAG_ERROR,
 		      _("invalid entry for '%s': wrong timestamp size"),
-	      username);
-      mu_dbm_close (db);
+		      username);
+      mu_dbm_destroy (&db);
       return 0;
     }
+  mu_dbm_destroy (&db);
 
-  memcpy (text, MU_DATUM_PTR(data), MU_DATUM_SIZE(data));
-  text[MU_DATUM_SIZE(data)] = 0;
-  mu_dbm_close (db);
-
+  memcpy (text, data.mu_dptr, data.mu_dsize);
+  text[data.mu_dsize] = 0;
+  mu_dbm_datum_free (&data);
+  
   prev_time = strtoul (text, &p, 0);
   if (*p)
     {
       mu_diag_output (MU_DIAG_ERROR,
 		      _("malformed timestamp for '%s': %s"),
-	      username, text);
+		      username, text);
       return 0;
     }
 
@@ -93,40 +114,42 @@ void
 update_login_delay (char *username)
 {
   time_t now;
-  DBM_FILE db;
-  DBM_DATUM key, data;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, data;
   char text[64];
   
   if (login_delay == 0 || username == NULL)
     return;
 
   time (&now);
-  if (open_stat_db (&db, MU_STREAM_RDWR))
+  db = open_stat_db (MU_STREAM_RDWR);
+  if (!db)
     return;
   
   memset(&key, 0, sizeof(key));
   memset(&data, 0, sizeof(data));
-  MU_DATUM_PTR(key) = username;
-  MU_DATUM_SIZE(key) = strlen (username);
+  key.mu_dptr = username;
+  key.mu_dsize = strlen (username);
   snprintf (text, sizeof text, "%lu", (unsigned long) now);
-  MU_DATUM_PTR(data) = text;
-  MU_DATUM_SIZE(data) = strlen (text);
-  if (mu_dbm_insert (db, key, data, 1))
-    mu_error (_("%s: cannot store datum %s/%s"),
-	      login_stat_file, username, text);
+  data.mu_dptr = text;
+  data.mu_dsize = strlen (text);
+  if (mu_dbm_store (db, &key, &data, 1))
+    mu_error (_("%s: cannot store datum %s/%s: %s"),
+	      login_stat_file, username, text,
+	      mu_dbm_strerror (db));
   
-  mu_dbm_close (db);
+  mu_dbm_destroy (&db);
 }
 
 void
 login_delay_capa ()
 {
-  DBM_FILE db;
+  mu_dbm_file_t db;
   
-  if (login_delay && open_stat_db (&db, MU_STREAM_RDWR) == 0)
+  if (login_delay && (db = open_stat_db (MU_STREAM_RDWR)) != NULL)
     {
       pop3d_outf ("LOGIN-DELAY %s\n", mu_umaxtostr (0, login_delay));
-      mu_dbm_close (db);
+      mu_dbm_destroy (&db);
     }
 }
 #endif
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 9a5f47d..5652b9d 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -77,7 +77,7 @@ cb_bulletin_source (void *data, mu_config_value_t *val)
   return 0;
 }
 
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
 static int
 cb_bulletin_db (void *data, mu_config_value_t *val)
 {
@@ -111,7 +111,7 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
   { "bulletin-source", mu_cfg_callback, NULL, 0, cb_bulletin_source,
     N_("Get bulletins from the specified mailbox."),
     N_("url") },
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
   { "bulletin-db", mu_cfg_callback, NULL, 0, cb_bulletin_db,
     N_("Set the bulletin database file name."),
     N_("file") },
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index ea43fb5..833eb7f 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -24,7 +24,7 @@
 #include <mailutils/types.h>
 #include <mailutils/stream.h>
 #include <mailutils/io.h>
-#include <mu_dbm.h>
+#include <mailutils/dbm.h>
 #include <mu_umaxtostr.h>
 #include <muaux.h>
 
@@ -35,7 +35,7 @@
    type automatically */
 #define APOP_PASSFILE_NAME "apop"
 
-#ifdef USE_DBM
+#ifdef ENABLE_DBM
 # define APOP_PASSFILE SYSCONFDIR "/" APOP_PASSFILE_NAME
 # define ENABLE_LOGIN_DELAY
 #else
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index 9ea4ba4..8ae7c95 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -73,7 +73,7 @@ static struct argp_option options[] =
 
   { NULL, 0, NULL, 0,
     N_("Default action is:\n"
-    "  For the file owner: --list\n"
+    "  For root: --list\n"
     "  For a user: --modify --user <username>\n"), 2 },
   
   { NULL, 0, NULL, 0, N_("Options are:"), 3 },
@@ -197,7 +197,7 @@ popauth_parse_opt (int key, char *arg, struct argp_state *astate)
 }
 
 int
-main(int argc, char **argv)
+main (int argc, char **argv)
 {
   struct action_data adata;
 
@@ -223,41 +223,121 @@ check_action (int action)
     }
 }
 
-int
-check_user_perm (int action, struct action_data *ap)
+mu_dbm_file_t
+open_db_file (int action, struct action_data *ap, int *my_file)
 {
-  struct stat sb;
+  mu_dbm_file_t db;
   struct passwd *pw;
   uid_t uid;
+  int rc;
+  int flags = 0;
+  char *db_name = NULL;
+  int fd;
+  struct stat sb;
+  int safety_flags = MU_FILE_SAFETY_ALL & ~MU_FILE_SAFETY_OWNER_MISMATCH;
   
-  if (!ap->input_name)
-    ap->input_name = APOP_PASSFILE;
-
-  if (mu_dbm_stat (ap->input_name, &sb))
+  switch (action)
     {
-      if (ap->action == ACT_ADD)
-	{
-	  DBM_FILE db;
-	  if (mu_dbm_open (ap->input_name, &db, MU_STREAM_CREAT, permissions))
-	    {
-	      mu_diag_funcall (MU_DIAG_ERROR, "mu_dbm_open",
-			       ap->input_name, errno);
-	      exit (EX_SOFTWARE);
-	    }
-	  mu_dbm_close (db);
-	  mu_dbm_stat (ap->input_name, &sb);
-	}
-      else
-	{
-	  mu_diag_funcall (MU_DIAG_ERROR, "stat", ap->input_name, errno);
-	  exit (EX_OSERR);
-	}
+    case ACT_CREATE:
+      flags = MU_STREAM_CREAT;
+      safety_flags = MU_FILE_SAFETY_NONE;
+      db_name = ap->output_name;
+      break;
+
+    case ACT_ADD:
+    case ACT_DELETE:
+      if (!ap->input_name)
+	ap->input_name = APOP_PASSFILE;
+      flags = MU_STREAM_RDWR;
+      db_name = ap->input_name;
+      break;
+      
+    case ACT_LIST:
+      if (!ap->input_name)
+	ap->input_name = APOP_PASSFILE;
+      flags = MU_STREAM_READ;
+      safety_flags = MU_FILE_SAFETY_NONE;
+      db_name = ap->input_name;
+      break;
+
+    case ACT_CHPASS:
+      if (!ap->input_name)
+	ap->input_name = APOP_PASSFILE;
+      flags = MU_STREAM_RDWR;
+      db_name = ap->input_name;
+      break;
+      
+    default:
+      abort ();
     }
 
   uid = getuid ();
-  if (uid == 0 || sb.st_uid == uid)
-    return 0;
 
+  rc = mu_dbm_create (db_name, &db);
+  if (rc)
+    {
+      mu_diag_output (MU_DIAG_ERROR, _("unable to create database %s: %s"),
+		      db_name, mu_strerror (rc));
+      exit (EX_SOFTWARE);
+    }
+
+  //  mu_dbm_safety_set_owner (db, uid);
+  /* Adjust safety flags */
+  if (permissions & 0002)
+    safety_flags &= ~MU_FILE_SAFETY_WORLD_WRITABLE;
+  if (permissions & 0004)
+    safety_flags &= ~MU_FILE_SAFETY_WORLD_READABLE;
+  if (permissions & 0020)
+    safety_flags &= ~MU_FILE_SAFETY_GROUP_WRITABLE;
+  if (permissions & 0040)
+    safety_flags &= ~MU_FILE_SAFETY_GROUP_READABLE;
+  
+  mu_dbm_safety_set_flags (db, safety_flags);
+  rc = mu_dbm_safety_check (db);
+  if (rc && rc != ENOENT)
+    {
+      mu_diag_output (MU_DIAG_ERROR,
+		      _("%s fails safety check: %s"),
+		      db_name, mu_strerror (rc));
+      mu_dbm_destroy (&db);
+      exit (EX_UNAVAILABLE);
+    }
+  
+  rc = mu_dbm_open (db, flags, permissions);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_dbm_open",
+		       db_name, rc);
+      exit (EX_SOFTWARE);
+    }
+
+  if (uid == 0)
+    return db;
+
+  rc = mu_dbm_get_fd (db, &fd, NULL);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_dbm_get_fd",
+		       db_name, rc);
+      exit (EX_SOFTWARE);
+    }
+
+  if (fstat (fd, &sb))
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "fstat",
+		       db_name, errno);
+      exit (EX_SOFTWARE);
+    }
+
+  if (sb.st_uid == uid)
+    {
+      if (my_file)
+	*my_file = 1;
+      return db;
+    }
+  if (my_file)
+    *my_file = 0;
+    
   if (ap->username)
     {
       mu_error (_("Only the file owner can use --username"));
@@ -273,41 +353,36 @@ check_user_perm (int action, struct action_data *ap)
   if (!pw)
     exit (EX_OSERR);
   ap->username = pw->pw_name;
-  return 1;
+  return db;
 }
 
 static void
-print_entry (mu_stream_t str, DBM_DATUM key, DBM_DATUM contents)
+print_entry (mu_stream_t str, struct mu_dbm_datum const *key,
+	     struct mu_dbm_datum const *contents)
 {
   if (compatibility_option)
     mu_stream_printf (str, "%.*s: %.*s\n",
-		      (int) MU_DATUM_SIZE (key),
-		      (char*) MU_DATUM_PTR (key),
-		      (int) MU_DATUM_SIZE (contents),
-		      (char*) MU_DATUM_PTR (contents));
+		      (int) key->mu_dsize,
+		      (char*) key->mu_dptr,
+		      (int) contents->mu_dsize,
+		      (char*) contents->mu_dptr);
   else
     mu_stream_printf (str, "%.*s %.*s\n",
-		      (int) MU_DATUM_SIZE (key),
-		      (char*) MU_DATUM_PTR (key),
-		      (int) MU_DATUM_SIZE (contents),
-		      (char*) MU_DATUM_PTR (contents));
+		      (int) key->mu_dsize,
+		      (char*) key->mu_dptr,
+		      (int) contents->mu_dsize,
+		      (char*) contents->mu_dptr);
 }
 
 int
 action_list (struct action_data *ap)
 {
   mu_stream_t str;
-  DBM_FILE db;
-  DBM_DATUM key;
-  DBM_DATUM contents;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, contents;
+  int rc;
   
-  check_user_perm (ACT_LIST, ap);
-  if (mu_dbm_open (ap->input_name, &db, MU_STREAM_READ, 0))
-    {
-      mu_error (_("cannot open file %s: %s"),
-		ap->input_name, mu_strerror (errno));
-      return 1;
-    }
+  db = open_db_file (ACT_LIST, ap, NULL);
   
   if (ap->output_name)
     {
@@ -331,32 +406,47 @@ action_list (struct action_data *ap)
     {
       memset (&key, 0, sizeof key);
       memset (&contents, 0, sizeof contents);
-      MU_DATUM_PTR (key) = ap->username;
-      MU_DATUM_SIZE (key) = strlen (ap->username);
-      if (mu_dbm_fetch (db, key, &contents))
+      key.mu_dptr = ap->username;
+      key.mu_dsize = strlen (ap->username);
+      rc = mu_dbm_fetch (db, &key, &contents);
+      if (rc == MU_ERR_NOENT)
 	{
 	  mu_error (_("no such user: %s"), ap->username);
 	}
+      else if (rc)
+	{
+	  mu_error (_("database fetch error: %s"), mu_dbm_strerror (db));
+	  exit (EX_UNAVAILABLE);
+	}
       else
 	{
-	  print_entry (str, key, contents);
+	  print_entry (str, &key, &contents);
 	  mu_dbm_datum_free (&contents);
 	}
     }
   else
     {
-      for (key = mu_dbm_firstkey (db); MU_DATUM_PTR(key);
-	   key = mu_dbm_nextkey (db, key))
+      memset (&key, 0, sizeof key);
+      for (rc = mu_dbm_firstkey (db, &key); rc == 0;
+	   rc = mu_dbm_nextkey (db, &key))
 	{
 	  memset (&contents, 0, sizeof contents);
-	  mu_dbm_fetch (db, key, &contents);
-	  print_entry (str, key, contents);
-	  mu_dbm_datum_free (&contents);
+	  rc = mu_dbm_fetch (db, &key, &contents);
+	  if (rc == 0)
+	    {
+	      print_entry (str, &key, &contents);
+	      mu_dbm_datum_free (&contents);
+	    }
+	  else
+	    {
+	      mu_error (_("database fetch error: %s"), mu_dbm_strerror (db));
+	      exit (EX_UNAVAILABLE);
+	    }
+	  mu_dbm_datum_free (&key);
 	}
     }
   
-  mu_dbm_close (db);
-  mu_stream_destroy (&str);
+  mu_dbm_destroy (&db);
   return 0;
 }
 
@@ -365,9 +455,8 @@ action_create (struct action_data *ap)
 {
   int rc;
   mu_stream_t in;
-  DBM_FILE db;
-  DBM_DATUM key;
-  DBM_DATUM contents;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, contents;
   char *buf = NULL;
   size_t size = 0, len;
   int line = 0;
@@ -399,12 +488,8 @@ action_create (struct action_data *ap)
   
   if (!ap->output_name)
     ap->output_name = APOP_PASSFILE;
-  if (mu_dbm_open (ap->output_name, &db, MU_STREAM_CREAT, permissions))
-    {
-      mu_error (_("cannot create database %s: %s"),
-		ap->output_name, mu_strerror (errno));
-      return 1;
-    }
+
+  db = open_db_file (ACT_CREATE, ap, NULL);
 
   line = 0;
   while ((rc = mu_stream_getline (in, &buf, &size, &len)) == 0
@@ -435,20 +520,25 @@ action_create (struct action_data *ap)
       
       memset (&key, 0, sizeof key);
       memset (&contents, 0, sizeof contents);
-      MU_DATUM_PTR (key) = str;
-      MU_DATUM_SIZE (key) = strlen (str);
-      MU_DATUM_PTR (contents) = pass;
-      MU_DATUM_SIZE (contents) = strlen (pass);
+      key.mu_dptr = str;
+      key.mu_dsize = strlen (str);
+      contents.mu_dptr = pass;
+      contents.mu_dsize = strlen (pass);
 
-      if (mu_dbm_insert (db, key, contents, 1))
-	mu_error (_("%s:%d: cannot store datum"), ap->input_name, line);
+      rc = mu_dbm_store (db, &key, &contents, 1);
+      if (rc)
+	mu_error (_("%s:%d: cannot store datum: %s"),
+		  ap->input_name, line,
+		  rc == MU_ERR_FAILURE ?
+		     mu_dbm_strerror (db) : mu_strerror (rc));
     }
   free (buf);
-  mu_dbm_close (db);
+  mu_dbm_destroy (&db);
   mu_stream_destroy (&in);
   return 0;
 }
 
+/*FIXME
 int
 open_io (int action, struct action_data *ap, DBM_FILE *db, int *not_owner)
 {
@@ -463,6 +553,7 @@ open_io (int action, struct action_data *ap, DBM_FILE *db, int *not_owner)
     }
   return 0;
 }
+*/
 
 void
 fill_pass (struct action_data *ap)
@@ -527,9 +618,8 @@ fill_pass (struct action_data *ap)
 int
 action_add (struct action_data *ap)
 {
-  DBM_FILE db;
-  DBM_DATUM key;
-  DBM_DATUM contents;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, contents;
   int rc;
   
   if (!ap->username)
@@ -538,31 +628,32 @@ action_add (struct action_data *ap)
       return 1;
     }
 
-  if (open_io (ACT_ADD, ap, &db, NULL))
-    return 1;
+  db = open_db_file (ACT_ADD, ap, NULL);
 
   fill_pass (ap);
   
   memset (&key, 0, sizeof key);
   memset (&contents, 0, sizeof contents);
-  MU_DATUM_PTR (key) = ap->username;
-  MU_DATUM_SIZE (key) = strlen (ap->username);
-  MU_DATUM_PTR (contents) = ap->passwd;
-  MU_DATUM_SIZE (contents) = strlen (ap->passwd);
+  key.mu_dptr = ap->username;
+  key.mu_dsize = strlen (ap->username);
+  contents.mu_dptr = ap->passwd;
+  contents.mu_dsize = strlen (ap->passwd);
 
-  rc = mu_dbm_insert (db, key, contents, 1);
+  rc = mu_dbm_store (db, &key, &contents, 1);
   if (rc)
-    mu_error (_("cannot store datum"));
+    mu_error (_("cannot store datum: %s"),
+	      rc == MU_ERR_FAILURE ?
+		     mu_dbm_strerror (db) : mu_strerror (rc));
 
-  mu_dbm_close (db);
+  mu_dbm_destroy (&db);
   return rc;
 }
 
 int
 action_delete (struct action_data *ap)
 {
-  DBM_FILE db;
-  DBM_DATUM key;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key;
   int rc;
   
   if (!ap->username)
@@ -571,56 +662,64 @@ action_delete (struct action_data *ap)
       return 1;
     }
 
-  if (open_io (ACT_DELETE, ap, &db, NULL))
-    return 1;
-  
-  MU_DATUM_PTR (key) = ap->username;
-  MU_DATUM_SIZE (key) = strlen (ap->username);
+  db = open_db_file (ACT_DELETE, ap, NULL);
+
+  memset (&key, 0, sizeof key);
+  key.mu_dptr = ap->username;
+  key.mu_dsize = strlen (ap->username);
 
-  rc = mu_dbm_delete (db, key);
+  rc = mu_dbm_delete (db, &key);
   if (rc)
-    mu_error (_("cannot remove record for %s"), ap->username);
+    mu_error (_("cannot remove record for %s: %s"),
+	      ap->username,
+	      rc == MU_ERR_FAILURE ?
+		     mu_dbm_strerror (db) : mu_strerror (rc));
 
-  mu_dbm_close (db);
+  mu_dbm_destroy (&db);
   return rc;
 }
 
 int
 action_chpass (struct action_data *ap)
 {
-  DBM_FILE db;
-  DBM_DATUM key;
-  DBM_DATUM contents;
+  mu_dbm_file_t db;
+  struct mu_dbm_datum key, contents;
   int rc;
-  int not_owner;
+  int my_file;
   
-  if (open_io (ACT_CHPASS, ap, &db, &not_owner))
-    return 1;
+  db = open_db_file (ACT_CHPASS, ap, &my_file);
 
   if (!ap->username)
     {
-      mu_error (_("missing username"));
-      return 1;
+      struct passwd *pw = getpwuid (getuid ());
+      ap->username = pw->pw_name;
+      printf ("Changing password for %s\n", ap->username);
     }
 
   memset (&key, 0, sizeof key);
   memset (&contents, 0, sizeof contents);
 
-  MU_DATUM_PTR (key) = ap->username;
-  MU_DATUM_SIZE (key) = strlen (ap->username);
-  if (mu_dbm_fetch (db, key, &contents))
+  key.mu_dptr = ap->username;
+  key.mu_dsize = strlen (ap->username);
+  rc = mu_dbm_fetch (db, &key, &contents);
+  if (rc == MU_ERR_NOENT)
     {
       mu_error (_("no such user: %s"), ap->username);
       return 1;
     }
-
-  if (not_owner)
+  else if (rc)
+    {
+      mu_error (_("database fetch error: %s"), mu_dbm_strerror (db));
+      exit (EX_UNAVAILABLE);
+    }
+      
+  if (!my_file)
     {
       char *oldpass, *p;
       
-      oldpass = xmalloc (MU_DATUM_SIZE (contents) + 1);
-      memcpy (oldpass, MU_DATUM_PTR (contents), MU_DATUM_SIZE (contents));
-      oldpass[MU_DATUM_SIZE (contents)] = 0;
+      oldpass = xmalloc (contents.mu_dsize + 1);
+      memcpy (oldpass, contents.mu_dptr, contents.mu_dsize);
+      oldpass[contents.mu_dsize] = 0;
       p = getpass (_("Old Password:"));
       if (!p)
 	return 1;
@@ -634,32 +733,49 @@ action_chpass (struct action_data *ap)
   fill_pass (ap);
   
   mu_dbm_datum_free (&contents);
-  MU_DATUM_PTR (contents) = ap->passwd;
-  MU_DATUM_SIZE (contents) = strlen (ap->passwd);
-  rc = mu_dbm_insert (db, key, contents, 1);
+  contents.mu_dptr = ap->passwd;
+  contents.mu_dsize = strlen (ap->passwd);
+  rc = mu_dbm_store (db, &key, &contents, 1);
   if (rc)
-    mu_error (_("cannot replace datum"));
+    mu_error (_("cannot replace datum: %s"),
+	      rc == MU_ERR_FAILURE ?
+		     mu_dbm_strerror (db) : mu_strerror (rc));
 
-  mu_dbm_close (db);
+  mu_dbm_destroy (&db);
   return rc;
 }
 
 void
 popauth_version (FILE *stream, struct argp_state *state)
 {
-#if defined(WITH_GDBM)
-# define FORMAT "GDBM"
-#elif defined(WITH_BDB)
-# define FORMAT "Berkeley DB"
-#elif defined(WITH_NDBM)
-# define FORMAT "NDBM"
-#elif defined(WITH_OLD_DBM)
-# define FORMAT "Old DBM"
-#elif defined(WITH_TOKYOCABINET)
-# define FORMAT "Tokyo Cabinet"
-#endif
+  mu_iterator_t itr;
+  int rc;
+
   mu_program_version_hook (stream, state);
-  fprintf (stream, _("Database format: %s\n"), FORMAT);
-  fprintf (stream, _("Database location: %s\n"), APOP_PASSFILE);
+  fprintf (stream, _("Database formats: "));
+
+  rc = mu_dbm_impl_iterator (&itr);
+  if (rc)
+    {
+      fprintf (stream, "%s\n", _("unknown"));
+      mu_error ("%s", mu_strerror (rc));
+    }
+  else
+    {
+      int i;
+      for (mu_iterator_first (itr), i = 0; !mu_iterator_is_done (itr);
+	   mu_iterator_next (itr), i++)
+	{
+	  struct mu_dbm_impl *impl;
+
+	  mu_iterator_current (itr, (void**)&impl);
+	  if (i)
+	    fprintf (stream, ", ");
+	  fprintf (stream, "%s", impl->_dbm_name);
+	}
+      fputc ('\n', stream);
+      mu_iterator_destroy (&itr);
+    }
+  fprintf (stream, _("Default database location: %s\n"), APOP_PASSFILE);
   exit (EX_OK);
 }


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Oct 28 08:14:20 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RJlKG-0007OY-8w
	for mharc-commit-mailutils@gnu.org; Fri, 28 Oct 2011 08:14:20 -0400
Received: from eggs.gnu.org ([140.186.70.92]:51491)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RJlK4-0007NS-BG
	for commit-mailutils@gnu.org; Fri, 28 Oct 2011 08:14:18 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RJlJx-00077W-5H
	for commit-mailutils@gnu.org; Fri, 28 Oct 2011 08:14:08 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:51846)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RJlJx-00077R-26
	for commit-mailutils@gnu.org; Fri, 28 Oct 2011 08:14:01 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RJlJw-0005sP-6Q
	for commit-mailutils@gnu.org; Fri, 28 Oct 2011 12:14:01 +0000
Date: Fri, 28 Oct 2011 12:14:00 +0000
Message-Id: <E1RJlJw-0005sP-6Q@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-412-gfb994e0
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 442711bcda49eeca667d15c509d200995379c832
X-Git-Newrev: fb994e0a85011d050eb6e3e166018a5625118c20
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 28 Oct 2011 12:14:18 -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=fb994e0a85011d050eb6e3e166018a5625118c20

The branch, master has been updated
       via  fb994e0a85011d050eb6e3e166018a5625118c20 (commit)
       via  02334735e86f1cfda6a2e07cfea9283e4fc88011 (commit)
       via  e9a329bfe70d903fb0a78007adaff6b565ddfc6b (commit)
      from  442711bcda49eeca667d15c509d200995379c832 (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 fb994e0a85011d050eb6e3e166018a5625118c20
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 28 14:06:38 2011 +0300

    pop3d: configurable APOP file and safety criteria.
    
    * include/mailutils/dbm.h (mu_dbm_init)
    (mu_dbm_get_hint): New prototypes.
    * include/mailutils/util.h (mu_stpcpy)
    (mu_file_safety_compose): New prototypes.
    * libmailutils/string/Makefile.am (libstring_la_SOURCES): Add stpcpy.c
    * libmailutils/string/stpcpy.c: New file.
    * libmu_cfg/tls.c (cb2_safety_checks): Use mu_file_safety_compose.
    * libmu_dbm/create.c (mu_dbm_create): Use mu_dbm_init.
    * libmu_dbm/dbm.c (_mu_dbm_init): Rename mu_dbm_init. All uses changed.
    Use URL composing interface to create hints.
    * maidag/maidag.c (mu_dbm_get_hint): New function.
    * pop3d/pop3d.c (cb2_forward_file_checks): Use mu_file_safety_compose.
    (apop_database_name, apop_database_safety)
    (apop_database_safety_set): New variables.
    (pop3d_cfg_param) <apop-database-file>
    <apop-database-safety>: New configuration statements.
    (main) [ENABLE_DBM]: Initialize dbm safety criteria.
    * pop3d/apop.c (pop3d_apopuser): Use configured database name and
    safety flags, if set.
    * pop3d/pop3d.h [ENABLE_DBM] (APOP_PASSFILE): Add ".db" suffix.
    (apop_database_name, apop_database_safety)
    (apop_database_safety_set): New variables.

commit 02334735e86f1cfda6a2e07cfea9283e4fc88011
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 28 13:21:25 2011 +0300

    New interface for composing URLs from parts.
    
    * include/mailutils/url.h (mu_url_sget_name)
    (mu_url_aget_name,mu_url_get_name)
    (mu_url_invalidate,mu_url_create_null)
    (mu_url_set_user,mu_url_set_path,mu_url_set_scheme)
    (mu_url_set_host,mu_url_set_port,mu_url_set_service)
    (mu_url_set_auth,mu_url_set_secret,mu_url_add_param)
    (mu_url_clear_param,mu_url_add_query,mu_url_clear_query): New
    prototypes.
    
    * libmailutils/tests/url-comp.at: New test case.
    * libmailutils/tests/url-comp.c: New test program.
    * libmailutils/tests/.gitignore: Update.
    * libmailutils/tests/Makefile.am: Add new files.
    * libmailutils/tests/testsuite.at: Add new tests.
    
    * libmailutils/url/Makefile.am: Add new files.
    * libmailutils/url/add-param.c: New file.
    * libmailutils/url/add-query.c: New file.
    * libmailutils/url/clr-param.c: New file.
    * libmailutils/url/clr-query.c: New file.
    * libmailutils/url/null.c: New file.
    * libmailutils/url/set-auth.c: New file.
    * libmailutils/url/set-host.c: New file.
    * libmailutils/url/set-path.c: New file.
    * libmailutils/url/set-port.c: New file.
    * libmailutils/url/set-scheme.c: New file.
    * libmailutils/url/set-secret.c: New file.
    * libmailutils/url/set-service.c: New file.
    * libmailutils/url/set-user.c: New file.
    * libmailutils/url/urlinv.c: New file.
    
    * libmailutils/url/create.c (mu_url_create_hint): Return EINVAL if
    purl is NULL.
    * libmailutils/url/scheme.c (mu_url_set_scheme): Remove. See set-scheme.c
    * libmailutils/url/urlstr.c (mu_url_sget_name)
    (mu_url_aget_name,mu_url_get_name): New functions.
    (mu_url_to_string): Rewrite using the above.
    
    * libmailutils/base/Makefile.am: Add fscompose.c
    * libmailutils/base/fscompose.c: New file.

commit e9a329bfe70d903fb0a78007adaff6b565ddfc6b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 27 13:30:12 2011 +0300

    Add testcases for file safety checking functions.
    
    * libmailutils/tests/fsaf.at: New testcase.
    * libmailutils/tests/fsaf.c: New file.
    * libmailutils/tests/.gitignore: Add fsaf
    * libmailutils/tests/Makefile.am: Likewise.
    * libmailutils/tests/testsuite.at: Include fsaf.at.

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

Summary of changes:
 include/mailutils/dbm.h                            |    6 +-
 include/mailutils/url.h                            |   22 +++-
 include/mailutils/util.h                           |    2 +
 libmailutils/base/Makefile.am                      |    1 +
 .../datumfree.c => libmailutils/base/fscompose.c   |   45 +++++--
 libmailutils/string/Makefile.am                    |    1 +
 libmailutils/{base/freeitem.c => string/stpcpy.c}  |   18 ++-
 libmailutils/tests/.gitignore                      |    2 +
 libmailutils/tests/Makefile.am                     |    4 +
 libmailutils/tests/fsaf.at                         |   82 +++++++++++
 .../tests/argcv.c => libmailutils/tests/fsaf.c     |   64 +++++----
 libmailutils/tests/testsuite.at                    |    2 +
 libmailutils/tests/url-comp.at                     |   72 +++++++++
 libmailutils/tests/url-comp.c                      |  147 +++++++++++++++++++
 libmailutils/url/Makefile.am                       |   14 ++
 libmailutils/url/{get-query.c => add-param.c}      |   64 +++++----
 libmailutils/url/{get-query.c => add-query.c}      |   64 +++++----
 libmailutils/url/{get-secret.c => clr-param.c}     |   24 ++--
 libmailutils/url/{get-secret.c => clr-query.c}     |   24 ++--
 libmailutils/url/create.c                          |    6 +-
 libmailutils/url/flag.c                            |    2 +-
 libmailutils/url/{flag.c => null.c}                |   24 ++--
 libmailutils/url/scheme.c                          |   13 --
 libmailutils/url/{dup.c => set-auth.c}             |   36 +++---
 libmailutils/url/{get-query.c => set-host.c}       |   65 +++++----
 libmailutils/url/{dup.c => set-path.c}             |   36 +++---
 libmailutils/url/{dup.c => set-port.c}             |   43 ++++---
 libmailutils/url/{scheme.c => set-scheme.c}        |   41 +++---
 libmailutils/url/{get-secret.c => set-secret.c}    |   27 +++--
 libmailutils/url/{get-query.c => set-service.c}    |   70 +++++----
 libmailutils/url/{dup.c => set-user.c}             |   36 +++---
 libmailutils/url/{urlstr.c => urlinv.c}            |   16 ++-
 libmailutils/url/urlstr.c                          |  151 +++++++++++++++++++-
 libmu_cfg/tls.c                                    |   59 ++------
 libmu_dbm/create.c                                 |    2 +-
 libmu_dbm/dbm.c                                    |   40 ++----
 maidag/maidag.c                                    |   39 +-----
 pop3d/apop.c                                       |   30 +++--
 pop3d/pop3d.c                                      |   51 +++++++
 pop3d/pop3d.h                                      |    5 +-
 40 files changed, 1007 insertions(+), 443 deletions(-)
 copy libmu_dbm/datumfree.c => libmailutils/base/fscompose.c (54%)
 copy libmailutils/{base/freeitem.c => string/stpcpy.c} (78%)
 create mode 100644 libmailutils/tests/fsaf.at
 copy libmu_compat/tests/argcv.c => libmailutils/tests/fsaf.c (50%)
 create mode 100644 libmailutils/tests/url-comp.at
 create mode 100644 libmailutils/tests/url-comp.c
 copy libmailutils/url/{get-query.c => add-param.c} (57%)
 copy libmailutils/url/{get-query.c => add-query.c} (57%)
 copy libmailutils/url/{get-secret.c => clr-param.c} (74%)
 copy libmailutils/url/{get-secret.c => clr-query.c} (74%)
 copy libmailutils/url/{flag.c => null.c} (80%)
 copy libmailutils/url/{dup.c => set-auth.c} (69%)
 copy libmailutils/url/{get-query.c => set-host.c} (59%)
 copy libmailutils/url/{dup.c => set-path.c} (69%)
 copy libmailutils/url/{dup.c => set-port.c} (63%)
 copy libmailutils/url/{scheme.c => set-scheme.c} (70%)
 copy libmailutils/url/{get-secret.c => set-secret.c} (72%)
 copy libmailutils/url/{get-query.c => set-service.c} (55%)
 copy libmailutils/url/{dup.c => set-user.c} (69%)
 copy libmailutils/url/{urlstr.c => urlinv.c} (79%)

diff --git a/include/mailutils/dbm.h b/include/mailutils/dbm.h
index 0d194f6..ab0d5c1 100644
--- a/include/mailutils/dbm.h
+++ b/include/mailutils/dbm.h
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 2011 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
@@ -50,6 +49,9 @@ struct mu_dbm_impl
 
 extern mu_url_t mu_dbm_hint;
 
+void mu_dbm_init (void);
+mu_url_t mu_dbm_get_hint (void);
+
 int mu_dbm_register (struct mu_dbm_impl *impl);
 int mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db);
 int mu_dbm_create (char *name, mu_dbm_file_t *db);
diff --git a/include/mailutils/url.h b/include/mailutils/url.h
index c33dadc..513b767 100644
--- a/include/mailutils/url.h
+++ b/include/mailutils/url.h
@@ -80,6 +80,10 @@ int mu_url_has_flag (mu_url_t, int);
   
 void mu_url_destroy   (mu_url_t *);
 
+int mu_url_sget_name (const mu_url_t, const char **);
+int mu_url_aget_name (const mu_url_t, char **);
+int mu_url_get_name (const mu_url_t, char *, size_t, size_t *);
+  
 int mu_url_sget_scheme  (const mu_url_t, const char **);
 int mu_url_aget_scheme  (const mu_url_t, char **);  
 int mu_url_get_scheme  (const mu_url_t, char *, size_t, size_t *);
@@ -120,8 +124,6 @@ int mu_url_aget_param (const mu_url_t url, const char *param, char **val);
 int mu_url_expand_path (mu_url_t url);
 const char *mu_url_to_string   (const mu_url_t);
 
-int mu_url_set_scheme (mu_url_t url, const char *scheme);
-
 int mu_url_is_scheme   (mu_url_t, const char *scheme);
 
 int mu_url_is_same_scheme (mu_url_t, mu_url_t);
@@ -133,6 +135,22 @@ int mu_url_is_same_port   (mu_url_t, mu_url_t);
 int mu_url_matches_ticket   (mu_url_t ticket, mu_url_t url, int *wcn);  
 
 int mu_url_decode (mu_url_t url);
+
+int mu_url_invalidate (mu_url_t url);
+  
+int mu_url_create_null (mu_url_t *purl);
+int mu_url_set_user (mu_url_t url, const char *user);
+int mu_url_set_path (mu_url_t url, const char *path);
+int mu_url_set_scheme (mu_url_t url, const char *scheme);
+int mu_url_set_host (mu_url_t url, const char *host);
+int mu_url_set_port (mu_url_t url, unsigned port);
+int mu_url_set_service (mu_url_t url, const char *str);
+int mu_url_set_auth (mu_url_t url, const char *auth);
+int mu_url_set_secret (mu_url_t url, mu_secret_t secret);
+int mu_url_add_param (mu_url_t url, size_t pc, const char **pv);
+int mu_url_clear_param (mu_url_t url);
+int mu_url_add_query (mu_url_t url, size_t pc, const char **pv);
+int mu_url_clear_query (mu_url_t url);  
   
 #ifdef __cplusplus
 }
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index fcc11ac..d0ffd63 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -36,6 +36,7 @@ extern "C" {
 unsigned long mu_hex2ul (char hex);
 size_t mu_hexstr2ul (unsigned long* ul, const char* hex, size_t len);
 size_t mu_cpystr (char *dst, const char *src, size_t size);
+char *mu_stpcpy (char *p, char *q);
 int mu_string_unfold (char *text, size_t *plen);
 int mu_true_answer_p (const char *p);
 int mu_unre_set_regex (const char *str, int caseflag, char **errp);
@@ -225,6 +226,7 @@ int mu_file_safety_check (const char *filename, int mode,
 			  mu_list_t idlist);
 int mu_file_safety_name_to_code (const char *name, int *pcode);
 int mu_file_safety_name_to_error (const char *name, int *pcode);  
+int mu_file_safety_compose (int *res, const char *name, int defval);
   
 #ifdef __cplusplus
 }
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index 96ea2f8..5f41b0c 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -31,6 +31,7 @@ libbase_la_SOURCES = \
  fgetpwent.c\
  filename.c\
  freeitem.c\
+ fscompose.c\
  getcwd.c\
  getmaxfd.c\
  getpass.c\
diff --git a/libmu_dbm/datumfree.c b/libmailutils/base/fscompose.c
similarity index 54%
copy from libmu_dbm/datumfree.c
copy to libmailutils/base/fscompose.c
index c11db26..7af13ac 100644
--- a/libmu_dbm/datumfree.c
+++ b/libmailutils/base/fscompose.c
@@ -18,19 +18,46 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <stdlib.h>
+#include <string.h>
 #include <mailutils/types.h>
-#include <mailutils/dbm.h>
+#include <mailutils/util.h>
+#include <mailutils/nls.h>
+#include <mailutils/error.h>
 #include <mailutils/errno.h>
-#include "mudbm.h"
 
-void
-mu_dbm_datum_free (struct mu_dbm_datum *datum)
+int
+mu_file_safety_compose (int *res, const char *name, int defval)
 {
-  if (datum && datum->mu_data &&
-      datum->mu_sys && datum->mu_sys->_dbm_datum_free)
+  int negate = 0;
+  int val;
+  
+  if (*name == '-')
     {
-      datum->mu_sys->_dbm_datum_free (datum);
-      datum->mu_data = NULL;
+      negate = 1;
+      name++;
     }
+  else if (*name == '+')
+    name++;
+
+  if (strcmp (name, "none") == 0)
+    {
+      *res = negate ? MU_FILE_SAFETY_ALL : MU_FILE_SAFETY_NONE;
+      return 0;
+    }
+  else if (strcmp (name, "all") == 0)
+    {
+      *res = negate ? MU_FILE_SAFETY_NONE : MU_FILE_SAFETY_ALL;
+      return 0;
+    }
+  else if (strcmp (name, "default") == 0)
+    val = defval;
+  else if (mu_file_safety_name_to_code (name, &val))
+    return MU_ERR_NOENT;
+
+  if (negate)
+    *res &= ~val;
+  else
+    *res |= val;
+  
+  return 0;
 }
diff --git a/libmailutils/string/Makefile.am b/libmailutils/string/Makefile.am
index 628787c..94db386 100644
--- a/libmailutils/string/Makefile.am
+++ b/libmailutils/string/Makefile.am
@@ -24,6 +24,7 @@ libstring_la_SOURCES = \
  cstrlower.c\
  cstrupper.c\
  hexstr.c\
+ stpcpy.c\
  strltrim.c\
  strskip.c\
  stripws.c\
diff --git a/libmailutils/base/freeitem.c b/libmailutils/string/stpcpy.c
similarity index 78%
copy from libmailutils/base/freeitem.c
copy to libmailutils/string/stpcpy.c
index 458fbef..dea4aad 100644
--- a/libmailutils/base/freeitem.c
+++ b/libmailutils/string/stpcpy.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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
@@ -15,14 +15,18 @@
    Public License along with this library.  If not, see 
    <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
+#if HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <stdlib.h>
 
-/* Default destroy_item function. */
-void
-mu_list_free_item (void *item)
+#include <string.h>
+#include <mailutils/util.h>
+
+char *
+mu_stpcpy (char *p, char *q)
 {
-  free (item);
+  if (q)
+    while ((*p = *q++))
+      p++;
+  return p;
 }
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index d01d4ad..0860f07 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -11,9 +11,11 @@ debugspec
 decode2047
 encode2047
 fltst
+fsaf
 listop
 mailcap
 prop
+url-comp
 url-parse
 wicket
 wsp
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 5c00873..66d83ca 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -46,10 +46,12 @@ noinst_PROGRAMS = \
  decode2047\
  encode2047\
  fltst\
+ fsaf\
  listop\
  mailcap\
  prop\
  tempfile\
+ url-comp\
  url-parse\
  wicket\
  wsp
@@ -70,6 +72,7 @@ TESTSUITE_AT = \
  decode2047.at\
  encode2047.at\
  fromflt.at\
+ fsaf.at\
  hdrflt.at\
  inline-comment.at\
  linecon.at\
@@ -78,6 +81,7 @@ TESTSUITE_AT = \
  prop.at\
  testsuite.at\
  url.at\
+ url-comp.at\
  wicket.at\
  wordsplit.at
 
diff --git a/libmailutils/tests/fsaf.at b/libmailutils/tests/fsaf.at
new file mode 100644
index 0000000..3d6b530
--- /dev/null
+++ b/libmailutils/tests/fsaf.at
@@ -0,0 +1,82 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2011 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_BANNER(File Safety)
+
+dnl ------------------------------------------------------------
+dnl FSAF(CRITERIA, CODE, [STDOUT = `'], [RUN-IF-FAIL],
+dnl      [RUN-IF-PASS], [NAME])
+dnl
+
+m4_pushdef([FSAFCODE],[
+AT_SETUP([m4_if([$6],,$1,$6)])
+AT_KEYWORDS([fsaf])
+AT_CHECK([
+$2
+fsaf $1 file
+],
+[0],
+[file: $3
+],
+[],
+[$4],
+[$5])
+AT_CLEANUP
+])
+
+m4_pushdef([FSAF],[
+FSAFCODE([$1],
+[> file
+m4_if([$2],,,[chmod $2 file])],[$3],[$4],[$5],[$6])
+])
+
+dnl ------------------------------------------------------------
+
+FSAF([], [], [Success], [], [], [default])
+
+FSAF([+awrfil], [o+w], [World writable file])
+FSAF([+gwrfil], [g+w], [Group writable file])
+
+FSAFCODE([+linkwrdir],
+[mkdir dir
+chmod g+w dir
+> data
+cd dir
+ln ../data file
+],
+[Linked file in a writable directory])
+
+FSAFCODE([+awrdir],
+[mkdir dir
+chmod o+w dir
+cd dir
+> file
+],
+[File in world writable directory])
+
+FSAFCODE([+gwrdir],
+[mkdir dir
+chmod g+w dir
+cd dir
+> file
+],
+[File in group writable directory])
+
+FSAF([+ardfil], [o+r], [World readable file])
+FSAF([+grdfil], [g+r], [Group readable file])
+
+m4_popdef([FSAFCODE])
+m4_popdef([FSAF])
diff --git a/libmu_compat/tests/argcv.c b/libmailutils/tests/fsaf.c
similarity index 50%
copy from libmu_compat/tests/argcv.c
copy to libmailutils/tests/fsaf.c
index 8817f94..d548744 100644
--- a/libmu_compat/tests/argcv.c
+++ b/libmailutils/tests/fsaf.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2005, 2007, 2009, 2010, 2011 Free Software Foundation,
-   Inc.
+   Copyright (C) 2011 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
@@ -17,44 +16,57 @@
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
-#endif 
+#endif
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <errno.h>
 #include <unistd.h>
-#define MU_ARCGV_DEPRECATED
-#include <mailutils/argcv.h>
+#include <mailutils/types.h>
+#include <mailutils/error.h>
 #include <mailutils/errno.h>
+#include <mailutils/util.h>
 
 int
 main (int argc, char **argv)
 {
-  char *delim = "";
-  char *comment = "#";
-  char buf[512];
+  int i;
+  int mode = MU_FILE_SAFETY_OWNER_MISMATCH, rc, m;
+  mu_list_t idlist;
+  uid_t uid;
+
+  if (argc == 1)
+    {
+      mu_error ("usage: %s [+-]mode... file...", argv[0]);
+      exit (1);
+    }
   
-  while (fgets (buf, sizeof buf, stdin))
+  rc = mu_list_create (&idlist);
+  if (rc)
     {
-      int status, c;
-      char **v;
-      char *s;
-
-      status = mu_argcv_get (buf, delim, comment, &c, &v);
-      if (status)
+      mu_error ("mu_list_create: %s", mu_strerror (rc));
+      exit (1);
+    }
+  uid = getuid ();
+  
+  for (i = 1; i < argc; i++)
+    {
+      if (argv[i][0] == '-' || argv[i][0] == '+')
 	{
-	  fprintf (stderr, "cannot parse: %s\n", mu_strerror (status));
-	  continue;
+	  rc = mu_file_safety_name_to_code (argv[i] + 1, &m);
+	  if (rc)
+	    {
+	      mu_error ("%s: %s", argv[i], mu_strerror (rc));
+	      exit (1);
+	    }
+	  if (argv[i][0] == '-')
+	    mode &= ~m;
+	  else
+	    mode |= m;
 	}
-      status = mu_argcv_string (c, v, &s);
-      if (status)
-	fprintf (stderr, "cannot create string: %s\n", mu_strerror (status));
       else
 	{
-	  printf ("%d: %s\n", c, s);
-	  free (s);
+	  rc = mu_file_safety_check (argv[i], mode, uid, idlist);
+	  printf ("%s: %s\n", argv[i], mu_strerror (rc));
 	}
-      mu_argcv_free (c, v);
-    } 
+    }
   exit (0);
 }
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 31b0821..e29846b 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -58,6 +58,7 @@ m4_include([list.at])
 m4_include([address.at])
 m4_include([wordsplit.at])
 m4_include([url.at])
+m4_include([url-comp.at])
 m4_include([mailcap.at])
 m4_include([wicket.at])
 m4_include([prop.at])
@@ -77,3 +78,4 @@ m4_include([hdrflt.at])
 m4_include([linecon.at])
 m4_include([debugspec.at])
 
+m4_include([fsaf.at])
\ No newline at end of file
diff --git a/libmailutils/tests/url-comp.at b/libmailutils/tests/url-comp.at
new file mode 100644
index 0000000..e776e4b
--- /dev/null
+++ b/libmailutils/tests/url-comp.at
@@ -0,0 +1,72 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2011 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_BANNER(URL Composition)
+
+dnl ------------------------------------------------------------
+             1   2        3                4
+dnl URLCOMP(KW, ARGS, [STDOUT = `'], [STDERR = `'])
+dnl
+
+m4_pushdef([URLCOMP],[
+AT_SETUP([$2 => $3])
+AT_KEYWORDS([url-comp url-comp-$1])
+AT_CHECK([url-comp $2],
+[m4_if([$4],,0,1)],
+[m4_if([$3],,,[$3
+])],
+m4_if([$4],,,[url-comp: $4
+]))
+AT_CLEANUP
+])
+
+URLCOMP(0, [], [], [URL missing required parts])
+URLCOMP(1, [path=foo], [foo])
+URLCOMP(2, [scheme=file], [file://])
+URLCOMP(3, [scheme=file path=foo], [file://foo])
+URLCOMP(4, [scheme=smtp host=localhost port=587], [smtp://localhost:587])
+URLCOMP(5,
+        [scheme=smtp host=localhost port=587 param=strip-domain param=domain=example.com],
+        [smtp://localhost:587;strip-domain;domain=example.com])
+URLCOMP(6, [scheme=imap user=gray host=localhost path=INBOX],
+        [imap://gray@localhost/INBOX])
+URLCOMP(7,
+        [scheme=imap user=gray pass=test host=localhost path=INBOX],
+	[imap://gray:***@localhost/INBOX])
+URLCOMP(8,	
+        [scheme=pop user=gray pass=test auth=+APOP host=localhost path=INBOX],
+	[pop://gray:***;AUTH=+APOP@localhost/INBOX])
+URLCOMP(9,
+        [scheme=prog path=/bin/mailman query=request query=list],
+        [prog:///bin/mailman?request&list])
+URLCOMP(10,
+        [scheme=prog path=/bin/mailman query=request query=list param=test],
+        [prog:///bin/mailman;test?request&list])
+URLCOMP(11,
+        [url=imap://gray@localhost/INBOX path=],
+	[imap://gray@localhost])
+URLCOMP(12,
+        [url=imap://gray@localhost/INBOX path= user=],
+	[imap://localhost])
+URLCOMP(13,
+        [url='prog:///bin/mailman;test?request&list' query= param=],
+	[prog:///bin/mailman])
+URLCOMP(14,
+        [url=smtp://gray@localhost/test host=],
+	[],
+	[URL missing required parts])
+	
+m4_popdef([URLCOMP])
\ No newline at end of file
diff --git a/libmailutils/tests/url-comp.c b/libmailutils/tests/url-comp.c
new file mode 100644
index 0000000..e1344ba
--- /dev/null
+++ b/libmailutils/tests/url-comp.c
@@ -0,0 +1,147 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011 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 <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/url.h>
+#include <mailutils/secret.h>
+#include <mailutils/kwd.h>
+
+static const char *
+strval (const char *str)
+{
+  return str[0] ? str : NULL;
+}
+
+void
+usage (FILE *str, int code)
+{
+  fprintf (str, "usage: %s [url=URL] [OPTIONS]\n", mu_program_name);
+  exit (code);
+}
+
+int
+main (int argc, char **argv)
+{
+  int i = 1, rc;
+  mu_url_t url;
+  const char *arg;
+  
+  mu_set_program_name (argv[0]);
+  
+  if (argc > 1)
+    {
+      if (strcmp (argv[1], "help") == 0 ||
+	  strcmp (argv[1], "--help") == 0 ||
+	  strcmp (argv[1], "-h") == 0)
+	usage (stdout, 0);
+
+      if (strncmp (argv[1], "url=", 4) == 0)
+	{
+	  MU_ASSERT (mu_url_create (&url, argv[1] + 4));
+	  i = 2;
+	}
+    }
+
+  if (!url)
+    {
+      MU_ASSERT (mu_url_create_null (&url));
+      i = 1;
+    }
+  
+  for (; i < argc; i++)
+    {
+      if (strncmp (argv[i], "scheme=", 7) == 0)
+	{
+	  MU_ASSERT (mu_url_set_scheme (url, strval (argv[i] + 7)));
+	}
+      else if (strncmp (argv[i], "user=", 5) == 0)
+	{
+	  MU_ASSERT (mu_url_set_user (url, strval (argv[i] + 5)));
+	}
+      else if (strncmp (argv[i], "path=", 5) == 0)
+	{
+	  MU_ASSERT (mu_url_set_path (url, strval (argv[i] + 5)));
+	}
+      else if (strncmp (argv[i], "host=", 5) == 0)
+	{
+	  MU_ASSERT (mu_url_set_host (url, strval (argv[i] + 5)));
+	}
+      else if (strncmp (argv[i], "port=", 5) == 0)
+	{
+	  MU_ASSERT (mu_url_set_port (url, atoi (argv[i] + 5)));
+	}
+      else if (strncmp (argv[i], "service=", 8) == 0)
+	{
+	  MU_ASSERT (mu_url_set_service (url, strval (argv[i] + 8)));
+	}
+      else if (strncmp (argv[i], "auth=", 5) == 0)
+	{
+	  MU_ASSERT (mu_url_set_auth (url, strval (argv[i] + 5)));
+	}
+      else if (strncmp (argv[i], "pass=", 5) == 0)
+	{
+	  mu_secret_t secret;
+
+	  arg = strval (argv[i] + 5);
+	  if (arg)
+	    {
+	      MU_ASSERT (mu_secret_create (&secret, arg, strlen (arg)));
+	    }
+	  else
+	    secret = NULL;
+	  MU_ASSERT (mu_url_set_secret (url, secret));
+	}
+      else if (strncmp (argv[i], "param=", 6) == 0)
+	{
+	  arg = strval (argv[i] + 6);
+	  if (arg)
+	    MU_ASSERT (mu_url_add_param (url, 1, (const char **)&arg));
+	  else
+	    MU_ASSERT (mu_url_clear_param (url));
+	}
+      else if (strncmp (argv[i], "query=", 6) == 0)
+	{
+	  arg = strval (argv[i] + 6);
+	  if (arg)
+	    MU_ASSERT (mu_url_add_query (url, 1, (const char **)&arg));
+	  else
+	    MU_ASSERT (mu_url_clear_query (url));
+	}
+      else
+	{
+	  mu_error ("unrecognized argument: %s", argv[i]);
+	  return 1;
+	}
+    }
+		       
+  rc = mu_url_sget_name (url, &arg);
+  if (rc)
+    {
+      mu_error ("%s", mu_strerror (rc));
+      return 1;
+    }
+  
+
+  printf ("%s\n", arg);
+  return 0;
+}
diff --git a/libmailutils/url/Makefile.am b/libmailutils/url/Makefile.am
index 6f4a9c0..937f823 100644
--- a/libmailutils/url/Makefile.am
+++ b/libmailutils/url/Makefile.am
@@ -19,6 +19,10 @@ noinst_LTLIBRARIES = liburl.la
 
 liburl_la_SOURCES = \
  accessor.h\
+ add-param.c\
+ clr-param.c\
+ add-query.c\
+ clr-query.c\
  copy.c\
  create.c\
  decode.c\
@@ -36,9 +40,19 @@ liburl_la_SOURCES = \
  get-secret.c\
  get-user.c\
  match.c\
+ null.c\
  port.c\
  scheme.c\
+ set-auth.c\
+ set-host.c\
+ set-path.c\
+ set-port.c\
+ set-scheme.c\
+ set-secret.c\
+ set-service.c\
+ set-user.c\
  uplevel.c\
+ urlinv.c\
  urlstr.c
 
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/url/get-query.c b/libmailutils/url/add-param.c
similarity index 57%
copy from libmailutils/url/get-query.c
copy to libmailutils/url/add-param.c
index 6d82d87..0bd0f43 100644
--- a/libmailutils/url/get-query.c
+++ b/libmailutils/url/add-param.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -28,45 +28,47 @@
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/argcv.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
+mu_url_add_param (mu_url_t url, size_t pc, const char **pv)
 {
-  if (url == NULL)
+  char **fv;
+  int i, j;
+    
+  if (!url)
     return EINVAL;
-  /* See FIXME below */
-  *qc = url->qargc;
-  *qv = url->qargv;
-  return 0;
-}
+  if (!pc || !pv)
+    return 0;
 
-int
-mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
-{
-  size_t qargc, i;
-  char **qargv;
-  char **qcopy;
-
-  int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
-  if (rc)
-    return rc;
-
-  qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
-  if (!qcopy)
-    return errno;
-  for (i = 0; i < qargc; i++)
+  fv = realloc (url->fvpairs,
+		sizeof (url->fvpairs[0]) * (url->fvcount + pc + 1));
+  if (!fv)
+    return ENOMEM;
+  url->fvpairs = fv;
+  for (i = url->fvcount, j = 0; j < pc; i++, j++)
     {
-      if (!(qcopy[i] = strdup (qargv[i])))
+      fv[i] = strdup (pv[j]);
+      if (!fv[i])
 	{
-	  mu_argcv_free (i, qcopy);
-	  return errno;
+	  /* Restore the status quo */
+	  for (; j; j--)
+	    free (fv[--i]);
+	  if (url->fvcount)
+	    fv[url->fvcount] = NULL;
+	  else
+	    {
+	      free (url->fvpairs);
+	      url->fvpairs = NULL;
+	      url->fvcount = 0;
+	    }
+	  return ENOMEM;
 	}
     }
-  qcopy[i] = NULL;
-  *qc = qargc;
-  *qv = qcopy;
+  fv[i] = NULL;
+  url->fvcount = i;
+  url->flags |= MU_URL_PARAM;
+  mu_url_invalidate (url);
   return 0;
 }
-
diff --git a/libmailutils/url/get-query.c b/libmailutils/url/add-query.c
similarity index 57%
copy from libmailutils/url/get-query.c
copy to libmailutils/url/add-query.c
index 6d82d87..8d810bb 100644
--- a/libmailutils/url/get-query.c
+++ b/libmailutils/url/add-query.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -28,45 +28,47 @@
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/argcv.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
+mu_url_add_query (mu_url_t url, size_t pc, const char **pv)
 {
-  if (url == NULL)
+  char **fv;
+  int i, j;
+    
+  if (!url)
     return EINVAL;
-  /* See FIXME below */
-  *qc = url->qargc;
-  *qv = url->qargv;
-  return 0;
-}
+  if (!pc || !pv)
+    return 0;
 
-int
-mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
-{
-  size_t qargc, i;
-  char **qargv;
-  char **qcopy;
-
-  int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
-  if (rc)
-    return rc;
-
-  qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
-  if (!qcopy)
-    return errno;
-  for (i = 0; i < qargc; i++)
+  fv = realloc (url->qargv,
+		sizeof (url->qargv[0]) * (url->qargc + pc + 1));
+  if (!fv)
+    return ENOMEM;
+  url->qargv = fv;
+  for (i = url->qargc, j = 0; j < pc; i++, j++)
     {
-      if (!(qcopy[i] = strdup (qargv[i])))
+      fv[i] = strdup (pv[j]);
+      if (!fv[i])
 	{
-	  mu_argcv_free (i, qcopy);
-	  return errno;
+	  /* Restore the status quo */
+	  for (; j; j--)
+	    free (fv[--i]);
+	  if (url->qargc)
+	    fv[url->qargc] = NULL;
+	  else
+	    {
+	      free (url->qargv);
+	      url->qargv = NULL;
+	      url->qargc = 0;
+	    }
+	  return ENOMEM;
 	}
     }
-  qcopy[i] = NULL;
-  *qc = qargc;
-  *qv = qcopy;
+  fv[i] = NULL;
+  url->qargc = i;
+  url->flags |= MU_URL_QUERY;
+  mu_url_invalidate (url);
   return 0;
 }
-
diff --git a/libmailutils/url/get-secret.c b/libmailutils/url/clr-param.c
similarity index 74%
copy from libmailutils/url/get-secret.c
copy to libmailutils/url/clr-param.c
index 7057315..0feb80f 100644
--- a/libmailutils/url/get-secret.c
+++ b/libmailutils/url/clr-param.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -28,17 +28,23 @@
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/secret.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
+mu_url_clear_param (mu_url_t url)
 {
-  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 i;
+  
+  if (!url)
+    return EINVAL;
+
+  for (i = 0; i < url->fvcount; i++)
+    free (url->fvpairs[i]);
+  free (url->fvpairs);
+  url->fvpairs = NULL;
+  url->fvcount = 0;
+  url->flags &= ~MU_URL_PARAM;
+  mu_url_invalidate (url);
   return 0;
 }
diff --git a/libmailutils/url/get-secret.c b/libmailutils/url/clr-query.c
similarity index 74%
copy from libmailutils/url/get-secret.c
copy to libmailutils/url/clr-query.c
index 7057315..186cb25 100644
--- a/libmailutils/url/get-secret.c
+++ b/libmailutils/url/clr-query.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -28,17 +28,23 @@
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/secret.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
+mu_url_clear_query (mu_url_t url)
 {
-  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 i;
+  
+  if (!url)
+    return EINVAL;
+
+  for (i = 0; i < url->qargc; i++)
+    free (url->qargv[i]);
+  free (url->qargv);
+  url->qargv = NULL;
+  url->qargc = 0;
+  url->flags &= ~MU_URL_QUERY;
+  mu_url_invalidate (url);
   return 0;
 }
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index 130b7a2..d6b01be 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -532,7 +532,11 @@ mu_url_create_hint (mu_url_t *purl, const char *str, int flags,
 {
   int rc;
   struct mu_url_ctx ctx;
-  mu_url_t url = calloc (1, sizeof (*url));
+  mu_url_t url;
+
+  if (!purl)
+    return EINVAL;
+  url = calloc (1, sizeof (*url));
   if (url == NULL)
     return ENOMEM;
   url->name = strdup (str);
diff --git a/libmailutils/url/flag.c b/libmailutils/url/flag.c
index 586c881..4387948 100644
--- a/libmailutils/url/flag.c
+++ b/libmailutils/url/flag.c
@@ -27,7 +27,7 @@ mu_url_get_flags (mu_url_t url, int *pf)
 {
   if (!url || !pf)
     return EINVAL;
-  *pf = url->flags;
+  *pf = url->flags; 
   return 0;
 }
 
diff --git a/libmailutils/url/flag.c b/libmailutils/url/null.c
similarity index 80%
copy from libmailutils/url/flag.c
copy to libmailutils/url/null.c
index 586c881..471f194 100644
--- a/libmailutils/url/flag.c
+++ b/libmailutils/url/null.c
@@ -18,23 +18,21 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-
+#include <stdlib.h>
 #include <errno.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_get_flags (mu_url_t url, int *pf)
+mu_url_create_null (mu_url_t *purl)
 {
-  if (!url || !pf)
-    return EINVAL;
-  *pf = url->flags;
-  return 0;
-}
+  mu_url_t url;
 
-int
-mu_url_has_flag (mu_url_t url, int flags)
-{
-  if (!url)
-    return 0;
-  return url->flags & flags;
+  if (!purl)
+    return EINVAL;  
+  url = calloc (1, sizeof (*url));
+  if (url == NULL)
+    return ENOMEM;
+  *purl = url;
+  return 0;
 }
diff --git a/libmailutils/url/scheme.c b/libmailutils/url/scheme.c
index fa9fbf1..ec42f70 100644
--- a/libmailutils/url/scheme.c
+++ b/libmailutils/url/scheme.c
@@ -31,19 +31,6 @@
 #include <mailutils/sys/url.h>
 
 int
-mu_url_set_scheme (mu_url_t url, const char *scheme)
-{
-  char *p;
-  if (!url || !scheme)
-    return EINVAL;
-  p = realloc (url->scheme, strlen (scheme) + 1);
-  if (!p)
-    return ENOMEM;
-  strcpy (url->scheme, scheme);
-  return 0;
-}
-
-int
 mu_url_is_scheme (mu_url_t url, const char *scheme)
 {
   if (url && scheme && url->scheme 
diff --git a/libmailutils/url/dup.c b/libmailutils/url/set-auth.c
similarity index 69%
copy from libmailutils/url/dup.c
copy to libmailutils/url/set-auth.c
index 5fb0288..b4e9e61 100644
--- a/libmailutils/url/dup.c
+++ b/libmailutils/url/set-auth.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -27,30 +27,32 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/util.h>
+#include <mailutils/errno.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
+mu_url_set_auth (mu_url_t url, const char *auth)
 {
-  int rc;
-  mu_url_t url = calloc (1, sizeof (*url));
-
+  char *copy;
+  
   if (!url)
-    return ENOMEM;
-  url->name = strdup (old_url->name);
-  if (!url->name)
+    return EINVAL;
+  if (auth)
     {
-      free (url);
-      return ENOMEM;
+      copy = strdup (auth);
+      if (!copy)
+	return ENOMEM;
+      url->flags |= MU_URL_AUTH;
     }
-  
-  rc = mu_url_copy_hints (url, old_url);
-  if (rc)
+  else
     {
-      mu_url_destroy (&url);
-      return rc;
+      url->flags &= ~MU_URL_AUTH;
+      copy = NULL;
     }
-  *new_url = url;
+  free (url->auth);
+  url->auth = copy;
+  url->_get_auth = NULL;
+  mu_url_invalidate (url);
   return 0;
 }
diff --git a/libmailutils/url/get-query.c b/libmailutils/url/set-host.c
similarity index 59%
copy from libmailutils/url/get-query.c
copy to libmailutils/url/set-host.c
index 6d82d87..6cb21f6 100644
--- a/libmailutils/url/get-query.c
+++ b/libmailutils/url/set-host.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -28,45 +28,46 @@
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/argcv.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
+mu_url_set_host (mu_url_t url, const char *host)
 {
-  if (url == NULL)
+  char *copy;
+  
+  if (!url)
     return EINVAL;
-  /* See FIXME below */
-  *qc = url->qargc;
-  *qv = url->qargv;
-  return 0;
-}
-
-int
-mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
-{
-  size_t qargc, i;
-  char **qargv;
-  char **qcopy;
-
-  int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
-  if (rc)
-    return rc;
-
-  qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
-  if (!qcopy)
-    return errno;
-  for (i = 0; i < qargc; i++)
+  if (host)
     {
-      if (!(qcopy[i] = strdup (qargv[i])))
+      size_t len;
+      int flag = MU_URL_HOST;
+      
+      len = strlen (host);
+      if (len == 0)
+	return EINVAL;
+      if (host[0] == '[' && host[len-1] == ']')
 	{
-	  mu_argcv_free (i, qcopy);
-	  return errno;
+	  flag |= MU_URL_IPV6;
+	  host++;
+	  len -= 2;
 	}
+      
+      copy = malloc (len + 1);
+      if (!copy)
+	return ENOMEM;
+      memcpy (copy, host, len);
+      copy[len] = 0;
+      url->flags |= flag;
     }
-  qcopy[i] = NULL;
-  *qc = qargc;
-  *qv = qcopy;
+  else
+    {
+      url->flags &= ~(MU_URL_HOST|MU_URL_IPV6);
+      copy = NULL;
+    }
+  url->_get_host = NULL;
+  free (url->host);
+  url->host = copy;
+  mu_url_invalidate (url);
   return 0;
 }
-
diff --git a/libmailutils/url/dup.c b/libmailutils/url/set-path.c
similarity index 69%
copy from libmailutils/url/dup.c
copy to libmailutils/url/set-path.c
index 5fb0288..686dfad 100644
--- a/libmailutils/url/dup.c
+++ b/libmailutils/url/set-path.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -27,30 +27,32 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/util.h>
+#include <mailutils/errno.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
+mu_url_set_path (mu_url_t url, const char *path)
 {
-  int rc;
-  mu_url_t url = calloc (1, sizeof (*url));
-
+  char *copy;
+  
   if (!url)
-    return ENOMEM;
-  url->name = strdup (old_url->name);
-  if (!url->name)
+    return EINVAL;
+  if (path)
     {
-      free (url);
-      return ENOMEM;
+      copy = strdup (path);
+      if (!copy)
+	return ENOMEM;
+      url->flags |= MU_URL_PATH;
     }
-  
-  rc = mu_url_copy_hints (url, old_url);
-  if (rc)
+  else
     {
-      mu_url_destroy (&url);
-      return rc;
+      url->flags &= ~MU_URL_PATH;
+      copy = NULL;
     }
-  *new_url = url;
+  free (url->path);
+  url->path = copy;
+  url->_get_path = NULL;
+  mu_url_invalidate (url);
   return 0;
 }
diff --git a/libmailutils/url/dup.c b/libmailutils/url/set-port.c
similarity index 63%
copy from libmailutils/url/dup.c
copy to libmailutils/url/set-port.c
index 5fb0288..6549b72 100644
--- a/libmailutils/url/dup.c
+++ b/libmailutils/url/set-port.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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,6 +20,7 @@
 #endif
 
 #include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #ifdef HAVE_STRINGS_H
@@ -27,30 +28,38 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/util.h>
+#include <mailutils/errno.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
+mu_url_set_port (mu_url_t url, unsigned port)
 {
-  int rc;
-  mu_url_t url = calloc (1, sizeof (*url));
-
+  char *copy;
+  
   if (!url)
-    return ENOMEM;
-  url->name = strdup (old_url->name);
-  if (!url->name)
+    return EINVAL;
+  if (port)
     {
-      free (url);
-      return ENOMEM;
+      char nbuf[128];
+      snprintf (nbuf, sizeof nbuf, "%u", port);
+      copy = strdup (nbuf);
+      if (!copy)
+	return ENOMEM;
+      url->flags |= MU_URL_PORT;
     }
-  
-  rc = mu_url_copy_hints (url, old_url);
-  if (rc)
+  else
     {
-      mu_url_destroy (&url);
-      return rc;
+      copy = NULL;
+      url->flags &= ~MU_URL_PORT;
     }
-  *new_url = url;
+  url->_get_port = NULL;
+  url->_get_portstr = NULL;
+  free (url->portstr);
+  url->port = port;
+  url->portstr = copy;
+  mu_url_invalidate (url);
   return 0;
 }
+
+  
diff --git a/libmailutils/url/scheme.c b/libmailutils/url/set-scheme.c
similarity index 70%
copy from libmailutils/url/scheme.c
copy to libmailutils/url/set-scheme.c
index fa9fbf1..2e8ed13 100644
--- a/libmailutils/url/scheme.c
+++ b/libmailutils/url/set-scheme.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -27,29 +27,32 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/cstr.h>
+#include <mailutils/errno.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
 mu_url_set_scheme (mu_url_t url, const char *scheme)
 {
-  char *p;
-  if (!url || !scheme)
+  char *copy;
+  
+  if (!url)
     return EINVAL;
-  p = realloc (url->scheme, strlen (scheme) + 1);
-  if (!p)
-    return ENOMEM;
-  strcpy (url->scheme, scheme);
+  if (scheme)
+    {
+      copy = strdup (scheme);
+      if (!copy)
+	return ENOMEM;
+      url->flags |= MU_URL_SCHEME;
+    }
+  else
+    {
+      url->flags &= ~MU_URL_SCHEME;
+      copy = NULL;
+    }
+  free (url->scheme);
+  url->scheme = copy;
+  url->_get_scheme = NULL;
+  mu_url_invalidate (url);
   return 0;
 }
-
-int
-mu_url_is_scheme (mu_url_t url, const char *scheme)
-{
-  if (url && scheme && url->scheme 
-      && mu_c_strcasecmp (url->scheme, scheme) == 0)
-    return 1;
-
-  return 0;
-}
-
diff --git a/libmailutils/url/get-secret.c b/libmailutils/url/set-secret.c
similarity index 72%
copy from libmailutils/url/get-secret.c
copy to libmailutils/url/set-secret.c
index 7057315..30af285 100644
--- a/libmailutils/url/get-secret.c
+++ b/libmailutils/url/set-secret.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -28,17 +28,26 @@
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/secret.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
+#include <mailutils/secret.h>
 
 int
-mu_url_get_secret (const mu_url_t url, mu_secret_t *psecret)
+mu_url_set_secret (mu_url_t url, mu_secret_t secret)
 {
-  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;
+  if (!url)
+    return EINVAL;
+  if (secret)
+    {
+      url->flags |= MU_URL_SECRET;
+    }
+  else
+    {
+      url->flags &= ~MU_URL_SECRET;
+    }
+  mu_secret_destroy (&url->secret);
+  url->secret = secret;
+  url->_get_secret = NULL;
+  mu_url_invalidate (url);
   return 0;
 }
diff --git a/libmailutils/url/get-query.c b/libmailutils/url/set-service.c
similarity index 55%
copy from libmailutils/url/get-query.c
copy to libmailutils/url/set-service.c
index 6d82d87..f570977 100644
--- a/libmailutils/url/get-query.c
+++ b/libmailutils/url/set-service.c
@@ -22,51 +22,59 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <netdb.h>
+#include <arpa/inet.h>
 #ifdef HAVE_STRINGS_H
 # include <strings.h>
 #endif
 
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
-#include <mailutils/argcv.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_sget_query (const mu_url_t url, size_t *qc, char ***qv)
+mu_url_set_service (mu_url_t url, const char *str)
 {
-  if (url == NULL)
+  unsigned port;
+  char *copy;
+  
+  if (!url)
     return EINVAL;
-  /* See FIXME below */
-  *qc = url->qargc;
-  *qv = url->qargv;
-  return 0;
-}
-
-int
-mu_url_aget_query (const mu_url_t url, size_t *qc, char ***qv)
-{
-  size_t qargc, i;
-  char **qargv;
-  char **qcopy;
-
-  int rc = mu_url_sget_fvpairs (url, &qargc, &qargv);
-  if (rc)
-    return rc;
-
-  qcopy = calloc (qargc + 1, sizeof (qcopy[0]));
-  if (!qcopy)
-    return errno;
-  for (i = 0; i < qargc; i++)
+  if (str)
     {
-      if (!(qcopy[i] = strdup (qargv[i])))
+      unsigned long n;
+      char *p;
+      
+      n = strtoul (str, &p, 10);
+      if (*p)
 	{
-	  mu_argcv_free (i, qcopy);
-	  return errno;
+	  /* FIXME: 1. This assumes MU_URL_PARSE_PORTSRV. */
+	  /* FIXME: 2. Another proto? */
+	  struct servent *sp = getservbyname (str, "tcp");
+	  if (!sp)
+	    return MU_ERR_TCP_NO_PORT; /*FIXME: Error code?*/
+	  port = ntohs (sp->s_port);
 	}
+      else if (n > USHRT_MAX)
+	return ERANGE;
+
+      copy = strdup (str);
+      if (!copy)
+	return ENOMEM;
+      url->flags |= MU_URL_PORT;
     }
-  qcopy[i] = NULL;
-  *qc = qargc;
-  *qv = qcopy;
+  else
+    {
+      copy = NULL;
+      port = 0;
+      url->flags &= ~MU_URL_PORT;
+    }
+  url->_get_port = NULL;
+  url->_get_portstr = NULL;
+  free (url->portstr);
+  url->port = port;
+  url->portstr = copy;
+  mu_url_invalidate (url);
   return 0;
 }
-
diff --git a/libmailutils/url/dup.c b/libmailutils/url/set-user.c
similarity index 69%
copy from libmailutils/url/dup.c
copy to libmailutils/url/set-user.c
index 5fb0288..8494f43 100644
--- a/libmailutils/url/dup.c
+++ b/libmailutils/url/set-user.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 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
@@ -27,30 +27,32 @@
 #endif
 
 #include <mailutils/types.h>
-#include <mailutils/util.h>
+#include <mailutils/errno.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/url.h>
 
 int
-mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
+mu_url_set_user (mu_url_t url, const char *user)
 {
-  int rc;
-  mu_url_t url = calloc (1, sizeof (*url));
-
+  char *copy;
+  
   if (!url)
-    return ENOMEM;
-  url->name = strdup (old_url->name);
-  if (!url->name)
+    return EINVAL;
+  if (user)
     {
-      free (url);
-      return ENOMEM;
+      copy = strdup (user);
+      if (!copy)
+	return ENOMEM;
+      url->flags |= MU_URL_USER;
     }
-  
-  rc = mu_url_copy_hints (url, old_url);
-  if (rc)
+  else
     {
-      mu_url_destroy (&url);
-      return rc;
+      url->flags &= ~MU_URL_USER;
+      copy = NULL;
     }
-  *new_url = url;
+  free (url->user);
+  url->user = copy;
+  url->_get_user = NULL;
+  mu_url_invalidate (url);
   return 0;
 }
diff --git a/libmailutils/url/urlstr.c b/libmailutils/url/urlinv.c
similarity index 79%
copy from libmailutils/url/urlstr.c
copy to libmailutils/url/urlinv.c
index f2faa81..c4f8113 100644
--- a/libmailutils/url/urlstr.c
+++ b/libmailutils/url/urlinv.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011 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,13 +19,15 @@
 # include <config.h>
 #endif
 #include <stdlib.h>
-#include <mailutils/types.h>
+#include <errno.h>
 #include <mailutils/sys/url.h>
 
-const char *
-mu_url_to_string (const mu_url_t url)
+int
+mu_url_invalidate (mu_url_t url)
 {
-  if (url == NULL || url->name == NULL)
-    return "";
-  return url->name;
+  if (!url)
+    return EINVAL;
+  free (url->name);
+  url->name = NULL;
+  return 0;
 }
diff --git a/libmailutils/url/urlstr.c b/libmailutils/url/urlstr.c
index f2faa81..48a7805 100644
--- a/libmailutils/url/urlstr.c
+++ b/libmailutils/url/urlstr.c
@@ -19,13 +19,160 @@
 # include <config.h>
 #endif
 #include <stdlib.h>
+#include <string.h>
 #include <mailutils/types.h>
 #include <mailutils/sys/url.h>
+#include <mailutils/errno.h>
+#include <mailutils/util.h>
+#include <mailutils/opool.h>
+
+#define AUTH_PFX ";AUTH="
+
+static int
+url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
+{
+  if (url->flags & MU_URL_SCHEME)
+    {
+      int i;
+      
+      mu_opool_append (pool, url->scheme, strlen (url->scheme));
+      mu_opool_append (pool, "://", 3);
+
+      if (url->flags & MU_URL_USER)
+	mu_opool_append (pool, url->user, strlen (url->user));
+      if (url->flags & MU_URL_SECRET)
+	mu_opool_append (pool, ":***", 4); /* FIXME: How about MU_URL_PARSE_HIDEPASS? */
+      if (url->flags & MU_URL_AUTH)
+	{
+	  mu_opool_append (pool, AUTH_PFX, sizeof AUTH_PFX - 1);
+	  mu_opool_append (pool, url->auth, strlen (url->auth));
+	}
+      if (url->flags & MU_URL_HOST)
+	{
+	  if (url->flags & (MU_URL_USER|MU_URL_SECRET|MU_URL_AUTH))
+	    mu_opool_append_char (pool, '@');
+	  mu_opool_append (pool, url->host, strlen (url->host));
+	  if (url->flags & MU_URL_PORT)
+	    {
+	      mu_opool_append_char (pool, ':');
+	      mu_opool_append (pool, url->portstr, strlen (url->portstr));
+	    }
+	}
+      else if (url->flags & (MU_URL_USER|MU_URL_SECRET|MU_URL_AUTH))
+	return MU_ERR_URL_MISS_PARTS;
+      
+      if (url->flags & MU_URL_PATH)
+	{
+	  if (url->flags & MU_URL_HOST)
+	    mu_opool_append_char (pool, '/');
+	  mu_opool_append (pool, url->path, strlen (url->path));
+	}
+      
+      if (url->flags & MU_URL_PARAM)
+	{
+	  for (i = 0; i < url->fvcount; i++)
+	    {
+	      mu_opool_append_char (pool, ';');
+	      mu_opool_append (pool, url->fvpairs[i],
+			       strlen (url->fvpairs[i]));
+	    }
+	}
+      if (url->flags & MU_URL_QUERY)
+	{
+	  mu_opool_append_char (pool, '?');
+	  mu_opool_append (pool, url->qargv[0],
+			   strlen (url->qargv[0]));
+	  for (i = 1; i < url->qargc; i++)
+	    {
+	      mu_opool_append_char (pool, '&');
+	      mu_opool_append (pool, url->qargv[i],
+			       strlen (url->qargv[i]));
+	    }
+	}
+      return 0;
+    }
+  else if (url->flags == MU_URL_PATH)
+    {
+      mu_opool_append (pool, url->path, strlen (url->path));
+      return 0;
+    }
+  return MU_ERR_URL_MISS_PARTS;
+}
+
+int
+mu_url_sget_name (const mu_url_t url, const char **retptr)
+{
+  if (!url)
+    return EINVAL;
+  if (!url->name)
+    {
+      mu_opool_t pool;
+      int rc;
+      char *ptr, *newname;
+      size_t size;
+      
+      rc = mu_opool_create (&pool, 0);
+      if (rc)
+	return rc;
+      rc = url_reconstruct_to_pool (url, pool);
+      if (rc)
+	{
+	  mu_opool_destroy (&pool);
+	  return rc;
+	}
+      ptr = mu_opool_finish (pool, &size);	  
+
+      newname = realloc (url->name, size + 1);
+      if (!newname)
+	{
+	  mu_opool_destroy (&pool);
+	  return ENOMEM;
+	}
+      memcpy (newname, ptr, size);
+      newname[size] = 0;
+      url->name = newname;
+      mu_opool_destroy (&pool);
+    }
+  if (retptr)
+    *retptr = url->name;
+  return 0;
+}
+
+int
+mu_url_aget_name (const mu_url_t url, char **ret)
+{
+  char *s;
+  const char *ptr;
+  int rc = mu_url_sget_name (url, &ptr);
+  if (rc)
+    return rc;
+  s = strdup (ptr);
+  if (!s)
+    return errno;
+  *ret = s;
+  return 0;
+}
+
+int
+mu_url_get_name (const mu_url_t url, char *buf, size_t size, size_t *n)
+{
+  size_t i;
+  const char *ptr;
+  int rc = mu_url_sget_name (url, &ptr);
+  if (rc)
+    return rc;
+  i = mu_cpystr (buf, ptr, size);
+  if (n)
+    *n = i;
+  return 0;
+}
 
 const char *
 mu_url_to_string (const mu_url_t url)
 {
-  if (url == NULL || url->name == NULL)
+  const char *ptr;
+  
+  if (mu_url_sget_name (url, &ptr))
     return "";
-  return url->name;
+  return ptr;
 }
diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
index 37afc10..c40586b 100644
--- a/libmu_cfg/tls.c
+++ b/libmu_cfg/tls.c
@@ -47,58 +47,25 @@ static struct mu_tls_module_config tls_settings = {
     SSL_CA_FILE_CHECKS
 };
 
-
 static int
 cb2_safety_checks (const char *name, void *data)
 {
-  int negate = 0;
-  int val;
-  int *res = data;
+  int defval;
   
-  if (*name == '-')
-    {
-      negate = 1;
-      name++;
-    }
-  else if (*name == '+')
-    name++;
-
-  if (strcmp (name, "none") == 0)
-    {
-      *res = negate ? MU_FILE_SAFETY_ALL : MU_FILE_SAFETY_NONE;
-      return 0;
-    }
-  else if (strcmp (name, "all") == 0)
-    {
-      *res = negate ? MU_FILE_SAFETY_NONE : MU_FILE_SAFETY_ALL;
-      return 0;
-    }
-  else if (strcmp (name, "default") == 0)
-    {
-      if (data == &tls_settings.ssl_key)
-	val = SSL_KEY_FILE_CHECKS;
-      else if (data == &tls_settings.ssl_cert)
-	val = SSL_CERT_FILE_CHECKS;
-      else if (data == &tls_settings.ssl_cafile)
-	val = SSL_CA_FILE_CHECKS;
-      else
-	{
-	  mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
-		    __FILE__, __LINE__);
-	  val = MU_FILE_SAFETY_ALL;
-	}
-    }
-  else if (mu_file_safety_name_to_code (name, &val))
+  if (data == &tls_settings.ssl_key)
+    defval = SSL_KEY_FILE_CHECKS;
+  else if (data == &tls_settings.ssl_cert)
+    defval = SSL_CERT_FILE_CHECKS;
+  else if (data == &tls_settings.ssl_cafile)
+    defval = SSL_CA_FILE_CHECKS;
+  else
     {
-      mu_error (_("unknown keyword: %s"), name);
-      return 0;
+      mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
+		__FILE__, __LINE__);
+      defval = MU_FILE_SAFETY_ALL;
     }
-
-  if (negate)
-    *res &= ~val;
-  else
-    *res |= val;
-  
+  if (mu_file_safety_compose (data, name, defval))
+    mu_error (_("unknown keyword: %s"), name);
   return 0;
 }
 
diff --git a/libmu_dbm/create.c b/libmu_dbm/create.c
index c1915a7..dec1801 100644
--- a/libmu_dbm/create.c
+++ b/libmu_dbm/create.c
@@ -35,7 +35,7 @@ mu_dbm_create (char *name, mu_dbm_file_t *db)
   int rc;
   mu_url_t url;
 
-  _mu_dbm_init ();
+  mu_dbm_init ();
   rc = mu_url_create_hint (&url, name, 0, mu_dbm_hint);
   if (rc)
     return rc;
diff --git a/libmu_dbm/dbm.c b/libmu_dbm/dbm.c
index e09cbbc..794affb 100644
--- a/libmu_dbm/dbm.c
+++ b/libmu_dbm/dbm.c
@@ -54,7 +54,7 @@ _implist_cmp (const void *a, const void *b)
 }
 
 void
-_mu_dbm_init ()
+mu_dbm_init ()
 {
   int rc;
 
@@ -86,42 +86,32 @@ _mu_dbm_init ()
   if (!mu_dbm_hint)
     {
       struct mu_dbm_impl *impl;
-      char *urlbuf;
-      
-      rc = mu_list_get (implist, 0, (void**) &impl);
-      if (rc)
+
+      if ((rc = mu_list_get (implist, 0, (void**) &impl)) ||
+	  (rc = mu_url_create_null (&mu_dbm_hint)) ||
+	  (rc = mu_url_set_scheme (mu_dbm_hint, impl->_dbm_name)))
 	{
 	  mu_error (_("cannot initialize DBM hint: %s"),
 		    mu_strerror (rc));
 	  abort ();
 	}
-      urlbuf = malloc (strlen (impl->_dbm_name) + 4);
-      if (urlbuf)
-	{
-	  strcpy (urlbuf, impl->_dbm_name);
-	  strcat (urlbuf, "://");
-	  rc = mu_url_create (&mu_dbm_hint, urlbuf);
-	  free (urlbuf);
-	}
-      else
-	rc = ENOMEM;
-	  
-      if (rc)
-	{
-	  mu_error (_("cannot initialize DBM hint: %s"),
-		      mu_strerror (rc));
-	  abort ();
-	}
     }
 }
 
+mu_url_t
+mu_dbm_get_hint ()
+{
+  mu_dbm_init ();
+  return mu_dbm_hint;
+}
+
 int
 mu_dbm_register (struct mu_dbm_impl *impl)
 {
   int rc;
   struct mu_dbm_impl *ptr;
 
-  _mu_dbm_init ();
+  mu_dbm_init ();
   ptr = calloc (1, sizeof (*ptr));
   if (!ptr)
     return ENOMEM;
@@ -151,7 +141,7 @@ mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db)
   int safety_flags = 0;
   uid_t owner_uid = getuid ();
 
-  _mu_dbm_init ();
+  mu_dbm_init ();
   
   mu_url_get_flags (url, &flags);
   if ((flags & (MU_URL_HOST | MU_URL_PATH)) == (MU_URL_HOST | MU_URL_PATH))
@@ -260,6 +250,6 @@ mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db)
 int
 mu_dbm_impl_iterator (mu_iterator_t *itr)
 {
-  _mu_dbm_init ();
+  mu_dbm_init ();
   return mu_list_get_iterator (implist, itr);
 }
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 9faa36d..eee6d83 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -336,47 +336,16 @@ cb_group (void *data, mu_config_value_t *arg)
 static int
 cb2_forward_file_checks (const char *name, void *data)
 {
-  int val;
-  int negate = 0;
-  
-  if (*name == '-')
-    {
-      negate = 1;
-      name++;
-    }
-  else if (*name == '+')
-    name++;
-
-  if (strcmp (name, "none") == 0)
-    {
-      forward_file_checks = negate ? MU_FILE_SAFETY_ALL : MU_FILE_SAFETY_NONE;
-      return 0;
-    }
-  else if (strcmp (name, "all") == 0)
-    {
-      forward_file_checks = negate ? MU_FILE_SAFETY_NONE : MU_FILE_SAFETY_ALL;
-      return 0;
-    }
-  else if (strcmp (name, "default") == 0)
-    forward_file_checks = FORWARD_FILE_PERM_CHECK;
-  else if (mu_file_safety_name_to_code (name, &val))
-    {
-      mu_error (_("unknown keyword: %s"), name);
-      return 0;
-    }
-
-  if (negate)
-    forward_file_checks &= ~val;
-  else
-    forward_file_checks |= val;
-
+  if (mu_file_safety_compose (data, name, FORWARD_FILE_PERM_CHECK))
+    mu_error (_("unknown keyword: %s"), name);
   return 0;
 }
 
 static int
 cb_forward_file_checks (void *data, mu_config_value_t *arg)
 {
-  return mu_cfg_string_value_cb (arg, cb2_forward_file_checks, data);
+  return mu_cfg_string_value_cb (arg, cb2_forward_file_checks,
+				 &forward_file_checks);
 }
 
 static int
diff --git a/pop3d/apop.c b/pop3d/apop.c
index 7a2697f..ac9fbd7 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -42,27 +42,30 @@ char *
 pop3d_apopuser (const char *user)
 {
   char *password = NULL;
+  int rc;
   
 #ifdef ENABLE_DBM
   {
     size_t len;
     mu_dbm_file_t db;
     struct mu_dbm_datum key, data;
-    int rc;
 
-    rc = mu_dbm_create (APOP_PASSFILE, &db);
+    rc = mu_dbm_create (apop_database_name, &db);
     if (rc)
       {
 	mu_diag_output (MU_DIAG_ERROR, _("unable to create APOP db"));
 	return NULL;
       }
 
+    if (apop_database_safety_set)
+      mu_dbm_safety_set_flags (db, apop_database_safety);
+    
     rc = mu_dbm_safety_check (db);
     if (rc)
       {
 	mu_diag_output (MU_DIAG_ERROR,
 			_("APOP file %s fails safety check: %s"),
-			APOP_PASSFILE, mu_strerror (rc));
+			apop_database_name, mu_strerror (rc));
 	mu_dbm_destroy (&db);
 	return NULL;
       }
@@ -115,20 +118,21 @@ pop3d_apopuser (const char *user)
     size_t ulen;
     FILE *apop_file;
 
-    /* FIXME */    
-/*     if (mu_check_perm (APOP_PASSFILE, 0600)) */
-/*       { */
-/* 	mu_diag_output (MU_DIAG_INFO, */
-/* 			_("bad permissions on APOP password file")); */
-/* 	return NULL; */
-/*     } */
-
-    apop_file = fopen (APOP_PASSFILE, "r");
+    rc = mu_file_safety_check (apop_database_name, apop_database_safety,
+			       apop_database_uid, NULL);
+    if (rc)
+      {
+	mu_diag_output (MU_DIAG_ERROR,
+			_("APOP file %s fails safety check: %s"),
+			apop_database_name, mu_strerror (rc));
+	return NULL;
+      }
+    apop_file = fopen (apop_database_name, "r");
     if (apop_file == NULL)
       {
 	mu_diag_output (MU_DIAG_INFO,
 			_("unable to open APOP password file %s: %s"),
-			APOP_PASSFILE, mu_strerror (errno));
+			apop_database_name, mu_strerror (errno));
 	return NULL;
       }
 
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 5652b9d..4a15b38 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -31,6 +31,9 @@ int pop3d_transcript;
 int debug_mode;
 int tls_required;
 int pop3d_xlines;
+char *apop_database_name = APOP_PASSFILE;
+int apop_database_safety;
+int apop_database_safety_set;
 
 #ifdef WITH_TLS
 int tls_available;
@@ -77,6 +80,22 @@ cb_bulletin_source (void *data, mu_config_value_t *val)
   return 0;
 }
 
+static int
+cb2_file_safety_checks (const char *name, void *data)
+{
+  if (mu_file_safety_compose (data, name, MU_FILE_SAFETY_ALL))
+    mu_error (_("unknown keyword: %s"), name);
+  return 0;
+}
+
+static int
+cb_apop_safety_checks (void *data, mu_config_value_t *arg)
+{
+  apop_database_safety_set = 1;
+  return mu_cfg_string_value_cb (arg, cb2_file_safety_checks,
+				 &apop_database_safety);
+}
+
 #ifdef ENABLE_DBM
 static int
 cb_bulletin_db (void *data, mu_config_value_t *val)
@@ -98,6 +117,24 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
     N_("Delete expired messages upon closing the mailbox.") },
   { "scan-lines", mu_cfg_bool, &pop3d_xlines, 0, NULL,
     N_("Output the number of lines in the message in its scan listing.") },
+  { "apop-database-file", mu_cfg_string, &apop_database_name, 0, NULL,
+    N_("set APOP database file name or URL") },
+  { "apop-database-safety", mu_cfg_callback, NULL, 0, cb_apop_safety_checks,
+    N_("Configure safety checks for APOP database files.  Argument is a list or "
+       "sequence of check names optionally prefixed with '+' to enable or "
+       "'-' to disable the corresponding check.  Valid check names are:\n"
+       "\n"
+       "  none          disable all checks\n"
+       "  all           enable all checks\n"
+       "  gwrfil        forbid group writable files\n"
+       "  awrfil        forbid world writable files\n"
+       "  grdfil        forbid group readable files\n"
+       "  ardfil        forbid world writable files\n"
+       "  linkwrdir     forbid symbolic links in group or world writable directories\n"
+       "  gwrdir        forbid files in group writable directories\n"
+       "  awrdir        forbid files in world writable directories\n"),
+    N_("arg: list") },  
+    
 #ifdef WITH_TLS
   { "tls-required", mu_cfg_bool, &tls_required, 0, NULL,
      N_("Always require STLS before entering authentication phase.") },
@@ -303,6 +340,16 @@ pop3d_alloc_die ()
   pop3d_abquit (ERR_NO_MEM);
 }
 
+#ifdef ENABLE_DBM
+static void
+set_dbm_safety ()
+{
+  mu_url_t hints = mu_dbm_get_hint ();
+  const char *param[] = { "+all" };
+  mu_url_add_param (hints, 1, param);
+}
+#endif
+
 int
 main (int argc, char **argv)
 {
@@ -341,6 +388,10 @@ main (int argc, char **argv)
 
   mu_log_syslog = 1;
   manlock_mandatory_locking = 1;
+
+#ifdef ENABLE_DBM
+  set_dbm_safety ();
+#endif
   
   if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, 
 		   argc, argv, 0, NULL, server))
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index 833eb7f..0696c51 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -36,7 +36,7 @@
 #define APOP_PASSFILE_NAME "apop"
 
 #ifdef ENABLE_DBM
-# define APOP_PASSFILE SYSCONFDIR "/" APOP_PASSFILE_NAME
+# define APOP_PASSFILE SYSCONFDIR "/" APOP_PASSFILE_NAME ".db"
 # define ENABLE_LOGIN_DELAY
 #else
 # define APOP_PASSFILE SYSCONFDIR "/" APOP_PASSFILE_NAME ".passwd"
@@ -197,6 +197,9 @@ extern unsigned int idle_timeout;
 extern int pop3d_transcript;
 extern size_t pop3d_output_bufsize;
 extern int pop3d_xlines;
+extern char *apop_database_name;
+extern int apop_database_safety;
+extern int apop_database_safety_set;
 
 extern pop3d_command_handler_t pop3d_find_command (const char *name);
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 29 11:55:54 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RKBGE-0003FB-6y
	for mharc-commit-mailutils@gnu.org; Sat, 29 Oct 2011 11:55:54 -0400
Received: from eggs.gnu.org ([140.186.70.92]:53753)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKBG8-0003Ec-W2
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 11:55:51 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKBG5-000508-V0
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 11:55:48 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:38481)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKBG5-000502-Nq
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 11:55:45 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKBG4-00043W-MQ
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 15:55:45 +0000
Date: Sat, 29 Oct 2011 15:55:45 +0000
Message-Id: <E1RKBG4-00043W-MQ@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-413-g5f796a9
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: fb994e0a85011d050eb6e3e166018a5625118c20
X-Git-Newrev: 5f796a9c31d4ab9c281af3a072ae4d150fd2a1fb
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 29 Oct 2011 15:55:51 -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=5f796a9c31d4ab9c281af3a072ae4d150fd2a1fb

The branch, master has been updated
       via  5f796a9c31d4ab9c281af3a072ae4d150fd2a1fb (commit)
      from  fb994e0a85011d050eb6e3e166018a5625118c20 (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 5f796a9c31d4ab9c281af3a072ae4d150fd2a1fb
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 28 23:18:33 2011 +0300

    Reorganize error codes.
    
    * libmailutils/diag/errors (MU_ERR_TCP_NO_HOST)
    (MU_ERR_TCP_NO_PORT): Change wording.
    (MU_ERR_UNSAFE_PERMS): Remove error code.
    (MU_ERR_NO_HANDLER): Remove. All uses replaced by ENOSYS.
    (MU_ERR_OUT_NULL): Remove. MU_ERR_OUT_PTR_NULL is used instead.
    (MU_ERR_MBX_NULL): Remove. Use EINVAL instead.
    (MU_ERR_BAD_822_FORMAT): Rename to MU_ERR_INVALID_EMAIL. Change wording.
    (MU_ERR_REPLY): Change wording.
    
    * libmailutils/url/create.c: Remove misguiding comments
    * libmailutils/url/set-service.c: Likewise.
    
    * libmailutils/mailbox/mailbox.c (mu_mailbox_open): Return EACCES
    if trying to update quick-access mailboxes.
    (mu_mailbox_get_stream): Mark for deletion.
    * libmailutils/stream/fltstream.c (filter_read)
    (filter_write_internal): Return MU_ERR_BUFSPACE if requested more
    space than available in I/O buffers.
    * libproto/mbox/mbox.c (mbox_expunge_unlocked): Send MU_EVT_MAILBOX_CORRUPT
    event if the mailbox shrunk.
    * libproto/mbox/mboxscan.c (mbox_scan_internal): Return MU_ERR_NOENT if
    unable to locate message in quick-access mode.

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

Summary of changes:
 libmailutils/address/parse822.c      |    2 +-
 libmailutils/base/amd.c              |    8 ++---
 libmailutils/diag/errors             |   39 +++++++++++---------
 libmailutils/mailbox/mailbox.c       |   65 +++++++++++++++++----------------
 libmailutils/mailer/mailer.c         |    4 +-
 libmailutils/stream/fltstream.c      |    4 +-
 libmailutils/stream/message_stream.c |    2 +-
 libmailutils/tests/address.at        |   18 +++++-----
 libmailutils/url/create.c            |    2 +-
 libmailutils/url/set-service.c       |    2 +-
 libmu_dbm/dbm.c                      |    4 +-
 libproto/imap/mbox.c                 |    2 +-
 libproto/mailer/sendmail.c           |    4 +-
 libproto/mbox/mbox.c                 |    2 +
 libproto/mbox/mboxscan.c             |    2 +-
 libproto/pop/pop3_list.c             |    2 +-
 python/mailutils/error.py            |    2 +-
 17 files changed, 85 insertions(+), 79 deletions(-)

diff --git a/libmailutils/address/parse822.c b/libmailutils/address/parse822.c
index f9001aa..526afd1 100644
--- a/libmailutils/address/parse822.c
+++ b/libmailutils/address/parse822.c
@@ -97,7 +97,7 @@ actually help.
 #endif
 
 #define EOK	0
-#define EPARSE	MU_ERR_BAD_822_FORMAT
+#define EPARSE	MU_ERR_INVALID_EMAIL
 
 /*
  * Some convenience functions for dealing with dynamically re-sized
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index d60903f..bf08f50 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -409,7 +409,7 @@ amd_init_mailbox (mu_mailbox_t mailbox, size_t amd_size,
   struct _amd_data *amd;
 
   if (mailbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (amd_size < sizeof (*amd))
     return EINVAL;
 
@@ -533,7 +533,7 @@ amd_close (mu_mailbox_t mailbox)
   int i;
     
   if (!mailbox)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
 
   amd = mailbox->data;
   
@@ -1018,9 +1018,7 @@ amd_append_message (mu_mailbox_t mailbox, mu_message_t msg)
   struct _amd_data *amd = mailbox->data;
   struct _amd_message *mhm;
 
-  if (!mailbox)
-    return MU_ERR_MBX_NULL;
-  if (!msg)
+  if (!mailbox || !msg)
     return EINVAL;
 
   mhm = calloc (1, amd->msg_size);
diff --git a/libmailutils/diag/errors b/libmailutils/diag/errors
index 79fed33..5b88ef0 100644
--- a/libmailutils/diag/errors
+++ b/libmailutils/diag/errors
@@ -1,4 +1,3 @@
-
 # Error messages for GNU Mailutils
 # Copyright (C) 2005, 2006, 2007, 2010, 2011 Free Software Foundation,
 # Inc.
@@ -19,20 +18,20 @@
 MU_ERR_FAILURE              _("Operation failed")
 MU_ERR_CANCELED             _("Operation canceled")
 
-MU_ERR_NO_HANDLER           _("No registered handler")
 MU_ERR_EMPTY_VFN            _("Empty virtual function")
 
-MU_ERR_OUT_NULL             _("Pointer to output null")
-MU_ERR_OUT_PTR_NULL         _("Pointer to output pointer null")
+# A counterpart of EINVAL.  Functions receiving invalid input arguments
+# return EINVAL, those receiving invalid output arguments return this
+# code:
+MU_ERR_OUT_PTR_NULL         _("Null output pointer")
 
-MU_ERR_MBX_NULL             _("Mailbox null")
 MU_ERR_MBX_REMOVED          _("Mailbox removed")
 
 MU_ERR_NOT_OPEN             _("Resource not open")
 MU_ERR_OPEN                 _("Resource is already open")
 
-MU_ERR_BAD_822_FORMAT       _("Format of RFC822 object is bad")
-MU_ERR_EMPTY_ADDRESS        _("Address contains no addr specs")
+MU_ERR_INVALID_EMAIL        _("Malformed email address")
+MU_ERR_EMPTY_ADDRESS        _("Empty address list")
 
 MU_ERR_LOCKER_NULL          _("Locker null")
 MU_ERR_LOCK_CONFLICT        _("Conflict with previous locker")
@@ -47,13 +46,14 @@ MU_ERR_NO_SUCH_USER         _("No such user name")
 
 MU_ERR_GETHOSTBYNAME        _("DNS name resolution failed")
 MU_ERR_BAD_RESUMPTION       _("State busy must resume operation")
-MU_ERR_MAILER_BAD_FROM      _("Not a valid mailer from address")
-MU_ERR_MAILER_BAD_TO        _("Not a valid mailer to address")
-MU_ERR_MAILER_NO_RCPT_TO    _("No receipt addresses found")
+MU_ERR_MAILER_BAD_FROM      _("Not a valid sender address")
+MU_ERR_MAILER_BAD_TO        _("Not a valid recipient address")
+MU_ERR_MAILER_NO_RCPT_TO    _("No recipient addresses found")
 MU_ERR_MAILER_BAD_URL       _("Malformed or unsupported mailer URL")
-MU_ERR_SMTP_RCPT_FAILED     _("SMTP rcpt to command failed")
-MU_ERR_TCP_NO_HOST          _("Tcp connections need a host")
-MU_ERR_TCP_NO_PORT          _("Tcp connections need a positive port")
+MU_ERR_SMTP_RCPT_FAILED     _("SMTP RCPT command failed")
+
+MU_ERR_TCP_NO_HOST          _("Required host specification is missing")
+MU_ERR_TCP_NO_PORT          _("Invalid port or service specification")
 
 MU_ERR_BAD_2047_INPUT       _("Input string is not RFC 2047 encoded")
 MU_ERR_BAD_2047_ENCODING    _("Not a valid RFC 2047 encoding")
@@ -63,7 +63,7 @@ MU_ERR_NOPASSWORD           _("User password is not supplied")
 MU_ERR_BADREPLY             _("Invalid reply from the remote host")
 
 MU_ERR_SEQ                  _("Bad command sequence")
-MU_ERR_REPLY                _("Erroneous reply received")
+MU_ERR_REPLY                _("Operation rejected by remote party")
 
 MU_ERR_BAD_AUTH_SCHEME      _("Unsupported authentication scheme")
 MU_ERR_AUTH_FAILURE         _("Authentication failed")
@@ -78,6 +78,7 @@ MU_ERR_NOENT                _("Requested item not found")
 MU_ERR_EXISTS               _("Item already exists")
 MU_ERR_BUFSPACE             _("Not enough buffer space")
 
+# Database errors
 MU_ERR_SQL                  _("SQL error")
 MU_ERR_DB_ALREADY_CONNECTED _("Already connected to the database")
 MU_ERR_DB_NOT_CONNECTED     _("Not connected to the database")
@@ -94,9 +95,15 @@ MU_ERR_READ                 _("Read error")
 MU_ERR_NO_TRANSPORT         _("Transport stream not set")
 MU_ERR_AUTH_NO_CRED         _("No credentials supplied")
 
+# URL-related errors
 MU_ERR_URL_MISS_PARTS       _("URL missing required parts")
 MU_ERR_URL_EXTRA_PARTS      _("URL has parts not allowed by its scheme")
+MU_ERR_URL_INVALID_PARAMETER _("Invalid parameter in URL")
 
+# This error is returned when the requested data cannot be obtained right
+# now or by the given means, or obtaining them is too costly, e.g. as
+# obtaining number of lines in a message via POP3 (which would involve
+# downloading entire message) by mu_message_quick_lines.
 MU_ERR_INFO_UNAVAILABLE	    _("Information is not yet available")
 
 # The following are mapped to the corresponding EAI_ errors
@@ -106,7 +113,7 @@ MU_ERR_SOCKTYPE             _("Socket type not supported")
 MU_ERR_FAMILY               _("Address family not supported")
 MU_ERR_SERVICE              _("Requested service not supported")
 
-# File safety check
+# File safety checks
 MU_ERR_PERM_OWNER_MISMATCH  _("File owner mismatch")
 MU_ERR_PERM_GROUP_WRITABLE  _("Group writable file")
 MU_ERR_PERM_WORLD_WRITABLE  _("World writable file")
@@ -116,5 +123,3 @@ MU_ERR_PERM_LINKED_WRDIR    _("Linked file in a writable directory")
 MU_ERR_PERM_DIR_IWGRP       _("File in group writable directory")
 MU_ERR_PERM_DIR_IWOTH       _("File in world writable directory")
 
-# A simpler version of the above.  Possibly will be removed in the future.
-MU_ERR_UNSAFE_PERMS         _("Unsafe file permissions")
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index 34071be..4ffdab1 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -145,7 +145,7 @@ _mailbox_create_from_record (mu_mailbox_t *pmbox,
 	*pmbox = mbox;
       return status;
     }
-  return MU_ERR_NO_HANDLER;
+  return ENOSYS;
 }
 
 static int
@@ -156,7 +156,7 @@ _create_mailbox0 (mu_mailbox_t *pmbox, mu_url_t url, const char *name)
   if (mu_registrar_lookup_url (url, MU_FOLDER_ATTRIBUTE_FILE, &record, NULL)
       == 0)
     return _mailbox_create_from_record (pmbox, record, url, name);
-  return MU_ERR_NO_HANDLER;
+  return ENOSYS;
 }
 
 static int
@@ -268,7 +268,7 @@ mu_mailbox_open (mu_mailbox_t mbox, int flag)
   int rc;
   
   if (!mbox)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mbox->_open == NULL)
     return MU_ERR_EMPTY_VFN;
   if (mbox->flags & _MU_MAILBOX_OPEN)
@@ -278,7 +278,7 @@ mu_mailbox_open (mu_mailbox_t mbox, int flag)
       /* Quick access mailboxes are read-only */
       if (flag & (MU_STREAM_WRITE 
 		  | MU_STREAM_APPEND | MU_STREAM_CREAT))
-	return EINVAL; /* FIXME: Better error code, please? */
+	return EACCES;
     }
   rc = mbox->_open (mbox, flag);
   if (rc == 0)
@@ -292,7 +292,7 @@ mu_mailbox_close (mu_mailbox_t mbox)
   int rc;
 
   if (!mbox)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (!(mbox->flags & _MU_MAILBOX_OPEN))
     return MU_ERR_NOT_OPEN;
   if (mbox == NULL || mbox->_close == NULL)
@@ -308,7 +308,7 @@ int
 mu_mailbox_remove (mu_mailbox_t mbox)
 {
   if (!mbox)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mbox->flags & _MU_MAILBOX_OPEN)
     return MU_ERR_OPEN;
   if (mbox->flags & _MU_MAILBOX_REMOVED)
@@ -325,7 +325,7 @@ mu_mailbox_flush (mu_mailbox_t mbox, int expunge)
   int status = 0;
   
   if (!mbox)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mbox->flags & _MU_MAILBOX_REMOVED)
     return MU_ERR_MBX_REMOVED;
   if (!(mbox->flags & _MU_MAILBOX_OPEN))
@@ -354,7 +354,7 @@ mu_mailbox_flush (mu_mailbox_t mbox, int expunge)
 
 #define _MBOX_CHECK_FLAGS(mbox)			\
   if (mbox == NULL)				\
-    return MU_ERR_MBX_NULL;			\
+    return EINVAL;			        \
   if (mbox->flags & _MU_MAILBOX_REMOVED)	\
     return MU_ERR_MBX_REMOVED;			\
   if (!(mbox->flags & _MU_MAILBOX_OPEN))	\
@@ -517,7 +517,7 @@ int
 mu_mailbox_set_locker (mu_mailbox_t mbox, mu_locker_t locker)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mbox->locker)
     mu_locker_destroy (&mbox->locker);
   mbox->locker = locker;
@@ -528,7 +528,7 @@ int
 mu_mailbox_get_locker (mu_mailbox_t mbox, mu_locker_t *plocker)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (plocker == NULL)
     return MU_ERR_OUT_PTR_NULL;
   *plocker = mbox->locker;
@@ -539,9 +539,9 @@ int
 mu_mailbox_get_flags (mu_mailbox_t mbox, int *flags)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (!*flags)
-    return MU_ERR_OUT_NULL;
+    return EINVAL;
+  if (!flags)
+    return MU_ERR_OUT_PTR_NULL;
   *flags = mbox->flags & ~_MU_MAILBOX_MASK;
   return 0;
 }
@@ -550,7 +550,7 @@ int
 mu_mailbox_set_stream (mu_mailbox_t mbox, mu_stream_t stream)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mbox->flags & MU_STREAM_QACCESS)
     return MU_ERR_BADOP;
   if (mbox->stream)
@@ -560,19 +560,20 @@ mu_mailbox_set_stream (mu_mailbox_t mbox, mu_stream_t stream)
 }
 
 /* FIXME: This is a problem.  We provide a mu_mailbox_get_stream ()
-   and this stream is special it should, in theory, represent
-   a "view" of a flow of messages.  But providing this perspective
-   may make sense for local mailboxes but downright impossible
-   for a remote mailbox, short on downloading the entire mailbox
+   and this stream is special: it should, in theory, represent
+   a "view" of a flow of messages.  However, providing this perspective
+   may make sense for local mailboxes, but downright impossible
+   for remote mailboxes, short on downloading entire mailbox
    locally.
-   The question is : should this function be removed?
-   So far it as been used on local mailboxes to get offsets.  */
+
+   This function will be removed in the short run.  It is no longer
+   used by MU.  */
 int
 mu_mailbox_get_stream (mu_mailbox_t mbox, mu_stream_t *pstream)
 {
   /* FIXME: Deprecation warning */
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (pstream == NULL)
     return MU_ERR_OUT_PTR_NULL;
 
@@ -592,7 +593,7 @@ int
 mu_mailbox_get_streamref (mu_mailbox_t mbox, mu_stream_t *pstream)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (pstream == NULL)
     return MU_ERR_OUT_PTR_NULL;
 
@@ -611,7 +612,7 @@ int
 mu_mailbox_get_observable (mu_mailbox_t mbox, mu_observable_t *pobservable)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (pobservable == NULL)
     return MU_ERR_OUT_PTR_NULL;
 
@@ -629,7 +630,7 @@ int
 mu_mailbox_set_property (mu_mailbox_t mbox, mu_property_t property)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mbox->property)
     mu_property_unref (mbox->property);
   mbox->property = property;
@@ -641,7 +642,7 @@ int
 mu_mailbox_get_property (mu_mailbox_t mbox, mu_property_t *pproperty)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (pproperty == NULL)
     return MU_ERR_OUT_PTR_NULL;
   
@@ -665,7 +666,7 @@ int
 mu_mailbox_get_url (mu_mailbox_t mbox, mu_url_t *purl)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (purl == NULL)
     return MU_ERR_OUT_PTR_NULL;
   *purl = mbox->url;
@@ -676,7 +677,7 @@ int
 mu_mailbox_get_folder (mu_mailbox_t mbox, mu_folder_t *pfolder)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (pfolder == NULL)
     return MU_ERR_OUT_PTR_NULL;
   *pfolder = mbox->folder;
@@ -687,7 +688,7 @@ int
 mu_mailbox_set_folder (mu_mailbox_t mbox, mu_folder_t folder)
 {
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
    mbox->folder = folder;
   return 0;
 }
@@ -715,9 +716,9 @@ mu_mailbox_get_uidls (mu_mailbox_t mbox, mu_list_t *plist)
   int status;
 
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (plist == NULL)
     return EINVAL;
+  if (plist == NULL)
+    return MU_ERR_OUT_PTR_NULL;
   status = mu_list_create (&list);
   if (status)
     return status;
@@ -847,9 +848,9 @@ mu_mailbox_translate (mu_mailbox_t mbox, int cmd, size_t from, size_t *to)
   mu_message_t msg;
   
   if (mbox == NULL)
-    return MU_ERR_MBX_NULL;
-  if (to == NULL)
     return EINVAL;
+  if (to == NULL)
+    return MU_ERR_OUT_PTR_NULL;
   if (mbox->flags & MU_STREAM_QACCESS)
     return MU_ERR_BADOP;
 
diff --git a/libmailutils/mailer/mailer.c b/libmailutils/mailer/mailer.c
index 8dbce63..eea2709 100644
--- a/libmailutils/mailer/mailer.c
+++ b/libmailutils/mailer/mailer.c
@@ -372,7 +372,7 @@ safe_address_create (mu_address_t *paddr, const char *addr_str,
 		     const char *who)
 {
   int status = mu_address_create (paddr, addr_str);
-  if (status == MU_ERR_BAD_822_FORMAT)
+  if (status == MU_ERR_INVALID_EMAIL)
     {
       int rc;
       char *p;
@@ -394,7 +394,7 @@ safe_address_create (mu_address_t *paddr, const char *addr_str,
 	  rc = mu_address_create (paddr, p);
 	  if (rc == 0)
 	    status = 0;
-	  else if (rc == MU_ERR_BAD_822_FORMAT)
+	  else if (rc == MU_ERR_INVALID_EMAIL)
 	    mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE1,
 		      ("%s address guess failed", who));
 	  else
diff --git a/libmailutils/stream/fltstream.c b/libmailutils/stream/fltstream.c
index ef5f2ba..e01cdde 100644
--- a/libmailutils/stream/fltstream.c
+++ b/libmailutils/stream/fltstream.c
@@ -197,7 +197,7 @@ filter_read (mu_stream_t stream, char *buf, size_t size, size_t *pret)
       
 	  if (iobuf.isize > MFB_RDBYTES (fs->inbuf)
 	      || iobuf.osize > MFB_FREESIZE (fs->outbuf))
-	    return MU_ERR_FAILURE; /* FIXME: special error code? */
+	    return MU_ERR_BUFSPACE;
 	  
 	  /* iobuf.osize contains number of bytes written to output */
 	  MFB_advance_level (&fs->outbuf, iobuf.osize);
@@ -334,7 +334,7 @@ filter_write_internal (mu_stream_t stream, enum mu_filter_command cmd,
       
       if (iobuf.isize > MFB_RDBYTES (fs->inbuf)
 	  || iobuf.osize > MFB_FREESIZE (fs->outbuf))
-	return MU_ERR_FAILURE; /* FIXME: special error code? */
+	return MU_ERR_BUFSPACE;
       
       /* iobuf.osize contains number of bytes written to output */
       MFB_advance_level (&fs->outbuf, iobuf.osize);
diff --git a/libmailutils/stream/message_stream.c b/libmailutils/stream/message_stream.c
index f0c5f80..a4d9033 100644
--- a/libmailutils/stream/message_stream.c
+++ b/libmailutils/stream/message_stream.c
@@ -230,7 +230,7 @@ _message_open (mu_stream_t stream)
 		  offset += len;
 		  continue;
 		}
-	      return MU_ERR_BAD_822_FORMAT;
+	      return MU_ERR_INVALID_EMAIL;
 	    }
 	  has_headers = 1;
 	  if (!env_from || !env_date)
diff --git a/libmailutils/tests/address.at b/libmailutils/tests/address.at
index cbf546c..6b68d58 100644
--- a/libmailutils/tests/address.at
+++ b/libmailutils/tests/address.at
@@ -34,7 +34,7 @@ AT_CLEANUP
 TESTADDR([Sam <@[matrix (smtp)], @[nexus: [node 12]]:sroberts@[10].[1]>],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([a@b,z@y],[],
@@ -226,7 +226,7 @@ TESTADDR([a group: ,, ;],[group],
 TESTADDR([Sam <@[matrix (smtp)], @[nexus: [node 12]]:sroberts@[10].[1]> ;],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([Aliens: Sam <@[matrix (smtp)]: sam@sam>, sroberts@[10].[1];],[],
@@ -296,7 +296,7 @@ route <@mail2.uniserve.com>
 TESTADDR([< (hey) @ (hey, )smtp1.sympatico.ca, mail2.uniserve.com (hoo!):sroberts@uniserve.com>],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([hw@570.com (Hardware Support Account)],[],
@@ -374,7 +374,7 @@ local-part <paul> domain <pitbull-productions.com>
 TESTADDR(["'sam@cogent.ca'" <sam@cogent.ca>, "'sroberts@uniserve.com'"],[],
 [0],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR(["'sroberts\@certicom\.ca'" <sroberts@certicom.ca>],[],
@@ -603,7 +603,7 @@ local-part <zwk%f36.n480.z2.fidonet.org> domain <f36.n480.z2.fidonet.org>
 TESTADDR(['Dan Dall'Acqua' <ddallacqua@noetic.ab.ca>, 'Dave Shyong'],[],
 [0],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([0xdeadbeef-request@petting-zoo.net],[],
@@ -657,7 +657,7 @@ local-part <Nick_Shelness> domain <motorcity2.lotus.com>
 TESTADDR([<all: >],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([<fyi-admin@emyr.net>],[],
@@ -1008,7 +1008,7 @@ local-part <Kieran.O'Leary> domain <anpost.ie>
 TESTADDR([rfunk@wks.uts.ohio-state.eduofflinemailer-bounce@dikke.penguin.nl],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([root],[],
@@ -1021,7 +1021,7 @@ local-part <root> domain <localhost>
 TESTADDR([whom it may concern: ;;whom.it.may.concern: ;],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 TESTADDR([whom it may concern: mutt-dev@mutt.org, mutt-users@mutt.org;],[],
@@ -1052,7 +1052,7 @@ local-part <bach> domain <somewhere.org>
 TESTADDR(["A bad quote\" <devnull@localhost>],[],
 [1],
 [],
-[MU_ERR_BAD_822_FORMAT
+[MU_ERR_INVALID_EMAIL
 ])
 
 
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index d6b01be..b86fc41 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -476,7 +476,7 @@ _mu_url_create_internal (struct mu_url_ctx *ctx, mu_url_t hint)
 	      /* FIXME: Another proto? */
 	      struct servent *sp = getservbyname (url->portstr, "tcp");
 	      if (!sp)
-		return MU_ERR_TCP_NO_PORT; //FIXME: Error code?
+		return MU_ERR_TCP_NO_PORT; 
 	      url->port = ntohs (sp->s_port);
 	    }
 	  else
diff --git a/libmailutils/url/set-service.c b/libmailutils/url/set-service.c
index f570977..5f2fb04 100644
--- a/libmailutils/url/set-service.c
+++ b/libmailutils/url/set-service.c
@@ -53,7 +53,7 @@ mu_url_set_service (mu_url_t url, const char *str)
 	  /* FIXME: 2. Another proto? */
 	  struct servent *sp = getservbyname (str, "tcp");
 	  if (!sp)
-	    return MU_ERR_TCP_NO_PORT; /*FIXME: Error code?*/
+	    return MU_ERR_TCP_NO_PORT;
 	  port = ntohs (sp->s_port);
 	}
       else if (n > USHRT_MAX)
diff --git a/libmu_dbm/dbm.c b/libmu_dbm/dbm.c
index 794affb..2472dcf 100644
--- a/libmu_dbm/dbm.c
+++ b/libmu_dbm/dbm.c
@@ -204,7 +204,7 @@ mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db)
 		    }
 		}
 	      else if (name[5])
-		return MU_ERR_URL_EXTRA_PARTS;//FIXME: better error code
+		return MU_ERR_URL_INVALID_PARAMETER;
 	    }
 	  else if (strcmp (name, "none") == 0)
 	    {
@@ -221,7 +221,7 @@ mu_dbm_create_from_url (mu_url_t url, mu_dbm_file_t *db)
 	      val = DEFAULT_DBM_SAFETY_FLAGS;
 	    }
 	  else if (mu_file_safety_name_to_code (name, &val))
-	    return MU_ERR_URL_EXTRA_PARTS;//FIXME: better error code
+	    return MU_ERR_URL_INVALID_PARAMETER;
 
 	  if (negate)
 	    safety_flags &= ~val;
diff --git a/libproto/imap/mbox.c b/libproto/imap/mbox.c
index f678f40..5a5f69f 100644
--- a/libproto/imap/mbox.c
+++ b/libproto/imap/mbox.c
@@ -128,7 +128,7 @@ _mailbox_imap_and_imaps_init (mu_mailbox_t mailbox, int imaps)
   m_imap_t m_imap;
 
   if (!mailbox)
-    return MU_ERR_MBX_NULL;
+    return EINVAL;
   if (mailbox->folder == NULL)
     return EINVAL;
   
diff --git a/libproto/mailer/sendmail.c b/libproto/mailer/sendmail.c
index 4fbedbf..6f45948 100644
--- a/libproto/mailer/sendmail.c
+++ b/libproto/mailer/sendmail.c
@@ -166,7 +166,7 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
 	  mu_debug (MU_DEBCAT_MAILER, MU_DEBUG_TRACE,
 		    ("envelope from (%s) not fully qualifed\n",
 		     emailfrom));
-	  return MU_ERR_BAD_822_FORMAT;
+	  return MU_ERR_INVALID_EMAIL;
 	}
 
       argc += 2;		/* -f from */
@@ -239,7 +239,7 @@ sendmail_send_message (mu_mailer_t mailer, mu_message_t msg, mu_address_t from,
 			("envelope to (%s) not fully qualifed",
 			 email));
 	      free (argvec);
-	      return MU_ERR_BAD_822_FORMAT;
+	      return MU_ERR_INVALID_EMAIL;
 	    }
 	  argvec[argc++] = email;
 	}
diff --git a/libproto/mbox/mbox.c b/libproto/mbox/mbox.c
index 7e65b88..42a35ef 100644
--- a/libproto/mbox/mbox.c
+++ b/libproto/mbox/mbox.c
@@ -1307,6 +1307,8 @@ mbox_expunge_unlocked (mu_mailbox_t mailbox, size_t dirty, int remove_deleted,
       else if (size < mud->size)
 	{
 	  /* Corrupted mailbox. */
+	  mu_observable_notify (mailbox->observable, MU_EVT_MAILBOX_CORRUPT,
+				mailbox);
 	  mu_error (_("%s:%d: mailbox shrunk while expunging"),
 		    __FILE__, __LINE__);
 	  return MU_ERR_FAILURE; /* FIXME: need an error code for that */
diff --git a/libproto/mbox/mboxscan.c b/libproto/mbox/mboxscan.c
index e3bb926..7492c8e 100644
--- a/libproto/mbox/mboxscan.c
+++ b/libproto/mbox/mboxscan.c
@@ -346,7 +346,7 @@ mbox_scan_internal (mu_mailbox_t mailbox, mbox_message_t mum,
 	{
 	  /* In one-message mode, the positioning should be exact. */
 	  if (!isfrom)
-	    return EINVAL; /* FIXME: Better error code, please? */
+	    return MU_ERR_NOENT;
 	}
       
       /* Which part of the message are we in ?  */
diff --git a/libproto/pop/pop3_list.c b/libproto/pop/pop3_list.c
index fa45e4d..649d4c0 100644
--- a/libproto/pop/pop3_list.c
+++ b/libproto/pop/pop3_list.c
@@ -34,7 +34,7 @@ mu_pop3_list (mu_pop3_t pop3, unsigned int msgno, size_t *psize)
   if (pop3 == NULL || msgno == 0)
     return EINVAL;
   if (psize == NULL)
-    return MU_ERR_OUT_NULL;
+    return MU_ERR_OUT_PTR_NULL;
 
   switch (pop3->state)
     {
diff --git a/python/mailutils/error.py b/python/mailutils/error.py
index b853cd0..9eb8492 100644
--- a/python/mailutils/error.py
+++ b/python/mailutils/error.py
@@ -53,7 +53,7 @@ MU_ERR_EMPTY_VFN = (MU_ERR_BASE+3)
 MU_ERR_OUT_NULL = (MU_ERR_BASE+4)
 MU_ERR_OUT_PTR_NULL = (MU_ERR_BASE+5)
 MU_ERR_MBX_NULL = (MU_ERR_BASE+6)
-MU_ERR_BAD_822_FORMAT = (MU_ERR_BASE+7)
+MU_ERR_INVALID_EMAIL = (MU_ERR_BASE+7)
 MU_ERR_EMPTY_ADDRESS = (MU_ERR_BASE+8)
 MU_ERR_LOCKER_NULL = (MU_ERR_BASE+9)
 MU_ERR_LOCK_CONFLICT = (MU_ERR_BASE+10)


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 29 17:17:26 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RKGHO-00012b-L0
	for mharc-commit-mailutils@gnu.org; Sat, 29 Oct 2011 17:17:26 -0400
Received: from eggs.gnu.org ([140.186.70.92]:57019)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKGHL-000129-OS
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 17:17:24 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKGHK-0001hl-Ej
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 17:17:23 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:44809)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKGHK-0001hh-A1
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 17:17:22 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKGHJ-0007ap-Ez
	for commit-mailutils@gnu.org; Sat, 29 Oct 2011 21:17:22 +0000
Date: Sat, 29 Oct 2011 21:17:21 +0000
Message-Id: <E1RKGHJ-0007ap-Ez@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-414-g7e1ce57
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 5f796a9c31d4ab9c281af3a072ae4d150fd2a1fb
X-Git-Newrev: 7e1ce572fc47fc192f7b1b47d44a9441d010f1cd
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 29 Oct 2011 21:17:24 -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=7e1ce572fc47fc192f7b1b47d44a9441d010f1cd

The branch, master has been updated
       via  7e1ce572fc47fc192f7b1b47d44a9441d010f1cd (commit)
      from  5f796a9c31d4ab9c281af3a072ae4d150fd2a1fb (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 7e1ce572fc47fc192f7b1b47d44a9441d010f1cd
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Oct 30 00:17:52 2011 +0300

    Minor change

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

Summary of changes:
 libmailutils/url/set-service.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/libmailutils/url/set-service.c b/libmailutils/url/set-service.c
index 5f2fb04..ea7508c 100644
--- a/libmailutils/url/set-service.c
+++ b/libmailutils/url/set-service.c
@@ -27,7 +27,7 @@
 #ifdef HAVE_STRINGS_H
 # include <strings.h>
 #endif
-
+#include <limits.h>
 #include <mailutils/types.h>
 #include <mailutils/errno.h>
 #include <mailutils/sys/url.h>


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 31 11:09:05 2011
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1RKtU1-0001sJ-Pa
	for mharc-commit-mailutils@gnu.org; Mon, 31 Oct 2011 11:09:05 -0400
Received: from eggs.gnu.org ([140.186.70.92]:49940)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKtTw-0001cb-M4
	for commit-mailutils@gnu.org; Mon, 31 Oct 2011 11:09:03 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKtTr-0004Y7-ES
	for commit-mailutils@gnu.org; Mon, 31 Oct 2011 11:09:00 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:43810)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKtTr-0004Xw-BM
	for commit-mailutils@gnu.org; Mon, 31 Oct 2011 11:08:55 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1RKtTq-0004tM-HC
	for commit-mailutils@gnu.org; Mon, 31 Oct 2011 15:08:55 +0000
Date: Mon, 31 Oct 2011 15:08:54 +0000
Message-Id: <E1RKtTq-0004tM-HC@vcs.savannah.gnu.org>
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-416-gd96764b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 7e1ce572fc47fc192f7b1b47d44a9441d010f1cd
X-Git-Newrev: d96764ba829cea2bd2cbd8ff483a11101e74883b
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2)
X-Received-From: 140.186.70.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.14
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 31 Oct 2011 15:09: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=d96764ba829cea2bd2cbd8ff483a11101e74883b

The branch, master has been updated
       via  d96764ba829cea2bd2cbd8ff483a11101e74883b (commit)
       via  192e01af153545dadb14b01db810054726e152a3 (commit)
      from  7e1ce572fc47fc192f7b1b47d44a9441d010f1cd (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 d96764ba829cea2bd2cbd8ff483a11101e74883b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 31 17:07:39 2011 +0200

    cctype: bugfix.
    
    * include/mailutils/cctype.h (mu_isblank): Use mu_c_is_class.
    * libmailutils/string/muctype.c (mu_c_tab): Mark ' ' and '\t' as
    MU_CTYPE_BLANK.

commit 192e01af153545dadb14b01db810054726e152a3
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 31 15:01:37 2011 +0200

    inline-comment: bugfixes.
    
    Fixes following bugs:
    
    1. In whitespace-must-follow mode a comment sequence immediately followed
    by a newline caused the next line to be treated as a comment.  Thus the
    following input:
    
    ;
    text
    
    produced empty output (see test icmt-dec-08).
    
    2. Line number information was not emitted before lines starting
    with a comment sequence substring, e.g.:
    
    ; comment
    ;valid line
    
    See test icmt-dec-09.
    
    * libmailutils/filter/inline-comment.c (ilcmt_state)
    Withdraw ilcmt_rollback_com state, use ilcmt_rollback instead.
    Withdraw ilcmt_newline_ac state, use ILCMT_EMIT_LINE_INFO flag instead.
    (ILCMT_EMIT_LINE_INFO): New flag.
    (ilcmt_data) <replay>: Remove.
    <rollback_buffer, rollback_size>
    <rollback_index>: New members.
    (init_rollback): New function.
    (_ilcmt_decoder): Use ilcmt_rollback state.
    <ilcmt_comment_ws>: Do not skip newline following the comment.  Emit
    line info before rolling back, if required.
    (_ilcmt_encoder): Use ilcmt_rollback state.
    * libmailutils/tests/inline-comment.at: Rename tests.
    Add tests for newline after a comment (icmt-dec-08) and
    line info with whitespace-follow mode (icmt-dec-09).

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

Summary of changes:
 include/mailutils/cctype.h           |    2 +-
 libmailutils/filter/inline-comment.c |  104 ++++++++++++++++++----------------
 libmailutils/string/muctype.c        |    4 +-
 libmailutils/tests/inline-comment.at |   52 ++++++++++++++---
 4 files changed, 101 insertions(+), 61 deletions(-)

diff --git a/include/mailutils/cctype.h b/include/mailutils/cctype.h
index f56dfc0..49e1944 100644
--- a/include/mailutils/cctype.h
+++ b/include/mailutils/cctype.h
@@ -56,7 +56,7 @@ extern int mu_c_tab[MU_C_TAB_MAX];
 #define mu_isxdigit(c) mu_c_is_class (c, MU_CTYPE_DIGIT|MU_CTYPE_XLETR)
 #define mu_isalnum(c) mu_c_is_class (c, MU_CTYPE_ALPHA|MU_CTYPE_DIGIT)
 #define mu_isascii(c) (((unsigned)c) < MU_C_TAB_MAX)
-#define mu_isblank(c) ((c) == ' ' || (c) == '\t')
+#define mu_isblank(c) mu_c_is_class (c, MU_CTYPE_BLANK)
 #define mu_isendln(c) mu_c_is_class (c, MU_CTYPE_ENDLN)
 
 #define mu_tolower(c)					\
diff --git a/libmailutils/filter/inline-comment.c b/libmailutils/filter/inline-comment.c
index e1081e4..584f217 100644
--- a/libmailutils/filter/inline-comment.c
+++ b/libmailutils/filter/inline-comment.c
@@ -59,29 +59,28 @@ enum ilcmt_state
   {
     ilcmt_initial,
     ilcmt_newline,
-    ilcmt_newline_ac,
     ilcmt_copy,
     ilcmt_comment,
     ilcmt_partial,
     ilcmt_comment_ws,
     ilcmt_ws,
     ilcmt_rollback,
-    ilcmt_rollback_ws,
-    ilcmt_rollback_com
+    ilcmt_rollback_ws
   };
 
-#define ILCMT_REMOVE_EMPTY_LINES 0x01 /* Just that :) */
-#define ILCMT_SQUEEZE_WS         0x02 /* Replace a series of whitespace
-					 characters with a single space */
-#define ILCMT_FOLLOW_WS          0x04 /* In decode mode: comment sequence is
-					 recognized only if followed by a
-					 whitespace character.
-					 In encode mode: output a space after
-					 each comment prefix. */
-#define ILCMT_LINE_INFO          0x08 /* Emit line number information */ 
+#define ILCMT_REMOVE_EMPTY_LINES 0x001 /* Just that :) */
+#define ILCMT_SQUEEZE_WS         0x002 /* Replace a series of whitespace
+					  characters with a single space */
+#define ILCMT_FOLLOW_WS          0x004 /* In decode mode: comment sequence is
+					  recognized only if followed by a
+					  whitespace character.
+					  In encode mode: output a space after
+					  each comment prefix. */
+#define ILCMT_LINE_INFO          0x008 /* Emit line number information */ 
 
 #define ILCMT_COMMENT_STATIC     0x0100
 #define ILCMT_LINE_INFO_STATIC   0x0200
+#define ILCMT_EMIT_LINE_INFO     0x0400
 
 struct ilcmt_data
 {
@@ -94,15 +93,15 @@ struct ilcmt_data
   char sbuf[3];            /* Static location for single-character strings */
   char *buf;               /* Rollback buffer ... */
   size_t size;             /* and its size */
-  size_t level;            /* In ilcmt_partial and ilcmt_rollback_com
-			      states: number of bytes matched in the comment
-			      sequence.
-			      In ilcmt_initial, ilcmt_newline, and
-			      ilcmt_rollback_ws states: number of characters
+  size_t level;            /* In ilcmt_partial state: number of bytes matched
+			      in the comment sequence.
+			      In other states: number of characters
 			      stored in buf. */
-  size_t replay;           /* Index of the next-to-be-replayed character
-			      in buf (if state==ilcmt_rollback_ws) or
-			      comment (if state==ilcmt_rollback_com) */
+  /* Rollback info: */
+  char *rollback_buffer;   /* Actual rollback data */
+  size_t rollback_size;    /* Size of rollback data */
+  size_t rollback_index;   /* Index of the next-to-be-replayed character
+			      in rollback_buffer */
 };
 
 #define ILCMT_BUF_INIT 80
@@ -141,6 +140,15 @@ _ilcmt_free (struct ilcmt_data *pd)
   free (pd->buf);
 }
 
+static void
+init_rollback (struct ilcmt_data *pd, char *buf, size_t size)
+{
+  pd->state = ilcmt_rollback;
+  pd->rollback_buffer = buf;
+  pd->rollback_size = size;
+  pd->rollback_index = 0;
+}
+
 static enum mu_filter_result
 _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
 		struct mu_filter_io *iobuf)
@@ -174,21 +182,19 @@ _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
 	{
 	case ilcmt_initial:
 	case ilcmt_newline:
-	case ilcmt_newline_ac:
 	  if (*iptr == *pd->comment)
 	    {
 	      iptr++;
 	      pd->level = 1;
 	      pd->state = ilcmt_partial;
 	    }
-	  else if (pd->state == ilcmt_newline_ac)
+	  else if (pd->flags & ILCMT_EMIT_LINE_INFO)
 	    {
 	      mu_asnprintf (&pd->buf, &pd->size, "%s %lu\n",
 			    pd->line_info_starter,
 			    pd->line_number);
-	      pd->level = strlen (pd->buf);
-	      pd->replay = 0;
-	      pd->state = ilcmt_rollback;
+	      init_rollback (pd, pd->buf, strlen (pd->buf));
+	      pd->flags &= ~ILCMT_EMIT_LINE_INFO;
 	    }
 	  else if (*iptr == '\n')
 	    {
@@ -243,22 +249,32 @@ _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
 	  else
 	    {
 	      /* Begin restoring */
-	      pd->replay = 0;
-	      pd->state = ilcmt_rollback_com;
+	      init_rollback (pd, pd->comment, pd->level);
 	    }
 	  break;
 
 	case ilcmt_comment_ws:
 	  if (mu_isspace (*iptr))
 	    {
-	      iptr++;
+	      if (*iptr != '\n')
+		iptr++;
 	      pd->state = ilcmt_comment;
 	    }
 	  else
 	    {
 	      /* Begin restoring */
-	      pd->replay = 0;
-	      pd->state = ilcmt_rollback_com;
+	      if (pd->flags & ILCMT_EMIT_LINE_INFO)
+		{
+		  mu_asnprintf (&pd->buf, &pd->size, "%s %lu\n%.*s",
+				pd->line_info_starter,
+				pd->line_number,
+				pd->level,
+				pd->comment);
+		  init_rollback (pd, pd->buf, strlen (pd->buf));
+		  pd->flags &= ~ILCMT_EMIT_LINE_INFO;
+		}
+	      else
+		init_rollback (pd, pd->comment, pd->level);
 	    }
 	  break;
 	  
@@ -280,7 +296,7 @@ _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
 	    }
 	  else
 	    {
-	      pd->replay = 0;
+	      init_rollback (pd, pd->buf, pd->level);
 	      pd->state = ilcmt_rollback_ws;
 	    }
 	  break;
@@ -298,18 +314,11 @@ _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
 	    {
 	      pd->line_number++;
 	      if (pd->flags & ILCMT_LINE_INFO)
-		pd->state = ilcmt_newline_ac;
-	      else
-		pd->state = ilcmt_newline;
+		pd->flags |= ILCMT_EMIT_LINE_INFO;
+	      pd->state = ilcmt_newline;
 	    }
 	  break;
 
-	case ilcmt_rollback_com:
-	  *optr++ = pd->comment[pd->replay++];
-	  if (pd->replay == pd->level)
-	    pd->state = ilcmt_copy;
-	  break;
-
 	case ilcmt_rollback_ws:
 	  if (pd->flags & ILCMT_SQUEEZE_WS)
 	    {
@@ -319,8 +328,8 @@ _ilcmt_decoder (void *xd, enum mu_filter_command cmd,
 	    }
 	  /* fall through */
 	case ilcmt_rollback:
-	  *optr++ = pd->buf[pd->replay++];
-	  if (pd->replay == pd->level)
+	  *optr++ = pd->rollback_buffer[pd->rollback_index++];
+	  if (pd->rollback_index == pd->rollback_size)
 	    pd->state = ilcmt_copy;
 	}
     }
@@ -363,11 +372,10 @@ _ilcmt_encoder (void *xd,
 	{
 	case ilcmt_initial:
 	case ilcmt_newline:
-	  pd->replay = 0;
-	  pd->state = ilcmt_rollback_com;
-	case ilcmt_rollback_com:
-	  *optr++ = pd->comment[pd->replay++];
-	  if (pd->replay == pd->length)
+	  init_rollback (pd, pd->comment, pd->length);
+	case ilcmt_rollback:
+	  *optr++ = pd->rollback_buffer[pd->rollback_index++];
+	  if (pd->rollback_index == pd->rollback_size)
 	    pd->state = (pd->flags & ILCMT_FOLLOW_WS) ?
 	                   ilcmt_ws : ilcmt_copy;
 	  break;
@@ -404,7 +412,7 @@ alloc_state (void **pret, int mode MU_ARG_UNUSED, int argc, const char **argv)
 
   pd->flags = 0;
   pd->buf = NULL;
-  pd->size = pd->level = pd->replay = 0;
+  pd->size = pd->level = 0;
   pd->line_number = 1;
 
   for (i = 1; i < argc; i++)
diff --git a/libmailutils/string/muctype.c b/libmailutils/string/muctype.c
index 669c40a..5e9eafd 100644
--- a/libmailutils/string/muctype.c
+++ b/libmailutils/string/muctype.c
@@ -30,7 +30,7 @@ int mu_c_tab[MU_C_TAB_MAX] = {
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
-  MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
+  MU_CTYPE_CNTRL|MU_CTYPE_SPACE|MU_CTYPE_BLANK,
   MU_CTYPE_CNTRL|MU_CTYPE_SPACE|MU_CTYPE_ENDLN,
   MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
   MU_CTYPE_CNTRL|MU_CTYPE_SPACE,
@@ -53,7 +53,7 @@ int mu_c_tab[MU_C_TAB_MAX] = {
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
   MU_CTYPE_CNTRL,
-  MU_CTYPE_PRINT|MU_CTYPE_SPACE,
+  MU_CTYPE_PRINT|MU_CTYPE_SPACE|MU_CTYPE_BLANK,
   MU_CTYPE_GRAPH|MU_CTYPE_PRINT|MU_CTYPE_PUNCT,
   MU_CTYPE_GRAPH|MU_CTYPE_PRINT|MU_CTYPE_PUNCT,
   MU_CTYPE_GRAPH|MU_CTYPE_PRINT|MU_CTYPE_PUNCT,
diff --git a/libmailutils/tests/inline-comment.at b/libmailutils/tests/inline-comment.at
index cde382d..61e13d0 100644
--- a/libmailutils/tests/inline-comment.at
+++ b/libmailutils/tests/inline-comment.at
@@ -40,7 +40,7 @@ AT_CLEANUP
 
 dnl -------------------------------------------------------------------
 
-INLINECOM([default], [icmt00], [],
+INLINECOM([default], [icmt-dec-00], [],
 [; comment 1
 text 1
 ; comment 2
@@ -55,7 +55,7 @@ text 2
 text 3
 ])
 
-INLINECOM([change comment starter], [icmt02], [-- %],
+INLINECOM([change comment starter], [icmt-dec-01], [-- %],
 [% comment 1
 text 1
 % comment 2
@@ -70,7 +70,7 @@ text 2
 text 3
 ])
 
-INLINECOM([remove empty lines],[icmt03],[-- -r],
+INLINECOM([remove empty lines],[icmt-dec-02],[-- -r],
 [; comment 1
 text 1
 ; comment 2
@@ -90,7 +90,7 @@ text 4
      text 5[]dnl
 ])	
 
-INLINECOM([remove empty lines/squeeze whitespace],[icmt04],[-- -r -s],
+INLINECOM([remove empty lines/squeeze whitespace],[icmt-dec-03],[-- -r -s],
 [; comment 1
 text 1
 ; comment 2
@@ -110,7 +110,7 @@ text 4
  text 5[]dnl
 ])	
 
-INLINECOM([multichar comment starter],[icmt05],[-- rem],
+INLINECOM([multichar comment starter],[icmt-dec-04],[-- rem],
 [Text line 1
 rem remark text
 Text line 2
@@ -122,7 +122,7 @@ Text line 2
 Text line 3
 ])
 
-INLINECOM([multichar comment starter; follow ws; follow ws mode],[icmt06],
+INLINECOM([multichar comment starter; follow ws; follow ws mode],[icmt-dec-05],
 [-- rem -S],
 [Text line 1
 rem remark text
@@ -136,7 +136,7 @@ remark text (sic!)
 Text line 3
 ])
 
-INLINECOM([multichar; squeeze; remove empty],[icmt06],[-- rem -S -r],
+INLINECOM([multichar; squeeze; remove empty],[icmt-dec-06],[-- rem -S -r],
 [rem comment 1
 text 1
 rem comment 2
@@ -156,7 +156,7 @@ text 4
      text 5[]dnl
 ])	
 
-INLINECOM([line info facility],[icmt07 line-info],[-- -i ';line' ';'],
+INLINECOM([line info facility],[icmt-dec-07 line-info],[-- -i ';line' ';'],
 [; initial comment
 this is line 2
 this is line 3
@@ -174,11 +174,43 @@ this is line 3
 this is line 9
 ])
 
+INLINECOM([line info: newline after comment],[icmt-dec-08 line-info],
+[-- -i ';line' -S ';'],
+[;
+text
+],
+[;line 2
+text
+])
+
+INLINECOM([line info with follow ws],[icmt-dec-09 line-info follow-ws],
+[-- ';' -S -i ';'],
+[; Comment line
+;:directive=1
+first line
+; comment
+second line
+;:directive=2
+;
+;:directive=3
+last line
+],
+[; 2
+;:directive=1
+first line
+; 5
+second line
+;:directive=2
+; 8
+;:directive=3
+last line
+])
+
 dnl -------------------------------------------------------------------
 
 m4_define([FILTER_MODE],[encode])
 
-INLINECOM([encode],[icmt08],[],
+INLINECOM([encode],[icmt-enc-00],[],
 [C'est dans dix ans je m'en irai
 J'entends le loup et le renard chanter
 J'entends le loup, le renard et la belette
@@ -188,7 +220,7 @@ J'entends le loup et le renard chanter],
 ;J'entends le loup, le renard et la belette
 ;J'entends le loup et le renard chanter])
 
-INLINECOM([encode multichar; add ws],[icmt09],[-- NB: -S],
+INLINECOM([encode multichar; add ws],[icmt-enc-01],[-- NB: -S],
 [Tri martolod yaouank
 O voned da voyagi
 Gant'el oant bet kaset


hooks/post-receive
-- 
GNU Mailutils


