From MAILER-DAEMON Tue Jul 17 12:28:35 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1SrAdX-0008HV-8t
	for mharc-commit-mailutils@gnu.org; Tue, 17 Jul 2012 12:28:35 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55419)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrAdP-0007qp-1i
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 12:28:34 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrAdE-00075r-Hq
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 12:28:26 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:42196)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrAdE-00075n-Cu
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 12:28:16 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrAdD-0000oC-PE
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 16:28:16 +0000
Date: Tue, 17 Jul 2012 16:28:15 +0000
Message-Id: <E1SrAdD-0000oC-PE@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-616-g8658476
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 9cf47fb2b45e91177459d81f40a184265033752f
X-Git-Newrev: 8658476839bcd6704ce51f470e14cf302b888f4a
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, 17 Jul 2012 16:28:34 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=8658476839bcd6704ce51f470e14cf302b888f4a

The branch, master has been updated
       via  8658476839bcd6704ce51f470e14cf302b888f4a (commit)
       via  78f92501613a377b4c5bb2680dc071e928a96855 (commit)
       via  e9871d0f003889c8fff79ee24cb23ae0c1103d5c (commit)
       via  044c35cd493c76f49666ca1fbadb62eb18ac0a23 (commit)
      from  9cf47fb2b45e91177459d81f40a184265033752f (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 8658476839bcd6704ce51f470e14cf302b888f4a
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Jul 17 13:45:10 2012 +0300

    Improve configuration options.
    
    * am/enable.m4 (MU_ENABLE_BUILD): Change handling of additional-cond
    ($4): the --{enable|disable}-build-* argument value overrides it.
    This allows to use such configuration shortcuts as:
    
      --disable-build-clients --enable-build-mail
    
    which will build only mail, but no other client.
    
    * configure.ac: New option --with-dbm can be used to
    enable/disable building of all available DBM interfaces.
    It can be used in conjunction with implementation-specific
    options in the same way as described above, e.g.:
    
      --without-dbm --with-gdbm
    
    New option --with-mailbindir allows for overriding the installation
    directory for mail[x] only.
    
    * mail/Makefile.am (mailbindir): New variable.
    (bin_PROGRAMS): Rename to mailbin_PROGRAMS.

commit 78f92501613a377b4c5bb2680dc071e928a96855
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 16 14:26:57 2012 +0300

    Remove dependency on obstack. Use mu_opool_t instead.
    
    * include/mailutils/opool.h (mu_opool_alloc): New proto.
    * libmailutils/base/opool.c (mu_opool_alloc): New function.
    (mu_opool_appendz): Do not append trailing null character.
    * libmailutils/cfg/parser.y (mu_cfg_tree_create_node): Reflect
    the change in mu_opool_appendz.
    * comsat/action.c: Use mu_opool_t instead of struct obstack.
    * lib/mailcap.c: Likewise.
    * libmailutils/url/urlstr.c: Likewise.
    * mh/burst.c: Likewise.
    * mh/mh_fmtgram.y: Likewise.
    * mh/mh_format.c: Likewise.
    * mh/mh_format.h: Likewise.
    * mh/mhn.c: Likewise.
    * mh/repl.c: Likewise.
    * mh/whatnowenv.c: Likewise.
    * mimeview/mimetypes.l: Likewise.
    * mimeview/mimeview.h: Likewise.
    
    * gnulib.modules: Remove obstack.

commit e9871d0f003889c8fff79ee24cb23ae0c1103d5c
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 16 13:08:17 2012 +0300

    Remove dependency on getline.
    
    * gnulib.modules: Remove getline.
    * pop3d/apop.c [!ENABLE_DBM] Use mu_stream API instead of FILE.

commit 044c35cd493c76f49666ca1fbadb62eb18ac0a23
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 16 10:38:20 2012 +0300

    Bugfix.
    
    Imap4d would fail to select a nonexistent maildir INBOX, because the
    mu_mailbox_uidvalidity would return MU_ERR_NOENT.
    
    * libmailutils/base/amd.c (_amd_scan0): Recompute uidvalidity
    if the mailbox is empty.

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

Summary of changes:
 am/enable.m4              |   31 +++++-----
 comsat/action.c           |   35 +++++-------
 configure.ac              |   24 +++++++-
 gnulib.modules            |    4 +-
 include/mailutils/opool.h |    3 +
 lib/mailcap.c             |   43 ++++++-------
 libmailutils/base/amd.c   |   16 ++---
 libmailutils/base/opool.c |   22 ++++++-
 libmailutils/cfg/parser.y |    1 +
 libmailutils/url/urlstr.c |   14 ++--
 mail/Makefile.am          |    4 +-
 mh/burst.c                |   11 +--
 mh/mh_fmtgram.y           |   17 ++---
 mh/mh_format.c            |   16 +++---
 mh/mh_format.h            |    6 +--
 mh/mhn.c                  |  141 +++++++++++++++++++++++----------------------
 mh/repl.c                 |   10 ++--
 mh/whatnowenv.c           |    8 +-
 mimeview/mimetypes.l      |   72 +++++++++++------------
 mimeview/mimeview.h       |    3 -
 pop3d/apop.c              |   20 ++++---
 21 files changed, 258 insertions(+), 243 deletions(-)

diff --git a/am/enable.m4 b/am/enable.m4
index dfc256c..aeb4c7e 100644
--- a/am/enable.m4
+++ b/am/enable.m4
@@ -59,30 +59,31 @@ AC_DEFUN([MU_ENABLE_BUILD], [
 	pushdef([mu_cache_var],[mu_cv_enable_build_]translit($1,[+-],[x_]))
 	pushdef([mu_cond],[MU_COND_]mu_upcase)
 
-       	ifelse([$4],,,[if test $4; then])
-	  AC_ARG_ENABLE(build-$1, 
-	                AC_HELP_STRING([--disable-build-]$1,
-		                       [do not build ]$1),
+	AC_ARG_ENABLE(build-$1, 
+	              AC_HELP_STRING([--disable-build-]$1,
+	                             [do not build ]$1),
 	                [
   	  case "${enableval}" in
 		yes) mu_cache_var=yes;;
                 no)  mu_cache_var=no;;
 	        *)   AC_MSG_ERROR([bad value ${enableval} for --disable-$1]) ;;
           esac],
-                      [mu_cache_var=ifelse([$5],,yes,[$5])])
+                      [ifelse([$4],,[mu_cache_var=ifelse([$5],,yes,[$5])],
+		              [if test $4; then
+			         mu_cache_var=yes
+			       else
+			         mu_cache_var=no
+			       fi])])
 
-	  if test "[$]mu_cache_var" = "yes"; then
+	if test "[$]mu_cache_var" = "yes"; then
 		  ifelse([$2],,:,[$2])
 		  ifelse([$6],,,[$6="$[]$6 $1"])
-	  ifelse([$3],,,else
-                 [$3])
-	  fi
-	  if test "[$]mu_cache_var" = "yes"; then
-		AC_DEFINE([MU_BUILD_]mu_upcase,1,[Define this if you build $1])
-          fi
-	ifelse([$4],,,[else
-		mu_cache_var=no
-        fi])
+	ifelse([$3],,,else
+               [$3])
+	fi
+	if test "[$]mu_cache_var" = "yes"; then
+	  AC_DEFINE([MU_BUILD_]mu_upcase,1,[Define this if you build $1])
+        fi
 	  
 	AM_CONDITIONAL(mu_cond,
 	               [test "[$]mu_cache_var" = "yes"])
diff --git a/comsat/action.c b/comsat/action.c
index a9df4b9..c263d80 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -19,9 +19,7 @@
 #include <mailutils/io.h>
 #include <mailutils/argcv.h>
 #include <mailutils/prog.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
+#include <mailutils/opool.h>
 
 /* This module implements user-configurable actions for comsat. The
    actions are kept in file .biffrc in the user's home directory and
@@ -42,7 +40,7 @@
 		 When omitted, they default to 400, 5. */
 
 static int
-expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
+expand_escape (char **pp, mu_message_t msg, mu_opool_t pool)
 {
   char *p = *pp;
   char *start, *sval, *namep;
@@ -56,15 +54,13 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
   switch (*++p) /* skip past $ */
     {
     case 'u':
-      len = strlen (username);
-      obstack_grow (stk, username, len);
+      mu_opool_appendz (pool, username);
       *pp = p;
       rc = 0;
       break;
 
     case 'h':
-      len = strlen (hostname);
-      obstack_grow (stk, hostname, len);
+      mu_opool_appendz (pool, hostname);
       *pp = p;
       rc = 0;
       break;
@@ -85,10 +81,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
       namep[len] = 0;
       if (mu_message_get_header (msg, &hdr) == 0
 	  && mu_header_aget_value (hdr, namep, &sval) == 0)
-	{
-	  len = strlen (sval);
-	  obstack_grow (stk, sval, len);
-	}
+	mu_opool_appendz (pool, sval);
       free (namep);
       *pp = p;
       rc = 0;
@@ -131,7 +124,7 @@ expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
 		  size += s - q + 1;
 		  q = s + 1;
 		}
-	      obstack_grow (stk, buf, size);
+	      mu_opool_append (pool, buf, size);
 	    }
 	  mu_stream_destroy (&stream);
 	  free (buf);
@@ -147,11 +140,11 @@ expand_line (const char *str, mu_message_t msg)
 {
   const char *p;
   int c = 0;
-  struct obstack stk;
+  mu_opool_t pool;
 
   if (!*str)
     return NULL;
-  obstack_init (&stk);
+  mu_opool_create (&pool, 1);
   for (p = str; *p; p++)
     {
       switch (*p)
@@ -161,22 +154,22 @@ expand_line (const char *str, mu_message_t msg)
 	  if (*p)
 	    {
 	      c = mu_wordsplit_c_unquote_char (*p);
-	      obstack_1grow (&stk, c);
+	      mu_opool_append_char (pool, c);
 	    }
 	  break;
 
 	case '$':
-	  if (expand_escape ((char**)&p, msg, &stk) == 0)
+	  if (expand_escape ((char**)&p, msg, pool) == 0)
 	    break;
 
 	  /*FALLTHRU*/
 	default:
-	  obstack_1grow (&stk, *p);
+	  mu_opool_append_char (pool, *p);
 	}
     }
-  obstack_1grow (&stk, 0);
-  str = strdup (obstack_finish (&stk));
-  obstack_free (&stk, NULL);
+  mu_opool_append_char (pool, 0);
+  str = strdup (mu_opool_finish (pool, NULL));
+  mu_opool_destroy (&pool);
   return (char *)str;
 }
 
diff --git a/configure.ac b/configure.ac
index ec3b416..1e5b6b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -358,8 +358,19 @@ AC_SUBST(DBMLIBS)
 AC_SUBST(DBMLIB_DEPENDENCY)
 AC_SUBST(DBMINCLUDES)
 
-enable_dbm=no
+enable_dbm=
 disable_dbm=no
+all_dbm="GDBM BDB TC NDBM"
+
+AC_ARG_WITH([dbm],
+            AC_HELP_STRING([--with-dbm],
+	                   [build DBM support (default yes)]),
+	    [		   
+case "${withval}" in
+  yes) enable_dbm="$all_dbm";;
+  no)  enable_dbm=no;;
+  *)   enable_dbm="$withval" ;;
+esac])
 
 AC_ARG_WITH([gdbm],
             AC_HELP_STRING([--with-gdbm],
@@ -570,8 +581,8 @@ check_dbm_impl() {
   esac
 }
 
-if test "$enable_dbm" = no; then
-  enable_dbm="GDBM BDB TC NDBM"
+if test -z "$enable_dbm"; then
+  enable_dbm=$all_dbm
 fi
 
 for impl in $enable_dbm
@@ -1266,7 +1277,14 @@ MU_ENABLE_BUILD(comsat,,,["$mu_build_servers" = yes],,[server_list])
 
 MU_ENABLE_BUILD(frm,,,["$mu_build_clients" = yes],,[client_list])
 MU_ENABLE_BUILD(maidag,,,["$mu_build_clients" = yes],,[client_list])
+
 MU_ENABLE_BUILD(mail,,,["$mu_build_clients" = yes],,[client_list])
+AC_SUBST([MAILBINDIR],'${bindir}')
+AC_ARG_WITH([mailbindir],
+            [AC_HELP_STRING([--with-mailbindir=DIR],
+	                    [install mail to DIR [[BINDIR]]])],
+            [MAILBINDIR=$withval])
+
 MU_ENABLE_BUILD(sieve,,,["$mu_build_clients" = yes],,[client_list])
 MU_ENABLE_BUILD(messages,,,["$mu_build_clients" = yes],,[client_list])
 MU_ENABLE_BUILD(readmsg,,,["$mu_build_clients" = yes],,[client_list])
diff --git a/gnulib.modules b/gnulib.modules
index d9354b5..afea682 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -6,7 +6,6 @@
 autobuild
 argp
 crypto/des
-getline
 gettext
 gitlog-to-changelog
 intprops
@@ -15,6 +14,5 @@ mbchar
 mbiter
 mbslen
 mbswidth
-obstack
 setenv
-stdint
\ No newline at end of file
+stdint
diff --git a/include/mailutils/opool.h b/include/mailutils/opool.h
index 19eeef8..0d08414 100644
--- a/include/mailutils/opool.h
+++ b/include/mailutils/opool.h
@@ -42,6 +42,9 @@ void mu_opool_clear (mu_opool_t opool);
 /* Destroy the pool, reclaim any memory associated with it. */
 void mu_opool_destroy (mu_opool_t *popool);
 
+/* Allocate SIZE bytes in the pool. */
+int mu_opool_alloc (mu_opool_t opool, size_t size);
+
 /* Append to the current object N bytes pointed to by STR. */
 int mu_opool_append (mu_opool_t opool, const void *str, size_t n);
 
diff --git a/lib/mailcap.c b/lib/mailcap.c
index 4308785..8125da7 100644
--- a/lib/mailcap.c
+++ b/lib/mailcap.c
@@ -19,9 +19,6 @@
 #endif
 #include <mailutils/mailutils.h>
 #include <fnmatch.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>  
 #include <sys/wait.h>
 #include <ctype.h>
 
@@ -241,7 +238,7 @@ mime_context_get_temp_file (struct mime_context *ctx, char **ptr)
 }
 
 
-static struct obstack expand_stack;
+static mu_opool_t expand_pool;
 
 static int
 expand_string (struct mime_context *ct, char **pstr)
@@ -258,14 +255,14 @@ expand_string (struct mime_context *ct, char **pstr)
 	      {
 	      case 's':
 		mime_context_get_temp_file (ct, &s);
-		obstack_grow (&expand_stack, s, strlen (s));
+		mu_opool_appendz (expand_pool, s);
 		rc = 1;
 		p += 2;
 		break;
 		
 	      case 't':
 		mime_context_get_content_type (ct, &s);
-		obstack_grow (&expand_stack, s, strlen (s));
+		mu_opool_appendz (expand_pool, s);
 		p += 2;
 		break;
 		
@@ -281,7 +278,7 @@ expand_string (struct mime_context *ct, char **pstr)
 		  if (mime_context_get_content_type_value (ct,
 							   q, p-q,
 							   &s, &n) == 0)
-		    obstack_grow (&expand_stack, s, n);
+		    mu_opool_append (expand_pool, s, n);
 		  if (*p)
 		    p++;
 		  break;
@@ -293,19 +290,19 @@ expand_string (struct mime_context *ct, char **pstr)
 		break;
 		
 	      default:
-		obstack_1grow (&expand_stack, p[0]);
+		mu_opool_append_char (expand_pool, p[0]);
 	      }
 	    break;
 
 	case '\\':
 	  if (p[1])
 	    {
-	      obstack_1grow (&expand_stack, p[1]);
+	      mu_opool_append_char (expand_pool, p[1]);
 	      p += 2;
 	    }
 	  else
 	    {
-	      obstack_1grow (&expand_stack, p[0]);
+	      mu_opool_append_char (expand_pool, p[0]);
 	      p++;
 	    }
 	  break;
@@ -313,23 +310,23 @@ expand_string (struct mime_context *ct, char **pstr)
 	case '"':
 	  if (p[1] == p[0])
 	    {
-	      obstack_1grow (&expand_stack, '%');
+	      mu_opool_append_char (expand_pool, '%');
 	      p++;
 	    }
 	  else
 	    {
-	      obstack_1grow (&expand_stack, p[0]);
+	      mu_opool_append_char (expand_pool, p[0]);
 	      p++;
 	    }
 	  break;
 
 	default:
-	  obstack_1grow (&expand_stack, p[0]);
+	  mu_opool_append_char (expand_pool, p[0]);
 	  p++;
 	}
     }
-  obstack_1grow (&expand_stack, 0);
-  *pstr = obstack_finish (&expand_stack);
+  mu_opool_append_char (expand_pool, 0);
+  *pstr = mu_opool_finish (expand_pool, NULL);
   return rc;
 }
 
@@ -514,8 +511,8 @@ run_test (mu_mailcap_entry_t entry, struct mime_context *ctx)
       struct mu_wordsplit ws;
       char *str;
 
-      obstack_blank (&expand_stack, size + 1);
-      str = obstack_finish (&expand_stack);
+      mu_opool_alloc (expand_pool, size + 1);
+      str = mu_opool_finish (expand_pool, NULL);
       mu_mailcap_entry_get_test (entry, str, size + 1, NULL);
 
       expand_string (ctx, &str);
@@ -556,8 +553,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx)
       if (mu_mailcap_entry_get_viewcommand (entry, NULL, 0, &size))
 	return 1;
       size++;
-      obstack_blank (&expand_stack, size);
-      view_command = obstack_finish (&expand_stack);
+      mu_opool_alloc (expand_pool, size);
+      view_command = mu_opool_finish (expand_pool, NULL);
       mu_mailcap_entry_get_viewcommand (entry, view_command, size, NULL);
     }
   else
@@ -565,8 +562,8 @@ run_mailcap (mu_mailcap_entry_t entry, struct mime_context *ctx)
       if (mu_mailcap_entry_get_value (entry, "print", NULL, 0, &size))
 	return 1;
       size++;
-      obstack_blank (&expand_stack, size);
-      view_command = obstack_finish (&expand_stack);
+      mu_opool_alloc (expand_pool, size);
+      view_command = mu_opool_finish (expand_pool, NULL);
       mu_mailcap_entry_get_value (entry, "print", view_command, size, NULL);
     }
 
@@ -691,7 +688,7 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr,
       mailcap_path = mailcap_path_tmp;
     }
   
-  obstack_init (&expand_stack);
+  mu_opool_create (&expand_pool, 1);
 
   ws.ws_delim = ":";
   if (mu_wordsplit (mailcap_path, &ws,
@@ -712,7 +709,7 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr,
 	}
       mu_wordsplit_free (&ws);
     }
-  obstack_free (&expand_stack, NULL);
+  mu_opool_destroy (&expand_pool);
   free (mailcap_path_tmp);
   mime_context_release (&ctx);
   return rc;
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index 1d835a0..8e563d2 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -695,19 +695,17 @@ static int
 _amd_scan0 (struct _amd_data *amd, size_t msgno, size_t *pcount,
 	    int do_notify)
 {
+  unsigned long uidval;
   int status = amd->scan0 (amd->mailbox, msgno, pcount, do_notify);
   if (status != 0)
     return status;
   /* Reset the uidvalidity.  */
-  if (amd->msg_count > 0)
+  if (amd->msg_count == 0 ||
+      _amd_prop_fetch_ulong (amd, _MU_AMD_PROP_UIDVALIDITY, &uidval) ||
+      !uidval)
     {
-      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);
-	}
+      uidval = (unsigned long)time (NULL);
+      _amd_prop_store_off (amd, _MU_AMD_PROP_UIDVALIDITY, uidval);
     }
   return 0;
 }
@@ -1502,7 +1500,7 @@ amd_uidvalidity (mu_mailbox_t mailbox, unsigned long *puidvalidity)
   int status = amd_messages_count (mailbox, NULL);
   if (status != 0)
     return status;
-  /* If we did not start a scanning yet do it now.  */
+  /* If we did not start scanning yet do it now.  */
   if (amd->msg_count == 0)
     {
       status = _amd_scan0 (amd, 1, NULL, 0);
diff --git a/libmailutils/base/opool.c b/libmailutils/base/opool.c
index 27b9a94..51c8e91 100644
--- a/libmailutils/base/opool.c
+++ b/libmailutils/base/opool.c
@@ -168,6 +168,25 @@ mu_opool_destroy (mu_opool_t *popool)
 }
 
 int
+mu_opool_alloc (mu_opool_t opool, size_t size)
+{
+  while (size)
+    {
+      size_t rest;
+
+      if (!opool->head || opool->tail->level == opool->tail->size)
+	if (alloc_pool (opool, opool->bucket_size))
+	  return ENOMEM;
+      rest = opool->tail->size - opool->tail->level;
+      if (size < rest)
+	rest = size;
+      opool->tail->level += rest;
+      size -= rest;
+    }
+  return 0;
+}
+
+int
 mu_opool_append (mu_opool_t opool, const void *str, size_t n)
 {
   const char *ptr = str;
@@ -191,8 +210,7 @@ mu_opool_append_char (mu_opool_t opool, char c)
 int
 mu_opool_appendz (mu_opool_t opool, const char *str)
 {
-  return mu_opool_append (opool, str, strlen (str))
-         || mu_opool_append_char (opool, 0);
+  return mu_opool_append (opool, str, strlen (str));
 }
 
 size_t
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index 2b93136..55780a3 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -1475,6 +1475,7 @@ mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
     {
       mu_opool_clear (tree->pool);
       mu_opool_appendz (tree->pool, label);
+      mu_opool_append_char (tree->pool, 0);
       val.v.string = mu_opool_finish (tree->pool, NULL);
       np->label = config_value_dup (&val);
     }
diff --git a/libmailutils/url/urlstr.c b/libmailutils/url/urlstr.c
index 86e5250..1e2aecb 100644
--- a/libmailutils/url/urlstr.c
+++ b/libmailutils/url/urlstr.c
@@ -35,27 +35,27 @@ url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
     {
       int i;
       
-      mu_opool_append (pool, url->scheme, strlen (url->scheme));
+      mu_opool_appendz (pool, url->scheme);
       mu_opool_append (pool, "://", 3);
 
       if (url->flags & MU_URL_USER)
-	mu_opool_append (pool, url->user, strlen (url->user));
+	mu_opool_appendz (pool, 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));
+	  mu_opool_appendz (pool, 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));
+	  mu_opool_appendz (pool, url->host);
 	  if (url->flags & MU_URL_PORT)
 	    {
 	      mu_opool_append_char (pool, ':');
-	      mu_opool_append (pool, url->portstr, strlen (url->portstr));
+	      mu_opool_appendz (pool, url->portstr);
 	    }
 	}
       else if (url->flags & (MU_URL_USER|MU_URL_SECRET|MU_URL_AUTH))
@@ -65,7 +65,7 @@ url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
 	{
 	  if (url->flags & MU_URL_HOST)
 	    mu_opool_append_char (pool, '/');
-	  mu_opool_append (pool, url->path, strlen (url->path));
+	  mu_opool_appendz (pool, url->path);
 	}
       
       if (url->flags & MU_URL_PARAM)
@@ -93,7 +93,7 @@ url_reconstruct_to_pool (mu_url_t url, mu_opool_t pool)
     }
   else if (url->flags == MU_URL_PATH)
     {
-      mu_opool_append (pool, url->path, strlen (url->path));
+      mu_opool_appendz (pool, url->path);
       return 0;
     }
   return MU_ERR_URL_MISS_PARTS;
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 60c97a7..b6610a4 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -19,7 +19,9 @@ AM_YFLAGS=-vt
 INCLUDES = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@ 
 AM_CFLAGS = -DSITE_MAIL_RC=\"@SITE_MAIL_RC@\"
 
-bin_PROGRAMS = mail
+mailbindir=@MAILBINDIR@
+
+mailbin_PROGRAMS = mail
 
 mail_LDADD = \
  ${MU_APP_LIBRARIES}\
diff --git a/mh/burst.c b/mh/burst.c
index c07657f..c2848e5 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -17,9 +17,6 @@
 /* MH burst command */
 
 #include <mh.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
 
 static char doc[] = N_("GNU MH burst")"\v"
 N_("Options marked with `*' are not yet implemented.\n\
@@ -134,7 +131,7 @@ struct burst_map map;        /* Currently built map */
 struct burst_map *burst_map; /* Finished burst map */
 size_t burst_count;          /* Number of items in burst_map */
 mu_mailbox_t tmpbox;         /* Temporary mailbox */
-struct obstack stk;          /* Stack for building burst_map, etc. */
+mu_opool_t pool;             /* Object pool for building burst_map, etc. */
 
 static int burst_or_copy (mu_message_t msg, int recursive, int copy);
 
@@ -592,7 +589,7 @@ burst (size_t num, mu_message_t msg, void *data)
 	       mu_umaxtostr (1, num)));
       if (inplace)
 	{
-	  obstack_grow (&stk, &map, sizeof map);
+	  mu_opool_append (pool, &map, sizeof map);
 	  burst_count++;
 	}
     }
@@ -752,7 +749,7 @@ main (int argc, char **argv)
 	  mu_attribute_set_deleted (attr);
 	}
       mu_mailbox_expunge (tmpbox);
-      obstack_init (&stk);
+      mu_opool_create (&pool, 1);
     }
   else
     tmpbox = mbox;
@@ -769,7 +766,7 @@ main (int argc, char **argv)
       size_t count;
       const char *dir;
       
-      burst_map = obstack_finish (&stk);
+      burst_map = mu_opool_finish (pool, NULL);
 
       mu_mailbox_uidnext (mbox, &next_uid);
       for (i = 0, last_uid = next_uid-1; i < burst_count; i++)
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index ac67415..6dd0f2d 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -17,9 +17,6 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mh.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
 
 int yyerror (const char *s);
 int yylex ();
@@ -27,7 +24,7 @@ int yylex ();
 static mh_format_t format;     /* Format structure being built */
 static size_t pc;              /* Program counter. Poins to current
 				  cell in format.prog */
-static struct obstack stack;   /* Temporary token storage */
+static mu_opool_t tokpool;     /* Temporary token storage */
 
 #define FORMAT_INC 64          /* Increase format.prog by that many
 				  cells each time pc reaches
@@ -459,16 +456,16 @@ yylex ()
       if (*curp == '\\')
 	{
 	  int c = backslash (*++curp);
-	  obstack_1grow (&stack, c);
+	  mu_opool_append_char (tokpool, c);
 	}
       else
-	obstack_1grow (&stack, *curp);
+	mu_opool_append_char (tokpool, *curp);
       curp++;
     }
   while (*curp && (expect_arg ? *curp != ')' : !isdelim(*curp)));
 
-  obstack_1grow (&stack, 0);
-  yylval.str = obstack_finish (&stack);
+  mu_opool_append_char (tokpool, 0);
+  yylval.str = mu_opool_finish (tokpool, NULL);
 
   if (want_function)
     {
@@ -502,7 +499,7 @@ mh_format_parse (char *format_str, mh_format_t *fmt)
   if (p)
     yydebug = 1;
   start = curp = format_str;
-  obstack_init (&stack);
+  mu_opool_create (&tokpool, 1);
   format.prog = NULL;
   format.progsize = 0;
   pc = 0;
@@ -513,7 +510,7 @@ mh_format_parse (char *format_str, mh_format_t *fmt)
 
   rc = yyparse ();
   mh_code_op (mhop_stop);
-  obstack_free (&stack, NULL);
+  mu_opool_destroy (&tokpool);
   if (rc)
     {
       mh_format_free (&format);
diff --git a/mh/mh_format.c b/mh/mh_format.c
index fc51edf..ef5b957 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -190,7 +190,7 @@ put_string (struct mh_machine *mach, char *str, int len)
 {
   if (len == 0)
     return;
-  obstack_grow (&mach->stk, str, len);
+  mu_opool_append (mach->pool, str, len);
   len = mbsnwidth (str, len, 0);
   mach->ind += len;
 }
@@ -339,7 +339,7 @@ print_fmt_segment (struct mh_machine *mach, size_t fmtwidth, char *str,
       fmtwidth -= width;
       mach->ind += fmtwidth;
       while (fmtwidth--)
-	obstack_1grow (&mach->stk, ' ');
+	mu_opool_append_char (mach->pool, ' ');
     }
 }
 
@@ -394,7 +394,7 @@ format_num (struct mh_machine *mach, long num)
 	  ptr = buf;
 	  for (i = n; i < fmtwidth && mach->ind < mach->width;
 	       i++, mach->ind++)
-	    obstack_1grow (&mach->stk, padchar);
+	    mu_opool_append_char (mach->pool, padchar);
 	}
     }
   else
@@ -422,7 +422,7 @@ format_str (struct mh_machine *mach, char *str)
 	  n = fmtwidth - len;
 	  for (i = 0; i < n && mach->ind < mach->width;
 	       i++, mach->ind++, fmtwidth--)
-	    obstack_1grow (&mach->stk, padchar);
+	    mu_opool_append_char (mach->pool, padchar);
 	}
 	      
       print_fmt_string (mach, fmtwidth, str);
@@ -491,7 +491,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
   
   mach.width = width - 1; /* Count the newline */
   mach.pc = 1;
-  obstack_init (&mach.stk);
+  mu_opool_create (&mach.pool, 1);
   mu_list_create (&mach.addrlist);
   
   reset_fmt_defaults (&mach);
@@ -678,10 +678,10 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
   
   if (pret)
     {
-      obstack_1grow (&mach.stk, 0);
-      *pret = mu_strdup (obstack_finish (&mach.stk));
+      mu_opool_append_char (mach.pool, 0);
+      *pret = mu_strdup (mu_opool_finish (mach.pool, NULL));
     }
-  obstack_free (&mach.stk, NULL);
+  mu_opool_destroy (&mach.pool);
   return mach.ind;
 }
 
diff --git a/mh/mh_format.h b/mh/mh_format.h
index d2c6309..cff57a0 100644
--- a/mh/mh_format.h
+++ b/mh/mh_format.h
@@ -14,10 +14,6 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>
-
 typedef struct       /* A string object type */
 {
   int size;          /* Allocated size or 0 for static storage */
@@ -43,7 +39,7 @@ struct mh_machine
   mh_instr_t *prog;         /* Program itself */
   int stop;                 /* Stop execution immediately */
 
-  struct obstack stk;       /* Output buffer */
+  mu_opool_t pool;          /* Output buffer */
   size_t width;             /* Output buffer width */
   size_t ind;               /* Output buffer index */
 
diff --git a/mh/mhn.c b/mh/mhn.c
index e209f1f..3c18824 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -19,9 +19,6 @@
 #include <mh.h>
 #include <signal.h>
 #include <mailutils/mime.h>
-#define obstack_chunk_alloc mu_alloc
-#define obstack_chunk_free free
-#include <obstack.h>
 #include <setjmp.h>
 
 static char doc[] = N_("GNU MH mhn")"\v"
@@ -541,7 +538,7 @@ msg_part_format (msg_part_t p)
 }
 
 void
-msg_part_format_stk (struct obstack *stk, msg_part_t p)
+msg_part_format_pool (mu_opool_t pool, msg_part_t p)
 {
   int i;
   
@@ -551,11 +548,11 @@ msg_part_format_stk (struct obstack *stk, msg_part_t p)
       const char *buf;
   
       if (i > 1)
-	obstack_1grow (stk, '.');
+	mu_opool_append_char (pool, '.');
 
       buf = mu_umaxtostr (0, p->part[i]);
       len = strlen (buf);
-      obstack_grow (stk, buf, len);
+      mu_opool_append (pool, buf, len);
     }
 }
 
@@ -634,7 +631,7 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
   const char *p, *str;
   char *type, *subtype, **typeargv = NULL;
   int typeargc = 0;
-  struct obstack stk;
+  mu_opool_t pool;
 
   split_content (typestr, &type, &subtype);
   str = _mhn_profile_get ("compose", type, subtype, NULL);
@@ -647,7 +644,8 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
     %F  %f, and stdout is not redirected
     %s  subtype */
 
-  obstack_init (&stk);
+  mu_opool_create (&pool, 1);
+
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   
   if (*p == '|')
@@ -671,8 +669,8 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
 		  for (i = 0; i < typeargc; i++)
 		    {
 		      if (i > 0)
-			obstack_1grow (&stk, ' ');
-		      obstack_grow (&stk, typeargv[i], strlen (typeargv[i]));
+			mu_opool_append_char (pool, ' ');
+		      mu_opool_appendz (pool, typeargv[i]);
 		    }
 		}
 	      break;
@@ -682,36 +680,36 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
 	      *flags |= MHN_STDIN;
 	      /*FALLTHRU*/
 	    case 'f':
-	      obstack_grow (&stk, file, strlen (file));
+	      mu_opool_appendz (pool, file);
 	      break;
 	      
 	    case 's':
 	      /* subtype */
-	      obstack_grow (&stk, subtype, strlen (subtype));
+	      mu_opool_appendz (pool, subtype);
 	      break;
 	      
 	    default:
-	      obstack_1grow (&stk, *p);
+	      mu_opool_append_char (pool, *p);
 	      p++;
 	    }
 	}
       else
-	obstack_1grow (&stk, *p);
+	mu_opool_append_char (pool, *p);
     }
-  obstack_1grow (&stk, 0);
+  mu_opool_append_char (pool, 0);
 
   free (type);
   free (subtype);
   mu_argcv_free (typeargc, typeargv);
     
-  str = obstack_finish (&stk);
+  str = mu_opool_finish (pool, NULL);
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
     str = NULL;
   else
     str = mu_strdup (p);
 
-  obstack_free (&stk, NULL);
+  mu_opool_destroy (&pool);
   return (char*) str;
 }
 
@@ -767,7 +765,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 {
   const char *p, *str, *tmp;
   char *typestr, *type, *subtype, *typeargs;
-  struct obstack stk;
+  mu_opool_t pool;
   mu_header_t hdr;
   char *temp_cmd = NULL;
   int typeargc = 0;
@@ -827,7 +825,8 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
     %s  subtype
     %d  content description */
 
-  obstack_init (&stk);
+  mu_opool_create (&pool, 1);
+
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   
   if (*p == '|')
@@ -851,8 +850,8 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 		  for (i = 0; i < typeargc; i++)
 		    {
 		      if (i > 0)
-			obstack_1grow (&stk, ' ');
-		      obstack_grow (&stk, typeargv[i], strlen (typeargv[i]));
+			mu_opool_append_char (pool, ' ');
+		      mu_opool_appendz (pool, typeargv[i]);
 		    }
 		}
 	      break;
@@ -866,7 +865,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 	      /* filename containing content */
 	      if (!*tempfile)
 		mhn_tempfile_name (tempfile, type, subtype);
-	      obstack_grow (&stk, *tempfile, strlen (*tempfile));
+	      mu_opool_appendz (pool, *tempfile);
 	      break;
 				     
 	    case 'F':
@@ -874,7 +873,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 	      *flags |= MHN_STDIN|MHN_EXCLUSIVE_EXEC;
 	      if (!*tempfile)
 		mhn_tempfile_name (tempfile, type, subtype);
-	      obstack_grow (&stk, *tempfile, strlen (*tempfile));
+	      mu_opool_appendz (pool, *tempfile);
 	      break;
 	      
 	    case 'l':
@@ -889,25 +888,25 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
 	      
 	    case 's':
 	      /* subtype */
-	      obstack_grow (&stk, subtype, strlen (subtype));
+	      mu_opool_appendz (pool, subtype);
 	      break;
 	      
 	    case 'd':
 	      /* content description */
 	      if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
 					&tmp) == 0)
-		obstack_grow (&stk, tmp, strlen (tmp));
+		mu_opool_appendz (pool, tmp);
 	      break;
 	      
 	    default:
-	      obstack_1grow (&stk, *p);
+	      mu_opool_append_char (pool, *p);
 	      p++;
 	    }
 	}
       else
-	obstack_1grow (&stk, *p);
+	mu_opool_append_char (pool, *p);
     }
-  obstack_1grow (&stk, 0);
+  mu_opool_append_char (pool, 0);
 
   free (typestr);
   free (type);
@@ -915,14 +914,14 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
   free (temp_cmd);
   mu_argcv_free (typeargc, typeargv);
   
-  str = obstack_finish (&stk);
+  str = mu_opool_finish (pool, NULL);
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
     str = NULL;
   else
     str = mu_strdup (p);
 
-  obstack_free (&stk, NULL);
+  mu_opool_destroy (&pool);
   return (char*) str;
 }
 
@@ -941,7 +940,7 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
 {
   const char *p, *str, *tmp;
   char *typestr, *type, *subtype, *typeargs;
-  struct obstack stk;
+  mu_opool_t pool;
   mu_header_t hdr;
   enum store_destination dest;
   
@@ -998,7 +997,8 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
      %p  part
      %s  subtype */
 
-  obstack_init (&stk);
+  mu_opool_create (&pool, 1);
+  
   for (p = str; *p; p++)
     {
       if (*p == '%')
@@ -1007,62 +1007,62 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
 	    {
 	    case 'a':
 	      /* additional arguments */
-	      obstack_grow (&stk, typeargs, strlen (typeargs));
+	      mu_opool_appendz (pool, typeargs);
 	      break;
 
 	    case 'm':
 	      if (name)
-		obstack_grow (&stk, name, strlen (name));
+		mu_opool_appendz (pool, name);
 	      else
 		{
                   const char *buf = mu_umaxtostr (0, msg_part_subpart (part, 0));
-		  obstack_grow (&stk, buf, strlen (buf));
+		  mu_opool_appendz (pool, buf);
 		}
 	      break;
 
 	    case 'P':
 	      if (msg_part_level (part) >= 1)
-		obstack_1grow (&stk, '.');
+		mu_opool_append_char (pool, '.');
 	      /*FALLTHRU*/
 	    case 'p':
 	      if (msg_part_level (part) >= 1)
-		msg_part_format_stk (&stk, part);
+		msg_part_format_pool (pool, part);
 	      break;
 	      
 	    case 's':
 	      /* subtype */
-	      obstack_grow (&stk, subtype, strlen (subtype));
+	      mu_opool_appendz (pool, subtype);
 	      break;
 	      
 	    case 'd':
 	      /* content description */
 	      if (mu_header_sget_value (hdr, MU_HEADER_CONTENT_DESCRIPTION,
 				        &tmp) == 0)
-		obstack_grow (&stk, tmp, strlen (tmp));
+		mu_opool_appendz (pool, tmp);
 	      break;
 	      
 	    default:
-	      obstack_1grow (&stk, *p);
+	      mu_opool_append_char (pool, *p);
 	      p++;
 	    }
 	}
       else
-	obstack_1grow (&stk, *p);
+	mu_opool_append_char (pool, *p);
     }
-  obstack_1grow (&stk, *p);
+  mu_opool_append_char (pool, *p);
 
   free (typestr);
   free (type);
   free (subtype);
   
-  str = obstack_finish (&stk);
+  str = mu_opool_finish (pool, NULL);
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   if (!*p)
     *return_string = NULL;
   else
     *return_string = mu_strdup (p);
   
-  obstack_free (&stk, NULL);
+  mu_opool_destroy (&pool);
   return dest;
 }
 
@@ -1932,7 +1932,7 @@ parse_brace (char **pval, char **cmd, int c, struct compose_env *env)
 
 int
 parse_content_type (struct compose_env *env,
-		    struct obstack *stk, char **prest, char **id, char **descr)
+		    mu_opool_t pool, char **prest, char **id, char **descr)
 {
   int status = 0, stop = 0;
   char *rest = *prest;
@@ -1990,12 +1990,12 @@ parse_content_type (struct compose_env *env,
 	  break;
 
 	case ';':
-	  obstack_1grow (stk, ';');
-	  obstack_1grow (stk, ' ');
+	  mu_opool_append_char (pool, ';');
+	  mu_opool_append_char (pool, ' ');
 	  skipws (rest);
 	  sp = rest;
 	  for (; *rest && !mu_isspace (*rest) && *rest != '='; rest++)
-	    obstack_1grow (stk, *rest);
+	    mu_opool_append_char (pool, *rest);
 	  skipws (rest);
 	  if (*rest != '=')
 	    {
@@ -2006,13 +2006,13 @@ parse_content_type (struct compose_env *env,
 	      break;
 	    }
 	  rest++;
-	  obstack_1grow (stk, '=');
+	  mu_opool_append_char (pool, '=');
 	  skipws (rest);
 	  for (; *rest; rest++)
 	    {
 	      if (isdelim (*rest))
 		break;
-	      obstack_1grow (stk, *rest);
+	      mu_opool_append_char (pool, *rest);
 	    }
 	  break;
 	    
@@ -2025,9 +2025,9 @@ parse_content_type (struct compose_env *env,
 
   if (comment)
     {
-      obstack_grow (stk, " (", 2);
-      obstack_grow (stk, comment, strlen (comment));
-      obstack_1grow (stk, ')');
+      mu_opool_append (pool, " (", 2);
+      mu_opool_appendz (pool, comment);
+      mu_opool_append_char (pool, ')');
       free (comment);
     }
   *prest = rest;
@@ -2048,7 +2048,7 @@ parse_type_command (char **pcmd, struct compose_env *env, mu_header_t hdr)
   char *type = NULL;
   char *subtype = NULL;
   char *descr = NULL, *id = NULL;
-  struct obstack stk;
+  mu_opool_t pool;
   char *rest = *pcmd;
   
   skipws (rest);
@@ -2068,15 +2068,17 @@ parse_type_command (char **pcmd, struct compose_env *env, mu_header_t hdr)
       return 1;
     }
 
-  obstack_init (&stk);
-  obstack_grow (&stk, type, strlen (type));
-  obstack_1grow (&stk, '/');
-  obstack_grow (&stk, subtype, strlen (subtype));
-  status = parse_content_type (env, &stk, &rest, &id, &descr);
-  obstack_1grow (&stk, 0);
+  mu_opool_create (&pool, 1);
+
+  mu_opool_appendz (pool, type);
+  mu_opool_append_char (pool, '/');
+  mu_opool_appendz (pool, subtype);
+  status = parse_content_type (env, pool, &rest, &id, &descr);
+  mu_opool_append_char (pool, 0);
   
-  mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, obstack_finish (&stk), 1);
-  obstack_free (&stk, NULL);
+  mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE,
+		       mu_opool_finish (pool, NULL), 1);
+  mu_opool_destroy (&pool);
 
   if (!id)
     id = mh_create_message_id (env->subpart);
@@ -2217,7 +2219,7 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
   mu_header_t hdr, hdr2;
   mu_body_t body;
   mu_stream_t in, out = NULL;
-  struct obstack stk;
+  mu_opool_t pool;
 
   if (!*msg)
     mu_message_create (msg, NULL);
@@ -2234,13 +2236,14 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
 
   mu_message_get_header (*msg, &hdr);
 
-  obstack_init (&stk);
-  obstack_grow (&stk, EXTCONTENT, sizeof (EXTCONTENT) - 1);
+  mu_opool_create (&pool, 1);
+  mu_opool_append (pool, EXTCONTENT, sizeof (EXTCONTENT) - 1);
   *--rest = ';'; /* FIXME */
-  rc = parse_content_type (env, &stk, &rest, &id, NULL);
-  obstack_1grow (&stk, 0);
-  mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE, obstack_finish (&stk), 1);
-  obstack_free (&stk, NULL);
+  rc = parse_content_type (env, pool, &rest, &id, NULL);
+  mu_opool_append_char (pool, 0);
+  mu_header_set_value (hdr, MU_HEADER_CONTENT_TYPE,
+		       mu_opool_finish (pool, NULL), 1);
+  mu_opool_destroy (&pool);
   if (rc)
     return 1;
 
diff --git a/mh/repl.c b/mh/repl.c
index 901cc80..8500966 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -120,7 +120,7 @@ static char *mhl_filter = NULL; /* --filter flag */
 static int annotate;       /* --annotate flag */
 static char *draftmessage = "new";
 static const char *draftfolder = NULL;
-static struct obstack fcc_stack;
+static mu_opool_t fcc_pool;
 static int has_fcc;
 
 static int
@@ -243,12 +243,12 @@ opt_handler (int key, char *arg, struct argp_state *state)
     case ARG_FCC:
       if (!has_fcc)
 	{
-	  obstack_init (&fcc_stack);
+	  mu_opool_create (&fcc_pool, 1);
 	  has_fcc = 1;
 	}
       else
-	obstack_grow (&fcc_stack, ", ", 2);
-      obstack_grow (&fcc_stack, arg, strlen (arg));
+	mu_opool_append (fcc_pool, ", ", 2);
+      mu_opool_appendz (fcc_pool, arg);
       break;
 	  
     case ARG_INPLACE:
@@ -348,7 +348,7 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
 	  
 	  mu_message_create_copy (&tmp_msg, msg);
 	  mu_message_get_header (tmp_msg, &hdr);
-	  text = obstack_finish (&fcc_stack);
+	  text = mu_opool_finish (fcc_pool, NULL);
 	  mu_header_set_value (hdr, MU_HEADER_FCC, text, 0);
 	  mh_format (&format, tmp_msg, msgno, width, &buf);
 	  mu_message_destroy (&tmp_msg, NULL);
diff --git a/mh/whatnowenv.c b/mh/whatnowenv.c
index e8b6a0a..284e979 100644
--- a/mh/whatnowenv.c
+++ b/mh/whatnowenv.c
@@ -97,7 +97,7 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
 	  if (prev_uid == 0)
 	    {
 	      s = mu_umaxtostr (0, uid);
-	      mu_opool_append (opool, s, strlen (s));
+	      mu_opool_appendz (opool, s);
 	      mrange = 0;
 	    }
 	  else if (uid == prev_uid + 1)
@@ -108,11 +108,11 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
 		{
 		  mu_opool_append_char (opool, '-');
 		  s = mu_umaxtostr (0, prev_uid);
-		  mu_opool_append (opool, s, strlen (s));
+		  mu_opool_appendz (opool, s);
 		}
 	      mu_opool_append_char (opool, ' ');
 	      s = mu_umaxtostr (0, uid);
-	      mu_opool_append (opool, s, strlen (s));
+	      mu_opool_appendz (opool, s);
 	      mrange = 0;
 	    }
 	}
@@ -121,7 +121,7 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
 	{
 	  mu_opool_append_char (opool, '-');
 	  s = mu_umaxtostr (0, prev_uid);
-	  mu_opool_append (opool, s, strlen (s));
+	  mu_opool_appendz (opool, s);
 	}
       mu_opool_append_char (opool, 0);
       s = mu_opool_finish (opool, NULL);
diff --git a/mimeview/mimetypes.l b/mimeview/mimetypes.l
index e69ec33..02b7ddd 100644
--- a/mimeview/mimetypes.l
+++ b/mimeview/mimetypes.l
@@ -32,7 +32,7 @@ static int line_num;
 static char *file_name;
 static int file_name_alloc; 
  
-static struct obstack stack;
+static mu_opool_t pool;
 static int prev_state;
  
 static unsigned 
@@ -56,25 +56,22 @@ WS [ \t]*
 \n                   { line_num++; return EOL; }
 {WS}                 ;
 {IDENT}              {
-  obstack_grow (&stack, yytext, yyleng);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, yytext, yyleng);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   return IDENT;
 }
 <INITIAL>{IDENT}"("           {
-  obstack_grow (&stack, yytext, yyleng-1);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, yytext, yyleng-1);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   BEGIN(ARGS);
   return IDENT_L;
 }
 <INITIAL,ARGS>\"[^\\"\n]*\"        {
-  obstack_grow (&stack, yytext+1, yyleng-2);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, yytext+1, yyleng-2);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   return STRING;
 }
 <INITIAL,ARGS>"<" {
@@ -82,40 +79,36 @@ WS [ \t]*
   BEGIN(HEX);
 }
 <ARGS>[^ \t<\\\n),]+/[),] {
-  obstack_grow (&stack, yytext, yyleng);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, yytext, yyleng);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   return STRING;
 }
 <ARGS>[^ \t<\\\n),]+< {
-  obstack_grow (&stack, yytext, yyleng);
+  mu_opool_append (pool, yytext, yyleng);
   prev_state = YYSTATE;
   BEGIN(HEX);
 }
 <INITIAL>[^ \t<\\\n)+,&]/[ \t\\\n)+,&] {
-  obstack_grow (&stack, yytext, yyleng);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, yytext, yyleng);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   return STRING;
 }
 <ARGS>[^ \t<\\\n),]/[ \t\\\n] {
-  obstack_grow (&stack, yytext, yyleng);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, yytext, yyleng);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   return STRING;
 }
 <HEX>{X}{X} {
   int c = digit_to_number (yytext[0])*16 + digit_to_number (yytext[1]);
-  obstack_1grow (&stack, c);
+  mu_opool_append_char (pool, c);
 }
 <HEX>">"/[ \t\\\n,)] {
   BEGIN(prev_state);
-  yylval.string.len = obstack_object_size (&stack);
-  obstack_1grow (&stack, 0);
-  yylval.string.ptr = obstack_finish (&stack);
+  mu_opool_append_char (pool, 0);
+  yylval.string.ptr = mu_opool_finish (pool, &yylval.string.len);
   return STRING;
 }
 <HEX>">" {
@@ -174,7 +167,7 @@ mimetypes_open (const char *name)
       return -1;
     }
   line_num = 1;
-  obstack_init (&stack);
+  mu_opool_create (&pool, 1);
   return 0;
 }
 
@@ -210,25 +203,26 @@ mimetypes_append_string2 (struct mimetypes_string *s1,
   struct mimetypes_string r;
 
   r.len = s1->len + s2->len + 1;
-  obstack_grow (&stack, s1->ptr, s1->len);
-  obstack_1grow (&stack, c);
-  obstack_grow (&stack, s2->ptr, s2->len);
-  obstack_1grow (&stack, 0);
-  r.ptr = obstack_finish (&stack);
+  mu_opool_append (pool, s1->ptr, s1->len);
+  mu_opool_append_char (pool, c);
+  mu_opool_append (pool, s2->ptr, s2->len);
+  mu_opool_append_char (pool, 0);
+  r.ptr = mu_opool_finish (pool, NULL);
   return r;
 }
 
 struct mimetypes_string *     
 mimetypes_string_dup (struct mimetypes_string *s)
 {
-  obstack_grow (&stack, s, sizeof *s);
-  return obstack_finish (&stack);
+  mu_opool_append (pool, s, sizeof *s);
+  return mu_opool_finish (pool, NULL);
 }
 
 void *
 mimetypes_malloc (size_t size)
 {
-  return obstack_alloc(&stack, size);
+  mu_opool_alloc (pool, size);
+  return mu_opool_finish (pool, NULL);
 }
 
 void
diff --git a/mimeview/mimeview.h b/mimeview/mimeview.h
index 2c42866..ff01d67 100644
--- a/mimeview/mimeview.h
+++ b/mimeview/mimeview.h
@@ -22,9 +22,6 @@
 #endif
 #include <mailutils/mailutils.h>
 #include <fnmatch.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include <obstack.h>  
 
 struct mimetypes_string
 {
diff --git a/pop3d/apop.c b/pop3d/apop.c
index ee05080..7dc59ae 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -114,9 +114,9 @@ pop3d_apopuser (const char *user)
 #else /* !ENABLE_DBM */
   {
     char *buf = NULL;
-    size_t size = 0;
+    size_t size = 0, n;
     size_t ulen;
-    FILE *apop_file;
+    mu_stream_t apop_stream;
 
     rc = mu_file_safety_check (apop_database_name, apop_database_safety,
 			       apop_database_owner, NULL);
@@ -127,17 +127,19 @@ pop3d_apopuser (const char *user)
 			apop_database_name, mu_strerror (rc));
 	return NULL;
       }
-    apop_file = fopen (apop_database_name, "r");
-    if (apop_file == NULL)
+
+    rc = mu_file_stream_create (&apop_stream, apop_database_name,
+				MU_STREAM_READ);
+    if (rc)
       {
 	mu_diag_output (MU_DIAG_INFO,
 			_("unable to open APOP password file %s: %s"),
-			apop_database_name, mu_strerror (errno));
+			apop_database_name, mu_strerror (rc));
 	return NULL;
       }
-
+    
     ulen = strlen (user);
-    while (getline (&buf, &size, apop_file) > 0)
+    while (mu_stream_getline (apop_stream, &buf, &size, &n) == 0 && n > 0)
       {
 	char *p, *start = mu_str_stripws (buf);
 
@@ -154,8 +156,8 @@ pop3d_apopuser (const char *user)
 	    break;
 	  }
       }
-
-    fclose (apop_file);
+    free (buf);
+    mu_stream_unref (apop_stream);
     return password;
   }
 #endif


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Jul 17 15:50:22 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1SrDmo-0008Oa-Bb
	for mharc-commit-mailutils@gnu.org; Tue, 17 Jul 2012 15:50:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:54283)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrDmk-0008Nz-Ov
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 15:50:20 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrDme-0001qx-7b
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 15:50:18 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:56644)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrDme-0001qt-3q
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 15:50:12 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrDmd-0001hF-Ea
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 19:50:11 +0000
Date: Tue, 17 Jul 2012 19:50:11 +0000
Message-Id: <E1SrDmd-0001hF-Ea@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-618-g240e03b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 8658476839bcd6704ce51f470e14cf302b888f4a
X-Git-Newrev: 240e03b918f7e91f652e9c597b9af1fe644e8666
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, 17 Jul 2012 19:50:20 -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=240e03b918f7e91f652e9c597b9af1fe644e8666

The branch, master has been updated
       via  240e03b918f7e91f652e9c597b9af1fe644e8666 (commit)
       via  214c192f867191e3aa673c26676c00b574c2f584 (commit)
      from  8658476839bcd6704ce51f470e14cf302b888f4a (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 240e03b918f7e91f652e9c597b9af1fe644e8666
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Jul 17 22:46:35 2012 +0300

    Spelling fixes.

commit 214c192f867191e3aa673c26676c00b574c2f584
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Tue Jul 17 22:44:47 2012 +0300

    Upgrade imprimatur module.
    
    * doc/imprimatur: Upgrade.

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

Summary of changes:
 doc/imprimatur                |    2 +-
 imap4d/select.c               |    2 +-
 imap4d/tests/IDEF0955.at      |    2 +-
 imap4d/tests/IDEF0956.at      |    2 +-
 imap4d/tests/close-expunge.at |    4 ++--
 imap4d/tests/examine.at       |    2 +-
 imap4d/tests/expunge.at       |    2 +-
 imap4d/tests/select.at        |    2 +-
 8 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/doc/imprimatur b/doc/imprimatur
index f32ef19..04255b6 160000
--- a/doc/imprimatur
+++ b/doc/imprimatur
@@ -1 +1 @@
-Subproject commit f32ef1983968e755cd580b06e369476d7e7f88b6
+Subproject commit 04255b6d5551952b4e0c94da15988f573e3e9fc4
diff --git a/imap4d/select.c b/imap4d/select.c
index 54cd7cc..75f3c7f 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -137,7 +137,7 @@ imap4d_select_status ()
   io_untagged_response (RESP_OK, "[UIDNEXT %lu] Predicted next uid",
 	                   (unsigned long) uidnext);
   if (unseen)
-    io_untagged_response (RESP_OK, "[UNSEEN %lu] first unseen messsage",
+    io_untagged_response (RESP_OK, "[UNSEEN %lu] first unseen message",
 	                     (unsigned long) unseen);
   io_untagged_response (RESP_NONE, "FLAGS (%s)", mflags);
   /* FIXME:
diff --git a/imap4d/tests/IDEF0955.at b/imap4d/tests/IDEF0955.at
index 4e64665..18e6691 100644
--- a/imap4d/tests/IDEF0955.at
+++ b/imap4d/tests/IDEF0955.at
@@ -35,7 +35,7 @@ imap4d IMAP4D_OPTIONS < input | remove_uidvalidity | tr -d '\r'
 * 5 EXISTS
 * 5 RECENT
 * OK [[UIDNEXT 6]] Predicted next uid
-* OK [[UNSEEN 1]] first unseen messsage
+* OK [[UNSEEN 1]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)]] Permanent flags
 1 OK [[READ-WRITE]] SELECT Completed
diff --git a/imap4d/tests/IDEF0956.at b/imap4d/tests/IDEF0956.at
index 1bb2925..cdcc665 100644
--- a/imap4d/tests/IDEF0956.at
+++ b/imap4d/tests/IDEF0956.at
@@ -34,7 +34,7 @@ imap4d IMAP4D_OPTIONS < input | remove_uidvalidity | tr -d '\r'
 * 8 EXISTS
 * 5 RECENT
 * OK [[UIDNEXT 9]] Predicted next uid
-* OK [[UNSEEN 4]] first unseen messsage
+* OK [[UNSEEN 4]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)]] Permanent flags
 1 OK [[READ-WRITE]] SELECT Completed
diff --git a/imap4d/tests/close-expunge.at b/imap4d/tests/close-expunge.at
index 406fdf2..b2b0de9 100644
--- a/imap4d/tests/close-expunge.at
+++ b/imap4d/tests/close-expunge.at
@@ -33,7 +33,7 @@ X LOGOUT
 * 8 EXISTS
 * 5 RECENT
 * OK [[UIDNEXT 9]] Predicted next uid
-* OK [[UNSEEN 4]] first unseen messsage
+* OK [[UNSEEN 4]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)]] Permanent flags
 1 OK [[READ-WRITE]] SELECT Completed
@@ -41,7 +41,7 @@ X LOGOUT
 * 5 EXISTS
 * 0 RECENT
 * OK [[UIDNEXT 9]] Predicted next uid
-* OK [[UNSEEN 1]] first unseen messsage
+* OK [[UNSEEN 1]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS ()]] No permanent flags
 3 OK [[READ-ONLY]] EXAMINE Completed
diff --git a/imap4d/tests/examine.at b/imap4d/tests/examine.at
index 12d1483..746f995 100644
--- a/imap4d/tests/examine.at
+++ b/imap4d/tests/examine.at
@@ -26,7 +26,7 @@ X LOGOUT
 * 8 EXISTS
 * 5 RECENT
 * OK [[UIDNEXT 9]] Predicted next uid
-* OK [[UNSEEN 4]] first unseen messsage
+* OK [[UNSEEN 4]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS ()]] No permanent flags
 1 OK [[READ-ONLY]] EXAMINE Completed
diff --git a/imap4d/tests/expunge.at b/imap4d/tests/expunge.at
index 18a2bcf..f9249e7 100644
--- a/imap4d/tests/expunge.at
+++ b/imap4d/tests/expunge.at
@@ -28,7 +28,7 @@ X LOGOUT
 * 8 EXISTS
 * 5 RECENT
 * OK [[UIDNEXT 9]] Predicted next uid
-* OK [[UNSEEN 4]] first unseen messsage
+* OK [[UNSEEN 4]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)]] Permanent flags
 1 OK [[READ-WRITE]] SELECT Completed
diff --git a/imap4d/tests/select.at b/imap4d/tests/select.at
index 34c5929..cd90913 100644
--- a/imap4d/tests/select.at
+++ b/imap4d/tests/select.at
@@ -26,7 +26,7 @@ X LOGOUT
 * 8 EXISTS
 * 5 RECENT
 * OK [[UIDNEXT 9]] Predicted next uid
-* OK [[UNSEEN 4]] first unseen messsage
+* OK [[UNSEEN 4]] first unseen message
 * FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
 * OK [[PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft)]] Permanent flags
 1 OK [[READ-WRITE]] SELECT Completed


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Tue Jul 17 17:00:22 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1SrEsY-0003jr-Cd
	for mharc-commit-mailutils@gnu.org; Tue, 17 Jul 2012 17:00:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:58458)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrEsV-0003iq-1s
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 17:00:21 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrEsR-0003PI-B4
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 17:00:18 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:60509)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrEsR-0003P6-7I
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 17:00:15 -0400
Received: from polak by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrEsO-00052a-7Y
	for commit-mailutils@gnu.org; Tue, 17 Jul 2012 21:00:13 +0000
Date: Tue, 17 Jul 2012 21:00:13 +0000
Message-Id: <E1SrEsO-00052a-7Y@vcs.savannah.gnu.org>
From: "Wojciech Polak" <polak@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-619-gca45a7a
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 240e03b918f7e91f652e9c597b9af1fe644e8666
X-Git-Newrev: ca45a7aad841db4231bdd598e9a977a36dbf90c3
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, 17 Jul 2012 21:00: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=ca45a7aad841db4231bdd598e9a977a36dbf90c3

The branch, master has been updated
       via  ca45a7aad841db4231bdd598e9a977a36dbf90c3 (commit)
      from  240e03b918f7e91f652e9c597b9af1fe644e8666 (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 ca45a7aad841db4231bdd598e9a977a36dbf90c3
Author: Wojciech Polak <polak@gnu.org>
Date:   Tue Jul 17 22:52:34 2012 +0200

    Update C++ and Python interfaces.
    
    * include/mailutils/prog.h: Add extern "C".
    * include/mailutils/wordsplit.h: Likewise.
    * libmu_cpp/address.cc (Address::to_string): Use mu_address_sget_printable.
    * libmu_cpp/filter.cc (FilterIconvStream): Use mu_filter_create_args.
    * python/mailutils/folder.py (get_stream, set_stream): Remove.

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

Summary of changes:
 .gitignore                    |    2 ++
 examples/cpp/listop.cc        |   40 ++++++++++++++++++++++------------------
 examples/cpp/mimetest.cc      |    4 ++--
 examples/cpp/msg-send.cc      |    4 ++--
 include/mailutils/cpp/list.h  |    3 +--
 include/mailutils/prog.h      |    8 ++++++++
 include/mailutils/wordsplit.h |    7 +++++++
 libmu_cpp/address.cc          |    7 ++++---
 libmu_cpp/filter.cc           |   10 ++++++----
 libmu_cpp/list.cc             |    2 +-
 python/mailutils/folder.py    |   11 -----------
 11 files changed, 55 insertions(+), 43 deletions(-)

diff --git a/.gitignore b/.gitignore
index f99f881..a1b6218 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,8 @@
 *.la
 *.lo
 *.o
+*.pyc
+*.pyo
 *.so
 *~
 .bootstrap
diff --git a/examples/cpp/listop.cc b/examples/cpp/listop.cc
index 30af69f..fc39c4f 100644
--- a/examples/cpp/listop.cc
+++ b/examples/cpp/listop.cc
@@ -221,9 +221,10 @@ shell (List& lst)
     {
       char *text;
       char buf[80];
-      int argc;
-      char **argv;
-      
+      int wsflags = MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT;
+      struct mu_wordsplit ws;
+      ws.ws_comment = "#";
+
       try {
 	itr[num]->current ((void**) &text);
       }
@@ -235,40 +236,43 @@ shell (List& lst)
       if (cin.getline (buf, sizeof (buf)).eof ())
 	return;
 
-      rc = mu_argcv_get (buf, "", "#", &argc, &argv);
-      if (rc)
-	cerr << "mu_argcv_get: " << rc << endl;
+      if (mu_wordsplit (buf, &ws, wsflags))
+	{
+	  mu_error ("cannot split line `%s': %s", buf,
+		    mu_wordsplit_strerror (&ws));
+	  continue;
+	}
 
-      if (argc > 0)
+      if (ws.ws_wordc > 0)
 	{
-	  string cmd (argv[0]);
+	  string cmd (ws.ws_wordv[0]);
 
 	  if (cmd == "next")
-	    next (itr[num], argv[1]);
+	    next (itr[num], ws.ws_wordv[1]);
 	  else if (cmd == "first")
 	    itr[num]->first ();
 	  else if (cmd == "del")
-	    del (lst, argc, argv);
+	    del (lst, ws.ws_wordc, ws.ws_wordv);
 	  else if (cmd == "add")
-	    add (lst, argc, argv);
+	    add (lst, ws.ws_wordc, ws.ws_wordv);
 	  else if (cmd == "prep")
-	    prep (lst, argc, argv);
+	    prep (lst, ws.ws_wordc, ws.ws_wordv);
 	  else if (cmd == "repl")
-	    repl (lst, argc, argv);
+	    repl (lst, ws.ws_wordc, ws.ws_wordv);
 	  else if (cmd == "print")
 	    print (lst);
 	  else if (cmd == "quit")
 	    return;
 	  else if (cmd == "iter")
-	    iter (&num, argc, argv);
+	    iter (&num, ws.ws_wordc, ws.ws_wordv);
 	  else if (cmd == "find")
-	    find (itr[num], argv[1]);
+	    find (itr[num], ws.ws_wordv[1]);
 	  else if (cmd == "help")
 	    help ();
-	  else if (argc == 1)
+	  else if (ws.ws_wordc == 1)
 	    {
 	      char* p;
-	      size_t n = strtoul (argv[0], &p, 0);
+	      size_t n = strtoul (ws.ws_wordv[0], &p, 0);
 	      if (*p != 0)
 		cerr << "?" << endl;
 	      else
@@ -287,7 +291,7 @@ shell (List& lst)
 	  else
 	    cerr << "?" << endl;
 	}
-      mu_argcv_free (argc, argv);
+	mu_wordsplit_free (&ws);
     }
 }
 
diff --git a/examples/cpp/mimetest.cc b/examples/cpp/mimetest.cc
index 6d36320..0c1d465 100644
--- a/examples/cpp/mimetest.cc
+++ b/examples/cpp/mimetest.cc
@@ -75,8 +75,8 @@ main (int argc, char **argv)
   /* Debugging trace. */
   if (debug)
     {
-      Debug debug = mbox.get_debug ();
-      debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
+      mu_debug_set_category_level (MU_DEBCAT_MAILBOX, 
+				   MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
     }
 
   /* Open the mailbox for reading only. */
diff --git a/examples/cpp/msg-send.cc b/examples/cpp/msg-send.cc
index 71aa076..8e75270 100644
--- a/examples/cpp/msg-send.cc
+++ b/examples/cpp/msg-send.cc
@@ -95,8 +95,8 @@ main (int argc, char *argv[])
     Mailer mailer (optmailer);
     if (optdebug)
       {
-	Debug debug = mailer.get_debug ();
-	debug.set_level (MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
+	mu_debug_set_category_level (MU_DEBCAT_MAILER, 
+				     MU_DEBUG_LEVEL_UPTO (MU_DEBUG_PROT));
       }
     mailer.open ();
     mailer.send_message (msg, from, to);
diff --git a/include/mailutils/cpp/list.h b/include/mailutils/cpp/list.h
index 8bb6adc..a7e2068 100644
--- a/include/mailutils/cpp/list.h
+++ b/include/mailutils/cpp/list.h
@@ -25,7 +25,6 @@
 #include <mailutils/cpp/error.h>
 #include <mailutils/cpp/iterator.h>
 
-typedef int mu_list_action_t (void*, void*);
 typedef int (*mu_list_comparator_t) (const void*, const void*);
 
 namespace mailutils
@@ -64,7 +63,7 @@ class List
   void to_array (void** array, size_t count, size_t* pcount);
   void locate (void* item, void** ret_item);
 
-  void apply (mu_list_action_t* action, void* cbdata);
+  void apply (mu_list_action_t action, void* cbdata);
   mu_list_comparator_t set_comparator (mu_list_comparator_t comp);
   mu_list_destroy_item_t set_destroy_item (mu_list_destroy_item_t mu_destroy_item);
 
diff --git a/include/mailutils/prog.h b/include/mailutils/prog.h
index 77cd6e1..89d9a3e 100644
--- a/include/mailutils/prog.h
+++ b/include/mailutils/prog.h
@@ -21,6 +21,10 @@
 #include <sys/resource.h>
 #include <mailutils/types.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define MU_PROG_LIMIT_AS      0
 #define MU_PROG_LIMIT_CPU     1
 #define MU_PROG_LIMIT_DATA    2
@@ -66,5 +70,9 @@ int mu_prog_stream_create (mu_stream_t *pstream,
 int mu_command_stream_create (mu_stream_t *pstream, const char *command,
 			      int flags);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
 
diff --git a/include/mailutils/wordsplit.h b/include/mailutils/wordsplit.h
index 2538da6..5da3803 100644
--- a/include/mailutils/wordsplit.h
+++ b/include/mailutils/wordsplit.h
@@ -19,6 +19,10 @@
 
 #include <stddef.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 struct mu_wordsplit
 {
   size_t ws_wordc;
@@ -155,5 +159,8 @@ void mu_wordsplit_c_quote_copy (char *dst, const char *src, int quote_hex);
 void mu_wordsplit_perror (struct mu_wordsplit *ws);
 const char *mu_wordsplit_strerror (struct mu_wordsplit *ws);
 
+#ifdef __cplusplus
+}
+#endif
 
 #endif
diff --git a/libmu_cpp/address.cc b/libmu_cpp/address.cc
index 9bd08f3..ba2d695 100644
--- a/libmu_cpp/address.cc
+++ b/libmu_cpp/address.cc
@@ -172,12 +172,13 @@ std::string
 Address :: to_string ()
 {
   size_t n;
-  char buf[1024];
-  int status = mu_address_to_string (addr, buf, sizeof (buf), &n);
+  char const *sptr;
+
+  int status = mu_address_sget_printable (addr, &sptr);
   if (status)
     throw Exception ("Address::to_string", status);
 
-  return std::string (buf);
+  return std::string (sptr);
 }
 
 namespace mailutils
diff --git a/libmu_cpp/filter.cc b/libmu_cpp/filter.cc
index 821cd8f..ef97505 100644
--- a/libmu_cpp/filter.cc
+++ b/libmu_cpp/filter.cc
@@ -47,10 +47,12 @@ FilterIconvStream :: FilterIconvStream (Stream& transport,
 					int flags,
 					enum mu_iconv_fallback_mode fm)
 {
-  int status = mu_filter_iconv_create (&this->stm, transport.stm,
-				       fromcode.c_str (),
-				       tocode.c_str (),
-				       flags, fm);
+  const char *argv[4] = { "iconv", NULL, NULL, NULL };
+  argv[1] = fromcode.c_str ();
+  argv[2] = tocode.c_str ();
+
+  int status = mu_filter_create_args (&this->stm, transport.stm, argv[0], 3,
+				      argv, MU_FILTER_DECODE, flags);
   if (status)
     throw Exception ("FilterIconvStream::FilterIconvStream", status);
   this->input = new Stream (transport);
diff --git a/libmu_cpp/list.cc b/libmu_cpp/list.cc
index d341a1c..0e4c0e0 100644
--- a/libmu_cpp/list.cc
+++ b/libmu_cpp/list.cc
@@ -199,7 +199,7 @@ List :: size ()
 }
 
 void
-List :: apply (mu_list_action_t* action, void* cbdata)
+List :: apply (mu_list_action_t action, void* cbdata)
 {
   int status = mu_list_foreach (mu_list, action, cbdata);
   if (status)
diff --git a/python/mailutils/folder.py b/python/mailutils/folder.py
index 07dc76e..ed98fa4 100644
--- a/python/mailutils/folder.py
+++ b/python/mailutils/folder.py
@@ -49,17 +49,6 @@ class Folder:
         if status:
             raise FolderError (status)
 
-    def get_stream (self):
-        status, stream = folder.get_stream (self.folder)
-        if status:
-            raise FolderError (status)
-        return stream.Stream (stm)
-
-    def set_stream (self, stream):
-        status = folder.set_stream (self.folder, stream.stm)
-        if status:
-            raise FolderError (status)
-
     def get_authority (self):
         status, authority = folder.get_authority (self.folder)
         if status:


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Jul 18 16:16:58 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1Srag6-0003n4-UZ
	for mharc-commit-mailutils@gnu.org; Wed, 18 Jul 2012 16:16:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:59650)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Srag2-0003mn-FN
	for commit-mailutils@gnu.org; Wed, 18 Jul 2012 16:16:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Srafz-0001lv-RL
	for commit-mailutils@gnu.org; Wed, 18 Jul 2012 16:16:54 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:37437)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Srafz-0001lp-Ne
	for commit-mailutils@gnu.org; Wed, 18 Jul 2012 16:16:51 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1Srafx-0007cK-9O
	for commit-mailutils@gnu.org; Wed, 18 Jul 2012 20:16:51 +0000
Date: Wed, 18 Jul 2012 20:16:50 +0000
Message-Id: <E1Srafx-0007cK-9O@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-620-g8ad4747
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: ca45a7aad841db4231bdd598e9a977a36dbf90c3
X-Git-Newrev: 8ad474712f6758cdff637c5391867706957dfd74
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: Wed, 18 Jul 2012 20:16:57 -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=8ad474712f6758cdff637c5391867706957dfd74

The branch, master has been updated
       via  8ad474712f6758cdff637c5391867706957dfd74 (commit)
      from  ca45a7aad841db4231bdd598e9a977a36dbf90c3 (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 8ad474712f6758cdff637c5391867706957dfd74
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Jul 18 23:02:14 2012 +0300

    Implement --attach option in mail; fix dead.letter functionality
    
    * NEWS: Update.
    * doc/imprimatur: Upgrade.
    * libmailutils/mime/attachment.c (mu_message_create_attachment): Bugfixes.
    * mail/mail.c: New options --attach, --content-type and
    --encoding.
    * mail/mail.h (default_encoding, default_content_type): New externs.
    (send_attach_file): New proto.
    * mail/send.c (send_attach_file): New function.
    (save_dead_message_env): New function.
    (save_dead_message): Rewrite.
    (mail_send0): Attach files, if requested.

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

Summary of changes:
 NEWS                           |   42 +++++-
 doc/imprimatur                 |    2 +-
 libmailutils/mime/attachment.c |    9 +-
 mail/mail.c                    |   26 +++-
 mail/mail.h                    |    3 +
 mail/send.c                    |  356 +++++++++++++++++++++++++++++++++++++---
 6 files changed, 409 insertions(+), 29 deletions(-)

diff --git a/NEWS b/NEWS
index 4017176..8cac522 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2012-06-07
+GNU mailutils NEWS -- history of user-visible changes. 2012-07-18
 Copyright (C) 2002-2012 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
@@ -82,7 +82,7 @@ are not used to avoid compromising security.
 
 See <http://mailutils.org/wiki/debug_level>.
 
-** Imap4d undergone a lot of changes to comply to existing RFCs
+** Imap4d underwent a lot of changes to comply to existing RFCs
 
 ** Pop3d and imap4d allow for mailbox-independent compulsory locking
 
@@ -114,6 +114,27 @@ header field with the given date.
 
 See <http://mailutils.org/wiki/Timestamp_(Sieve_test)>.
 
+** mail: sending attachments
+
+The mail[x] utility now allows for sending attachments.  Any number of
+files can be attached to the composed letter by using the `--attach'
+(`-A') options.  The files will be attached in the same order in which
+they appear in the command line.  By default, each attachment is
+assigned the content type "application/octet-stream" and is encoded
+using Base64.  This can be changed using the `--content-type' and
+`--encoding' options.  These options affect all attachments that
+appear after them in the command line, until next occurrence of the
+same option or end of command line, whichever occurs first.  For
+example:
+
+  mail -A prog --encoding quoted-printable --content-type text/c \
+       -A main.c -A ext.h
+
+Here, the file "prog" will be attached witg the content type
+"application/octet-stream" and encoding base64, while the files
+"main.c" and "ext.h" will be marked with content type "text/c" and
+encoded using "quoted-printable" algorithm.
+
 ** MH: improved compatibility with other implementations
 
 ** MH inc: new option --moveto
@@ -181,12 +202,29 @@ imap4d, pop3d, comsat) will be built.  Its counterpart,
 `--enable-build-clients' controls whether client utilities will be
 built.
 
+The effect of both options is overridden by the `--enable-build-*'
+options for particular components.  For example, to build only
+the "mail" utility:
+
+  ./configure --disable-build-clients --enable-build-mail
+
+** The --with-mailbindir option
+
+This option changes installation directory for the "mail" utility.
+  
 ** DBM options
 
 It is normally not needed to specify --with-gdbm, --with-berkeley-db
 or --with-ndbm explicitly.  Configuration will automatically pick up
 all available DBM libraries it can use.
 
+The option `--with-dbm' can be used to enable or disable building of
+all available DBM interfaces.  Its effect is overridden by `--with-*'
+options for particular interfaces.  For example, to build only GDBM
+(even if another databases are supported by the system):
+
+  ./configure --without-dbm --with-gdbm
+
 ** Nntp client is not yet implemented
 
 ** Link with GSASL by default
diff --git a/doc/imprimatur b/doc/imprimatur
index 04255b6..f32ef19 160000
--- a/doc/imprimatur
+++ b/doc/imprimatur
@@ -1 +1 @@
-Subproject commit 04255b6d5551952b4e0c94da15988f573e3e9fc4
+Subproject commit f32ef1983968e755cd580b06e369476d7e7f88b6
diff --git a/libmailutils/mime/attachment.c b/libmailutils/mime/attachment.c
index ff160da..b55e93d 100644
--- a/libmailutils/mime/attachment.c
+++ b/libmailutils/mime/attachment.c
@@ -88,12 +88,15 @@ mu_message_create_attachment (const char *content_type, const char *encoding,
 			     "Content-Transfer-Encoding: %s\n"
 			     "Content-Disposition: attachment; filename=%s\n\n",
 			     content_type, name, encoding, name);
-	  if (ret)
+	  if (ret == 0)
 	    {
 	      if ((ret = mu_header_create (&hdr, header,
 					   strlen (header))) == 0)
 		{
+		  mu_stream_t bstr;
 		  mu_message_get_body (*newmsg, &body);
+		  mu_body_get_streamref (body, &bstr);
+		  
 		  if ((ret = mu_file_stream_create (&fstream, filename,
 						    MU_STREAM_READ)) == 0)
 		    {
@@ -101,10 +104,12 @@ mu_message_create_attachment (const char *content_type, const char *encoding,
 						   MU_FILTER_ENCODE,
 						   MU_STREAM_READ)) == 0)
 			{
-			  mu_body_set_stream (body, tstream, *newmsg);
+			  mu_stream_copy (bstr, tstream, 0, NULL);
+			  mu_stream_unref (tstream);
 			  mu_message_set_header (*newmsg, hdr, NULL);
 			}
 		    }
+		  mu_stream_unref (bstr);
 		  free (header);
 		}
 	    }
diff --git a/mail/mail.c b/mail/mail.c
index 045745c..e2eb63d 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -31,7 +31,9 @@ static char doc[] = N_("GNU mail -- process mail messages.\n"
 "by the first argument, or the user's mbox, if no argument given.\n");
 static char args_doc[] = N_("[address...]\n-f [OPTION...] [file]\n--file [OPTION...] [file]\n--file=file [OPTION...]");
 
-#define F_OPTION 256
+#define F_OPTION       256
+#define F_ENCODING     257
+#define F_CONTENT_TYPE 258
 
 static struct argp_option options[] = {
   { NULL,     'f', NULL,      OPTION_HIDDEN, NULL, 0 },
@@ -57,6 +59,12 @@ static struct argp_option options[] = {
    N_("append given header to the message being sent"), 0},
   {"exec",    'E', N_("COMMAND"), 0,
    N_("execute COMMAND"), 0 },
+  {"encoding", F_ENCODING, N_("NAME"), 0,
+   N_("set encoding for subsequent --attach options"), 0 },
+  {"content-type", F_CONTENT_TYPE, N_("TYPE"), 0,
+   N_("set content type for subsequent --attach options"), 0 },
+  {"attach",  'A', N_("FILE"), 0,
+   N_("attach FILE"), 0 },
   { NULL,      0, NULL, 0, NULL, 0 }
 };
 
@@ -84,6 +92,17 @@ parse_opt (int key, char *arg, struct argp_state *state)
       args->hint |= HINT_SEND_MODE;
       send_append_header (arg);
       break;
+
+    case 'A':
+      args->hint |= HINT_SEND_MODE;
+      if (send_attach_file (arg))
+	exit (1);
+      break;
+      
+    case F_CONTENT_TYPE:
+      free (default_content_type);
+      default_content_type = mu_strdup (arg);
+      break;
       
     case 'e':
       util_cache_command (&command_list, "setq mode=exist");
@@ -139,6 +158,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
     case 'E':
       util_cache_command (&command_list, "%s", arg);
       break;
+
+    case F_ENCODING:
+      free (default_encoding);
+      default_encoding = mu_strdup (arg);
+      break;
       
     case 'F':
       util_cache_command (&command_list, "set byname");
diff --git a/mail/mail.h b/mail/mail.h
index 2dbe8d1..c116b1b 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -171,6 +171,8 @@ extern mu_mailbox_t mbox;
 extern size_t total;
 extern int interactive;
 extern const char *program_version;
+extern char *default_encoding;
+extern char *default_content_type;
 
 /* Functions */
 extern int mail_alias (int argc, char **argv);
@@ -256,6 +258,7 @@ extern char *mail_expand_name (const char *name);
 
 extern void send_append_header (char *text);
 extern void send_append_header2 (char *name, char *value, int mode);
+extern int send_attach_file (const char *name);
 
 extern int escape_shell (int argc, char **argv, compose_env_t *env);
 extern int escape_command (int argc, char **argv, compose_env_t *env);
diff --git a/mail/send.c b/mail/send.c
index 4d2ce20..3b8d446 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -15,6 +15,7 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
+#include <mailutils/mime.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -128,6 +129,233 @@ mail_sendheader (int argc, char **argv)
     }
   return 0;
 }
+
+/* Attachments */
+struct atchinfo
+{
+  char *encoding;
+  char *content_type;
+  char *filename;
+};
+
+static mu_list_t attlist;
+
+char *default_encoding;
+char *default_content_type;
+
+static void
+atchinfo_free (void *p)
+{
+  struct atchinfo *ap = p;
+  free (ap->encoding);
+  free (ap->content_type);
+  free (ap->filename);
+  free (ap);
+}
+
+int
+send_attach_file (const char *name)
+{
+  int rc;
+  struct stat st;
+  struct atchinfo *aptr;
+  
+  if (stat (name, &st))
+    {
+      if (errno == ENOENT)
+	{
+	  mu_error (_("%s: file does not exist"), name);
+	  return 1;
+	}
+      else
+	{
+	  mu_error (_("%s: cannot stat: %s"), name, mu_strerror (errno));
+	  return 1;
+	}
+    }
+
+  if (!S_ISREG (st.st_mode))
+    {
+      mu_error (_("%s: not a regular file"), name);
+      return 1;
+    }
+
+  if (!attlist)
+    {
+      rc = mu_list_create (&attlist);
+      if (rc)
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_list_create", NULL, rc);
+	  exit (1);
+	}
+      mu_list_set_destroy_item (attlist, atchinfo_free);
+    }
+  aptr = mu_alloc (sizeof (*aptr));
+  aptr->encoding = mu_strdup (default_encoding ?
+			      default_encoding : "base64");
+  aptr->content_type = mu_strdup (default_content_type ?
+				  default_content_type :
+				    "application/octet-stream");
+  aptr->filename = mu_strdup (name);
+  rc = mu_list_append (attlist, aptr);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc);
+      exit (1);
+    }
+  return 0;
+}
+
+static int
+saveatt (void *item, void *data)
+{
+  struct atchinfo *aptr = item;
+  mu_mime_t mime = data;
+  mu_message_t part;
+  mu_header_t hdr;
+  int rc;
+  size_t nparts;
+  char *p;
+  
+  rc = mu_message_create_attachment (aptr->content_type, aptr->encoding,
+				     aptr->filename, &part);
+  if (rc)
+    {
+      mu_error (_("cannot attach \"%s\": %s"), aptr->filename,
+		mu_strerror (rc));
+      return 1;
+    }
+
+  mu_mime_get_num_parts	(mime, &nparts);
+  mu_message_get_header (part, &hdr);
+  mu_rfc2822_msg_id (nparts, &p);
+  mu_header_set_value (hdr, MU_HEADER_CONTENT_ID, p, 1);
+  free (p);
+
+  rc = mu_mime_add_part (mime, part);
+  mu_message_unref (part);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mime_add_part", aptr->filename, rc);
+      return 1;
+    }
+
+  return 0;
+}
+
+static int
+add_attachments (mu_message_t *pmsg, mu_mime_t *pmime)
+{
+  mu_message_t inmsg, outmsg, part;
+  mu_body_t body;
+  mu_header_t inhdr, outhdr;
+  mu_iterator_t itr;
+  mu_mime_t mime;
+  mu_stream_t str, output;
+  int rc;
+  char *p;
+  
+  if (mu_list_is_empty (attlist))
+    {
+      *pmime = NULL;
+      return 0;
+    }
+  
+  inmsg = *pmsg;
+
+  /* Create a mime object */
+  rc = mu_mime_create (&mime, NULL, 0);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mime_create", NULL, rc);
+      return 1;
+    }
+
+  /* Add original message as its first part */
+  /* 1. Create the part and obtain a reference to its stream */
+  mu_message_create (&part, NULL);
+  mu_message_get_body (part, &body);
+  mu_body_get_streamref (body, &output);
+
+  /* 2. Get original body stream and copy it out to the part's body */
+  mu_message_get_body (inmsg, &body);
+  mu_body_get_streamref (body, &str);
+  mu_stream_copy (output, str, 0, NULL);
+
+  mu_stream_close (output);
+  mu_stream_destroy (&output);
+
+  mu_message_get_header (inmsg, &inhdr);
+  mu_header_get_iterator (inhdr, &itr);
+
+  /* 3. Copy "Content-*" headers from the original message */
+  mu_message_get_header (part, &outhdr);
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name, *value;
+      
+      if (mu_iterator_current_kv (itr, (const void **)&name,
+				  (void**)&value) == 0)
+	{
+	  if (mu_c_strncasecmp (name, "Content-", 8) == 0)
+	    mu_header_set_value (outhdr, name, value, 0);
+	}
+    }
+  
+  /* 4. Add the content type and content ID headers. */
+  mu_header_set_value (outhdr, MU_HEADER_CONTENT_TYPE, "text/plain", 0);
+  mu_rfc2822_msg_id (0, &p);
+  mu_header_set_value (outhdr, MU_HEADER_CONTENT_ID, p, 1);
+  free (p);
+
+  /* 5. Add part to the mime object */
+  mu_mime_add_part (mime, part);
+  mu_message_unref (part);
+
+  /* Add the respective attachments */
+  rc = mu_list_foreach (attlist, saveatt, mime);
+  if (rc)
+    {
+      mu_mime_destroy (&mime);
+      return 1;
+    }
+
+  /* Get the resulting message */
+  rc = mu_mime_get_message (mime, &outmsg);
+
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_mime_get_message", NULL, rc);
+      mu_mime_destroy (&mime);
+      return 1;
+    }
+
+  /* Copy rest of headers from the original message */
+  mu_message_get_header (outmsg, &outhdr);
+  for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
+       mu_iterator_next (itr))
+    {
+      const char *name, *value;
+      
+      if (mu_iterator_current_kv (itr, (const void **)&name,
+				  (void**)&value) == 0)
+	{
+	  if (mu_c_strcasecmp (name, MU_HEADER_MIME_VERSION) == 0 ||
+	      mu_c_strncasecmp (name, "Content-", 8) == 0)
+	    continue;
+	  mu_header_append (outhdr, name, value);
+	}
+    }
+  mu_iterator_destroy (&itr);
+
+  mu_message_unref (outmsg);
+  mu_message_unref (inmsg);
+  *pmsg = outmsg;
+  *pmime = mime;
+  return 0;
+}
+
 
 
 /* Send-related commands */
@@ -342,17 +570,21 @@ fill_body (mu_message_t msg, mu_stream_t instr)
 }
 
 static int
-save_dead_message (compose_env_t *env)
+save_dead_message_env (compose_env_t *env)
 {
   if (mailvar_get (NULL, "save", mailvar_type_boolean, 0) == 0)
     {
-      mu_stream_t dead_letter;
+      mu_stream_t dead_letter, str;
       int rc;
+      time_t t;
+      struct tm *tm;
       const char *name = getenv ("DEAD");
-
+      char *sender;
+      
       /* FIXME: Use MU_STREAM_APPEND if appenddeadletter, instead of the
 	 stream manipulations below */
-      rc = mu_file_stream_create (&dead_letter, name, MU_STREAM_WRITE);
+      rc = mu_file_stream_create (&dead_letter, name,
+				  MU_STREAM_CREAT|MU_STREAM_WRITE);
       if (rc)
 	{
 	  mu_error (_("Cannot open file %s: %s"), name, strerror (rc));
@@ -364,8 +596,73 @@ save_dead_message (compose_env_t *env)
       else
 	mu_stream_truncate (dead_letter, 0);
 
+      time (&t);
+      tm = gmtime (&t);
+      sender = mu_get_user_email (NULL);
+      if (!sender)
+	sender = mu_strdup ("UNKNOWN");
+      mu_stream_printf (dead_letter, "From %s ", sender);
+      free (sender);
+      mu_c_streamftime (dead_letter, "%c%n", tm, NULL);
+
+      if (mu_header_get_streamref (env->header, &str) == 0)
+	{
+	  mu_stream_copy (dead_letter, str, 0, NULL);
+	  mu_stream_unref (str);
+	}
+      else
+	mu_stream_write (dead_letter, "\n", 1, NULL);
+      
       mu_stream_seek (env->compstr, 0, MU_SEEK_SET, NULL);
       mu_stream_copy (dead_letter, env->compstr, 0, NULL);
+      mu_stream_write (dead_letter, "\n", 1, NULL);
+      mu_stream_destroy (&dead_letter);
+    }
+  return 0;
+}
+
+static int
+save_dead_message (mu_message_t msg)
+{
+  if (mailvar_get (NULL, "save", mailvar_type_boolean, 0) == 0)
+    {
+      mu_stream_t dead_letter, str;
+      int rc;
+      time_t t;
+      struct tm *tm;
+      const char *name = getenv ("DEAD");
+      char *sender;
+      
+      /* FIXME: Use MU_STREAM_APPEND if appenddeadletter, instead of the
+	 stream manipulations below */
+      rc = mu_file_stream_create (&dead_letter, name,
+				  MU_STREAM_CREAT|MU_STREAM_WRITE);
+      if (rc)
+	{
+	  mu_error (_("Cannot open file %s: %s"), name, strerror (rc));
+	  return 1;
+	}
+      if (mailvar_get (NULL, "appenddeadletter",
+		       mailvar_type_boolean, 0) == 0)
+	mu_stream_seek (dead_letter, 0, MU_SEEK_END, NULL);
+      else
+	mu_stream_truncate (dead_letter, 0);
+
+      time (&t);
+      tm = gmtime (&t);
+      sender = mu_get_user_email (NULL);
+      if (!sender)
+	sender = mu_strdup ("UNKNOWN");
+      mu_stream_printf (dead_letter, "From %s ", sender);
+      free (sender);
+      mu_c_streamftime (dead_letter, "%c%n", tm, NULL);
+
+      if (mu_message_get_streamref (msg, &str) == 0)
+	{
+	  mu_stream_copy (dead_letter, str, 0, NULL);
+	  mu_stream_unref (str);
+	}
+      mu_stream_write (dead_letter, "\n", 1, NULL);
       mu_stream_destroy (&dead_letter);
     }
   return 0;
@@ -445,6 +742,7 @@ mail_send0 (compose_env_t *env, int save_to)
   if (rc)
     {
       mu_error (_("Cannot open temporary file: %s"), mu_strerror (rc));
+      mu_list_destroy (&attlist);
       return 1;
     }
 
@@ -541,8 +839,9 @@ mail_send0 (compose_env_t *env, int save_to)
   /* If interrupted, dump the file to dead.letter.  */
   if (int_cnt)
     {
-      save_dead_message (env);
+      save_dead_message_env (env);
       mu_stream_destroy (&env->compstr);
+      mu_list_destroy (&attlist);
       return 1;
     }
 
@@ -558,18 +857,30 @@ mail_send0 (compose_env_t *env, int save_to)
 
   if (util_header_expand (&env->header) == 0)
     {
+      mu_mime_t mime = NULL;
       mu_message_t msg = NULL;
-      int rc;
       int status = 0;
-      
-      mu_message_create (&msg, NULL);
-      
-      /* Fill the body.  */
-      mu_stream_seek (env->compstr, 0, MU_SEEK_SET, NULL);
-      rc = fill_body (msg, env->compstr);
-
-      if (rc == 0)
+      int sendit = (compose_header_get (env, MU_HEADER_TO, NULL) ||
+		    compose_header_get (env, MU_HEADER_CC, NULL) ||
+		    compose_header_get (env, MU_HEADER_BCC, NULL));
+      do
 	{
+	  status = mu_message_create (&msg, NULL);
+	  if (status)
+	    break;
+	  /* Fill the body. */
+	  mu_stream_seek (env->compstr, 0, MU_SEEK_SET, NULL);
+	  status = fill_body (msg, env->compstr);
+	  if (status)
+	    break;
+	  
+	  mu_message_set_header (msg, env->header, NULL);
+	  env->header = NULL;
+	  
+	  status = add_attachments (&msg, &mime);
+	  if (status)
+	    break;
+	  
 	  /* Save outgoing message */
 	  if (save_to)
 	    {
@@ -628,30 +939,29 @@ mail_send0 (compose_env_t *env, int save_to)
 	    }
 	  
 	  /* Do we need to Send the message on the wire?  */
-	  if (status == 0 &&
-	      (compose_header_get (env, MU_HEADER_TO, NULL) ||
-	       compose_header_get (env, MU_HEADER_CC, NULL) ||
-	       compose_header_get (env, MU_HEADER_BCC, NULL)))
+	  if (status == 0 && sendit)
 	    {
-	      mu_message_set_header (msg, env->header, NULL);
-	      env->header = NULL;
 	      status = send_message (msg);
 	      if (status)
 		{
 		  mu_error (_("cannot send message: %s"),
 			    mu_strerror (status));
-		  save_dead_message (env);
+		  save_dead_message (msg);
 		}
 	    }
-	}  
+	}
+      while (0);
+
       mu_stream_destroy (&env->compstr);
       mu_message_destroy (&msg, NULL);
+      mu_mime_destroy (&mime);
       return status;
     }
   else
-    save_dead_message (env);
+    save_dead_message_env (env);
   
   mu_stream_destroy (&env->compstr);
+  mu_list_destroy (&attlist);
   return 1;
 }
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Jul 19 01:43:22 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1SrjWE-0001eZ-8H
	for mharc-commit-mailutils@gnu.org; Thu, 19 Jul 2012 01:43:22 -0400
Received: from eggs.gnu.org ([208.118.235.92]:52899)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrjWB-0001eQ-ED
	for commit-mailutils@gnu.org; Thu, 19 Jul 2012 01:43:21 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrjW9-00017Y-40
	for commit-mailutils@gnu.org; Thu, 19 Jul 2012 01:43:19 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:48046)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrjW8-00017U-Vj
	for commit-mailutils@gnu.org; Thu, 19 Jul 2012 01:43:17 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SrjW5-00025Z-HP
	for commit-mailutils@gnu.org; Thu, 19 Jul 2012 05:43:16 +0000
Date: Thu, 19 Jul 2012 05:43:14 +0000
Message-Id: <E1SrjW5-00025Z-HP@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-621-g62e22dc
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 8ad474712f6758cdff637c5391867706957dfd74
X-Git-Newrev: 62e22dcc8419437e03225ae55223aaf97227b1e1
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, 19 Jul 2012 05:43: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=62e22dcc8419437e03225ae55223aaf97227b1e1

The branch, master has been updated
       via  62e22dcc8419437e03225ae55223aaf97227b1e1 (commit)
      from  8ad474712f6758cdff637c5391867706957dfd74 (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 62e22dcc8419437e03225ae55223aaf97227b1e1
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Jul 19 08:31:14 2012 +0300

    mail: provide mechanism for listing and editing attachments from the shell
    
    * NEWS: Update.
    * mail/escape.c (escape_check_args): Take two additional arguments
    specifying minimum and maximum number of parameters to expect.
    All uses updated. Remove static qualifier.
    * mail/mail.h (send_attach_file): Rename to send_attach_file_default
    (escape_check_args,escape_list_attachments)
    (escape_attach,escape_remove_attachment): New protos.
    * mail/send.c (send_attach_file): Take encoding and content type
    as arguments.
    (send_attach_file_default): New function.
    (escape_list_attachments)
    (escape_attach,escape_remove_attachment): New functions.
    * mail/table.c: New escapes: l, +, ^
    
    * include/mailutils/list.h (mu_list_remove_nth)
    (mu_list_remove_nth_nd): New protos.
    * libmailutils/list/Makefile.am (liblist_la_SOURCES): Add removenth.c
    * libmailutils/list/removenth.c: New file.

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

Summary of changes:
 NEWS                                        |   16 ++++-
 doc/imprimatur                              |    2 +-
 include/mailutils/list.h                    |    4 +
 libmailutils/list/Makefile.am               |    1 +
 libmailutils/list/{remove.c => removenth.c} |   21 +++---
 mail/escape.c                               |   35 +++++++---
 mail/mail.c                                 |    2 +-
 mail/mail.h                                 |    9 ++-
 mail/send.c                                 |  102 +++++++++++++++++++++++++--
 mail/table.c                                |    3 +
 10 files changed, 166 insertions(+), 29 deletions(-)
 copy libmailutils/list/{remove.c => removenth.c} (78%)

diff --git a/NEWS b/NEWS
index 8cac522..7e55823 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU mailutils NEWS -- history of user-visible changes. 2012-07-18
+GNU mailutils NEWS -- history of user-visible changes. 2012-07-19
 Copyright (C) 2002-2012 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
@@ -135,6 +135,20 @@ Here, the file "prog" will be attached witg the content type
 "main.c" and "ext.h" will be marked with content type "text/c" and
 encoded using "quoted-printable" algorithm.
 
+The mail shell provides the following new escapes to handle attachments:
+
+ ~l
+    Lists all attachments.  The output is a numbered list of
+    attachments with their corresponding content types and
+    encodings.
+    
+ ~+ filename [content-type [encoding]]
+    Attach the file `filename'.  Optional arguments supply the content
+    type and encoding to use instead of the defaults.
+
+ ~^ N
+    Delete Nth attachment.
+
 ** MH: improved compatibility with other implementations
 
 ** MH inc: new option --moveto
diff --git a/doc/imprimatur b/doc/imprimatur
index f32ef19..04255b6 160000
--- a/doc/imprimatur
+++ b/doc/imprimatur
@@ -1 +1 @@
-Subproject commit f32ef1983968e755cd580b06e369476d7e7f88b6
+Subproject commit 04255b6d5551952b4e0c94da15988f573e3e9fc4
diff --git a/include/mailutils/list.h b/include/mailutils/list.h
index 09bfccb..4d3e014 100644
--- a/include/mailutils/list.h
+++ b/include/mailutils/list.h
@@ -118,6 +118,10 @@ int mu_list_remove   (mu_list_t _list, void *_item);
   /* A non-destructive version of mu_list_remove: removes the _item but does
      not deallocate it. */
 int mu_list_remove_nd  (mu_list_t _list, void *_item);
+  /* Remove Nth element from the list. */
+int mu_list_remove_nth (mu_list_t list, size_t n);
+  /* Remove Nth element from the list, non-destructive. */
+int mu_list_remove_nth_nd (mu_list_t list, size_t n);
   /* Find _old_item in _list and if found, replace it with _new_item,
      deallocating the removed item via the `destroy_item' method. */
 int mu_list_replace  (mu_list_t _list, void *_old_item, void *_new_item);
diff --git a/libmailutils/list/Makefile.am b/libmailutils/list/Makefile.am
index bd648a6..7e2324c 100644
--- a/libmailutils/list/Makefile.am
+++ b/libmailutils/list/Makefile.am
@@ -42,6 +42,7 @@ liblist_la_SOURCES = \
  prepend.c\
  push.c\
  remove.c\
+ removenth.c\
  replace.c\
  rfold.c\
  setcomp.c\
diff --git a/libmailutils/list/remove.c b/libmailutils/list/removenth.c
similarity index 78%
copy from libmailutils/list/remove.c
copy to libmailutils/list/removenth.c
index 5ebd312..80550ee 100644
--- a/libmailutils/list/remove.c
+++ b/libmailutils/list/removenth.c
@@ -1,6 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999-2001, 2004-2005, 2007-2008, 2010-2012 Free
-   Software Foundation, Inc.
+   Copyright (C) 2012 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -24,20 +23,22 @@
 #include <mailutils/errno.h>
 
 int
-mu_list_remove (mu_list_t list, void *item)
+mu_list_remove_nth (mu_list_t list, size_t n)
 {
   struct list_data *current;
   mu_list_comparator_t comp;
   int status = MU_ERR_NOENT;
-
+  size_t i;
+    
   if (list == NULL)
     return EINVAL;
-  comp = list->comp ? list->comp : _mu_list_ptr_comparator;
+  if (n >= list->count)
+    return ERANGE;
   mu_monitor_wrlock (list->monitor);
-  for (current = list->head.next;
-       current != &list->head; current = current->next)
+  for (current = list->head.next, i = 0; current != &list->head;
+       current = current->next, i++)
     {
-      if (comp (current->item, item) == 0)
+      if (i == n)
 	{
 	  struct list_data *previous = current->prev;
 	  
@@ -56,10 +57,10 @@ mu_list_remove (mu_list_t list, void *item)
 }
 
 int
-mu_list_remove_nd (mu_list_t list, void *item)
+mu_list_remove_nth_nd (mu_list_t list, size_t n)
 {
   mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL);
-  int rc = mu_list_remove (list, item);
+  int rc = mu_list_remove_nth (list, n);
   mu_list_set_destroy_item (list, dptr);
   return rc;
 }
diff --git a/mail/escape.c b/mail/escape.c
index c0c0dcb..c1ec448 100644
--- a/mail/escape.c
+++ b/mail/escape.c
@@ -156,16 +156,29 @@ escape_continue (void)
   mu_printf (_("(continue)\n"));
 }
 
-static int 
-escape_check_args (int argc, char **argv)
+int 
+escape_check_args (int argc, char **argv, int minargs, int maxargs)
 {
-  if (argc == 1)
+  char *escape = "~";
+  if (argc < minargs)
     {
-      char *escape = "~";
+      minargs--;
       mailvar_get (&escape, "escape", mailvar_type_string, 0);
-      mu_error (_("%c%s requires an argument"), escape[0], argv[0]);
+      mu_error (ngettext ("%c%s requires at least %d argument",
+			  "%c%s requires at least %d arguments",
+			  minargs), escape[0], argv[0], minargs);
       return 1;
     }
+  if (maxargs > 1 && argc > maxargs)
+    {
+      maxargs--;
+      mailvar_get (&escape, "escape", mailvar_type_string, 0);
+      mu_error (ngettext ("%c%s accepts at most %d argument",
+			  "%c%s accepts at most %d arguments",
+			  maxargs), escape[0], argv[0], maxargs);
+      return 1;
+    }
+    
   return 0;
 }
 
@@ -184,7 +197,7 @@ escape_command (int argc, char **argv, compose_env_t *env)
   const struct mail_command_entry *entry;
   int status;
   
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   if (argv[1][0] == '#')
     return 0;
@@ -416,6 +429,8 @@ escape_editor (int argc, char **argv, compose_env_t *env)
   return escape_run_editor (getenv ("EDITOR"), argc, argv, env);
 }
 
+/* ~l -- escape_list_attachments (send.c) */
+
 /* ~v */
 int
 escape_visual (int argc, char **argv, compose_env_t *env)
@@ -457,7 +472,7 @@ escape_headers (int argc, char **argv, compose_env_t *env)
 int
 escape_insert (int argc, char **argv, compose_env_t *env)
 {
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   mailvar_variable_format (env->compstr, mailvar_find_variable (argv[1], 0),
 			   NULL);
@@ -574,7 +589,7 @@ escape_read (int argc, char **argv, compose_env_t *env MU_ARG_UNUSED)
   mu_stream_t instr;
   int rc;
   
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   filename = util_fullpath (argv[1]);
 
@@ -597,7 +612,7 @@ int
 escape_subj (int argc, char **argv, compose_env_t *env)
 {
   char *buf;
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   mu_argcv_string (argc - 1, argv + 1, &buf);
   compose_header_set (env, MU_HEADER_SUBJECT, buf, COMPOSE_REPLACE);
@@ -623,7 +638,7 @@ escape_write (int argc, char **argv, compose_env_t *env)
   int rc;
   mu_off_t size;
   
-  if (escape_check_args (argc, argv))
+  if (escape_check_args (argc, argv, 2, 2))
     return 1;
   filename = util_fullpath (argv[1]);
   /* FIXME: check for existence first */
diff --git a/mail/mail.c b/mail/mail.c
index e2eb63d..400bb0c 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -95,7 +95,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 
     case 'A':
       args->hint |= HINT_SEND_MODE;
-      if (send_attach_file (arg))
+      if (send_attach_file_default (arg))
 	exit (1);
       break;
       
diff --git a/mail/mail.h b/mail/mail.h
index c116b1b..c754dfd 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -258,7 +258,9 @@ extern char *mail_expand_name (const char *name);
 
 extern void send_append_header (char *text);
 extern void send_append_header2 (char *name, char *value, int mode);
-extern int send_attach_file (const char *name);
+extern int send_attach_file_default (const char *name);
+
+extern int escape_check_args (int argc, char **argv, int minargs, int maxargs);
 
 extern int escape_shell (int argc, char **argv, compose_env_t *env);
 extern int escape_command (int argc, char **argv, compose_env_t *env);
@@ -280,6 +282,11 @@ extern int escape_visual (int argc, char **argv, compose_env_t *env);
 extern int escape_write (int argc, char **argv, compose_env_t *env);
 extern int escape_exit (int argc, char **argv, compose_env_t *env);
 extern int escape_pipe (int argc, char **argv, compose_env_t *env);
+extern int escape_list_attachments  (int argc, char **argv,
+				     compose_env_t *env);
+extern int escape_attach (int argc, char **argv, compose_env_t *env);
+extern int escape_remove_attachment (int argc, char **argv,
+				     compose_env_t *env);
 
 /* Cursor */
 extern void set_cursor (unsigned value);
diff --git a/mail/send.c b/mail/send.c
index 3b8d446..053a289 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -154,11 +154,13 @@ atchinfo_free (void *p)
 }
 
 int
-send_attach_file (const char *name)
+send_attach_file (const char *name,
+		  const char *content_type, const char *encoding)
 {
   int rc;
   struct stat st;
   struct atchinfo *aptr;
+  mu_list_t list;
   
   if (stat (name, &st))
     {
@@ -180,6 +182,16 @@ send_attach_file (const char *name)
       return 1;
     }
 
+  if (!encoding)
+    encoding = "base64";
+  mu_filter_get_list (&list);
+  rc = mu_list_locate (list, encoding, NULL);
+  if (rc)
+    {
+      mu_error (_("unsupported encoding: %s"), encoding);
+      return 1;
+    }
+  
   if (!attlist)
     {
       rc = mu_list_create (&attlist);
@@ -191,10 +203,10 @@ send_attach_file (const char *name)
       mu_list_set_destroy_item (attlist, atchinfo_free);
     }
   aptr = mu_alloc (sizeof (*aptr));
-  aptr->encoding = mu_strdup (default_encoding ?
-			      default_encoding : "base64");
-  aptr->content_type = mu_strdup (default_content_type ?
-				  default_content_type :
+
+  aptr->encoding = mu_strdup (encoding);  
+  aptr->content_type = mu_strdup (content_type ?
+				  content_type :
 				    "application/octet-stream");
   aptr->filename = mu_strdup (name);
   rc = mu_list_append (attlist, aptr);
@@ -206,6 +218,86 @@ send_attach_file (const char *name)
   return 0;
 }
 
+int
+send_attach_file_default (const char *name)
+{
+  return send_attach_file (name, default_content_type, default_encoding);
+}
+
+int
+escape_list_attachments (int argc, char **argv, compose_env_t *env)
+{
+  mu_iterator_t itr;
+  int i;
+  
+  if (mu_list_is_empty (attlist) ||
+      mu_list_get_iterator (attlist, &itr))
+    {
+      mu_printf ("%s\n", _("No attachments"));
+      return 0;
+    }
+  
+  for (mu_iterator_first (itr), i = 1; !mu_iterator_is_done (itr);
+       mu_iterator_next (itr), i++)
+    {
+      struct atchinfo *aptr;
+      if (mu_iterator_current (itr, (void**)&aptr))
+	continue;
+	  
+      mu_printf ("%3d %-12s %-30s %-s\n",
+		 i, aptr->filename, aptr->content_type, aptr->encoding);
+    }
+  mu_iterator_destroy (&itr);
+
+  return 0;
+}
+
+int
+escape_attach (int argc, char **argv, compose_env_t *env)
+{
+  const char *encoding = default_encoding;
+  const char *content_type = default_content_type;
+  
+  switch (argc)
+    {
+    case 4:
+      encoding = argv[3];
+    case 3:
+      content_type = argv[2];
+    case 2:
+      return send_attach_file (argv[1], content_type, encoding);
+    default:
+      return escape_check_args (argc, argv, 2, 4);
+    }
+  return 1;
+}
+
+int
+escape_remove_attachment (int argc, char **argv, compose_env_t *env)
+{
+  size_t count;
+  unsigned long n;
+  char *p;
+  
+  if (escape_check_args (argc, argv, 2, 2))
+    return 1;
+  n = strtoul (argv[1], &p, 10);
+  if (*p)
+    {
+      mu_error (_("not a valid number: %s"), argv[1]);
+      return 1;
+    }
+  
+  mu_list_count (attlist, &count);
+  if (n == 0 || n > count)
+    {
+      mu_error (_("index out of range"));
+      return 1;
+    }
+
+  return mu_list_remove_nth (attlist, n - 1);
+}
+
 static int
 saveatt (void *item, void *data)
 {
diff --git a/mail/table.c b/mail/table.c
index 41eda1d..a496612 100644
--- a/mail/table.c
+++ b/mail/table.c
@@ -226,6 +226,8 @@ static const struct mail_escape_entry mail_escape_table[] = {
   {"!",	"!",	"![shell-command]", escape_shell },
   {":",	":",	":[mail-command]",  escape_command },
   {"-",	"-",	"-[mail-command]",  escape_command },
+  {"+",	"+",	"+[name [content-type [encoding]]]", escape_attach },
+  {"^",	"^",	"^[N]",             escape_remove_attachment },
   {"?",	"?",	"?",		    escape_help },
   {"A",	"A",	"A",		    escape_sign },
   {"a",	"a",	"a",		    escape_sign },
@@ -237,6 +239,7 @@ static const struct mail_escape_entry mail_escape_table[] = {
   {"F",	"F",	"F[mesg-list]",	    escape_print },
   {"h",	"h",	"h",		    escape_headers },
   {"i",	"i",	"i[var-name]",	    escape_insert },
+  {"l",	"l",	"l",                escape_list_attachments },
   {"m",	"m",	"m[mesg-list]",	    escape_quote },
   {"M",	"M",	"M[mesg-list]",	    escape_quote },
   {"p",	"p",	"p",		    escape_type_input },


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Jul 22 15:43:19 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1St23j-0001T2-Ua
	for mharc-commit-mailutils@gnu.org; Sun, 22 Jul 2012 15:43:19 -0400
Received: from eggs.gnu.org ([208.118.235.92]:39004)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1St23g-0001Sm-GF
	for commit-mailutils@gnu.org; Sun, 22 Jul 2012 15:43:18 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1St23d-0006of-JO
	for commit-mailutils@gnu.org; Sun, 22 Jul 2012 15:43:16 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:37961)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1St23d-0006oZ-FZ
	for commit-mailutils@gnu.org; Sun, 22 Jul 2012 15:43:13 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1St23c-0005bV-FE
	for commit-mailutils@gnu.org; Sun, 22 Jul 2012 19:43:13 +0000
Date: Sun, 22 Jul 2012 19:43:12 +0000
Message-Id: <E1St23c-0005bV-FE@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-623-g0b1e16b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 62e22dcc8419437e03225ae55223aaf97227b1e1
X-Git-Newrev: 0b1e16bea8f32524dd123cc267fe1839f9bc3b0f
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, 22 Jul 2012 19:43: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=0b1e16bea8f32524dd123cc267fe1839f9bc3b0f

The branch, master has been updated
       via  0b1e16bea8f32524dd123cc267fe1839f9bc3b0f (commit)
       via  98f7cc4c92786005e95e9a234f33d1f5a8e88ce6 (commit)
      from  62e22dcc8419437e03225ae55223aaf97227b1e1 (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 0b1e16bea8f32524dd123cc267fe1839f9bc3b0f
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Jul 22 18:55:03 2012 +0300

    pop3d: make tls more configurable
    
    The "tls" statement can be used both within a server declaration
    and in the global scope, the former overriding the latter.  Its
    argument can be one of the following:
    
      no          TLS is not used.  The STLS command won't be available even
                  if the tls configuration is otherwise complete.
      ondemand    TLS is initiated when the user issues the STLS command.
                  This is the default when TLS is configured.
      required    Same as above, but the use of STLS is mandatory.  The
                  authentication state is entered only after TLS negotiation
                  has succeeded.
      connection  TLS is always forced when the connection is established (pops).
    
    For compatibility with prior versions the tls-required statement is retained,
    but is considered deprecated.  It is synonymous with "tls required".  The
    "tls" statement allows for the following alias values:
    
      false, off, 0           same as  no
      stls                    same as  ondemand
      yes, true, on, 1        same as  connection
    
    Internally, all handler functions receive a pointer to the POP session
    structure, which configures the current session.  In particular, it
    contains the TLS mode and capability list.
    
    * pop3d/capa.c (pop3d_capa): Traverse the capability list,
    outputting each of its elements.
    (pop3d_session_init)
    (pop3d_session_free): New functions.
    * pop3d/logindelay.c (login_delay_capa): Change signature.
    * pop3d/pop3d.c (tls_required): Remove.
    (tls_mode): New variable.
    (pop3d_srv_config) <tls>: Remove.
    (pop3d_srv_config) <tls_mode>: New member.
    (pop3d_srv_param): Change definition of the "tls" statement.
    (pop3d_cfg_param): New statement "tls". Mark "tls-required"
    as deprecated.
    (pop3d_mainloop): Change type of the tls argument.
    Initialize session and pass it to each handler.
    (pop3d_connection): Decide whether and how to use TLS
    using global and per-session settings, the latter
    overriding the former.
    * pop3d/pop3d.h (login_delay_capa): Change signature.
    (tls_mode): New enum.
    (pop3d_capa_type): New enum.
    (pop3d_capa, pop3d_session): New structs.
    (pop3d_session_init)
    (pop3d_session_free): New protos.
    (pop3d_command_handler_t): Change signature. All handlers and their
    uses are changed accordingly.
    * pop3d/stls.c (pop3d_stls): Return error if session does not
    allow tls.

commit 98f7cc4c92786005e95e9a234f33d1f5a8e88ce6
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Jul 21 23:47:48 2012 +0300

    Minor fix

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

Summary of changes:
 maidag/maidag.c    |    3 +-
 pop3d/apop.c       |    2 +-
 pop3d/auth.c       |    2 +-
 pop3d/capa.c       |  142 +++++++++++++++++++++++++++++++++++++++++++--------
 pop3d/dele.c       |    2 +-
 pop3d/list.c       |    2 +-
 pop3d/logindelay.c |    6 +-
 pop3d/noop.c       |    2 +-
 pop3d/pop3d.c      |  106 ++++++++++++++++++++++++++++++++-------
 pop3d/pop3d.h      |   72 ++++++++++++++++++++------
 pop3d/quit.c       |    2 +-
 pop3d/retr.c       |    2 +-
 pop3d/rset.c       |    2 +-
 pop3d/stat.c       |    2 +-
 pop3d/stls.c       |   13 ++++-
 pop3d/top.c        |    2 +-
 pop3d/uidl.c       |    2 +-
 pop3d/user.c       |    4 +-
 18 files changed, 291 insertions(+), 77 deletions(-)

diff --git a/maidag/maidag.c b/maidag/maidag.c
index dc86387..530d768 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -304,7 +304,8 @@ cb_stderr (void *data, mu_config_value_t *val)
     return 1;
   if (mu_cfg_parse_boolean (val->v.string, &res))
     mu_error (_("not a boolean"));
-  mu_log_syslog = !res;
+  else
+    mu_log_syslog = !res;
   return 0;
 }
     
diff --git a/pop3d/apop.c b/pop3d/apop.c
index 7dc59ae..bb5b383 100644
--- a/pop3d/apop.c
+++ b/pop3d/apop.c
@@ -164,7 +164,7 @@ pop3d_apopuser (const char *user)
 }
 
 int
-pop3d_apop (char *arg)
+pop3d_apop (char *arg, struct pop3d_session *sess)
 {
   char *p, *password, *user_digest, *user;
   struct mu_md5_ctx md5context;
diff --git a/pop3d/auth.c b/pop3d/auth.c
index e7cb508..33305b0 100644
--- a/pop3d/auth.c
+++ b/pop3d/auth.c
@@ -19,7 +19,7 @@
 /* AUTH is not yet implemented */
 
 int
-pop3d_auth (char *arg MU_ARG_UNUSED)
+pop3d_auth (char *arg MU_ARG_UNUSED, struct pop3d_session *sess MU_ARG_UNUSED)
 {
   if (state != AUTHORIZATION)
     return ERR_WRONG_STATE;
diff --git a/pop3d/capa.c b/pop3d/capa.c
index 0c75a70..5832c45 100644
--- a/pop3d/capa.c
+++ b/pop3d/capa.c
@@ -26,38 +26,134 @@
 
   Capabilities available in the AUTHORIZATION state MUST be announced
   in both states.  */
+
+static int
+print_capa (void *item, void *data)
+{
+  struct pop3d_capa *cp = item;
+  struct pop3d_session *session = data;
+  if (cp->type == capa_func)
+    {
+      cp->value.func (cp->name, session);
+    }
+  else 
+    {
+      pop3d_outf ("%s", cp->name);
+      if (cp->value.string)
+	pop3d_outf ("%s", cp->value.string);
+      pop3d_outf ("\n");
+    }
+  return 0;
+}
+
 int
-pop3d_capa (char *arg)
+pop3d_capa (char *arg, struct pop3d_session *sess)
 {
   if (strlen (arg) != 0)
     return ERR_BAD_ARGS;
 
   pop3d_outf ("+OK Capability list follows\n");
-  pop3d_outf ("TOP\n");
-  pop3d_outf ("USER\n");
-  pop3d_outf ("UIDL\n");
-  pop3d_outf ("RESP-CODES\n");
-  pop3d_outf ("PIPELINING\n");
-  if (pop3d_xlines)
-    pop3d_outf ("XLINES\n");
-    
+  mu_list_foreach (sess->capa, print_capa, sess);
+  pop3d_outf (".\n");
+  return OK;
+}
+
+static void
+pop3d_append_capa_string (struct pop3d_session *sess, const char *name,
+			  const char *value)
+{
+  struct pop3d_capa *cp;
+
+  cp = mu_alloc (sizeof (*cp));
+  cp->type = capa_string;
+  cp->name = name;
+  cp->value.string = value ? mu_strdup (value) : NULL;
+  if (mu_list_append (sess->capa, cp))
+    mu_alloc_die ();
+}
+
+static void
+pop3d_append_capa_func (struct pop3d_session *sess, const char *name,
+			void (*func) (const char *, struct pop3d_session *))
+{
+  struct pop3d_capa *cp;
+
+  if (!func)
+    return;
+  cp = mu_alloc (sizeof (*cp));
+  cp->type = capa_func;
+  cp->name = name;
+  cp->value.func = func;
+  if (mu_list_append (sess->capa, cp))
+    mu_alloc_die ();
+}  
+
+static void
+capa_free (void *p)
+{
+  struct pop3d_capa *cp = p;
+  if (cp->type == capa_string && cp->value.string)
+    free (cp->value.string);
+  free (cp);
+}
+
+static void
+capa_implementation (const char *name, struct pop3d_session *session)
+{
+  if (state == TRANSACTION)	/* let's not advertise to just anyone */
+    pop3d_outf ("%s %s\n", name, PACKAGE_STRING);
+}
+
 #ifdef WITH_TLS
-  if (tls_available && tls_done == 0)
-    pop3d_outf ("STLS\n");
+static void
+capa_stls (const char *name, struct pop3d_session *session)
+{
+  if ((session->tls == tls_ondemand || session->tls == tls_required)
+      && tls_available && tls_done == 0)
+    pop3d_outf ("%s\n", name);
+}
+#else
+# define capa_stls NULL
 #endif /* WITH_TLS */
 
-  login_delay_capa ();
-  /* This can be implemented by setting an header field on the message.  */
-  if (expire == EXPIRE_NEVER)
-    pop3d_outf ("EXPIRE NEVER\n");
-  else 
-    pop3d_outf ("EXPIRE %s\n", mu_umaxtostr (0, expire));
-
+static void
+capa_user (const char *name, struct pop3d_session *session)
+{
   if (state == INITIAL)
     pop3d_outf ("XTLSREQUIRED\n");
-  
-  if (state == TRANSACTION)	/* let's not advertise to just anyone */
-    pop3d_outf ("IMPLEMENTATION %s\n", PACKAGE_STRING);
-  pop3d_outf (".\n");
-  return OK;
+  else
+    pop3d_outf ("USER\n");
+}
+
+void
+pop3d_session_init (struct pop3d_session *session)
+{
+  if (mu_list_create (&session->capa))
+    mu_alloc_die ();
+  mu_list_set_destroy_item (session->capa, capa_free);
+
+  /* Initialize the capability list */
+  pop3d_append_capa_string (session, "TOP", NULL);
+  pop3d_append_capa_string (session, "UIDL", NULL);
+  pop3d_append_capa_string (session, "RESP-CODES", NULL);
+  pop3d_append_capa_string (session, "PIPELINING", NULL);
+  if (pop3d_xlines)
+    pop3d_append_capa_string (session, "XLINES", NULL);
+
+  pop3d_append_capa_func (session, "LOGIN-DELAY", login_delay_capa);
+    
+  /* This can be implemented by setting an header field on the message.  */
+  pop3d_append_capa_string (session, "EXPIRE",
+			    (expire == EXPIRE_NEVER) ?
+			    "NEVER" : mu_umaxtostr (0, expire));
+
+  pop3d_append_capa_func (session, NULL, capa_user);
+  pop3d_append_capa_func (session, "STLS", capa_stls);
+  pop3d_append_capa_func (session, "IMPLEMENTATION", capa_implementation);
+}
+
+void
+pop3d_session_free (struct pop3d_session *session)
+{
+  mu_list_destroy (&session->capa);
 }
diff --git a/pop3d/dele.c b/pop3d/dele.c
index 2cf9e43..1090653 100644
--- a/pop3d/dele.c
+++ b/pop3d/dele.c
@@ -20,7 +20,7 @@
 /* DELE adds a message number to the list of messages to be deleted on QUIT */
 
 int
-pop3d_dele (char *arg)
+pop3d_dele (char *arg, struct pop3d_session *sess)
 {
   size_t num;
   mu_message_t msg;
diff --git a/pop3d/list.c b/pop3d/list.c
index ba07275..607c698 100644
--- a/pop3d/list.c
+++ b/pop3d/list.c
@@ -39,7 +39,7 @@
   XLINES capability.
 */
 int
-pop3d_list (char *arg)
+pop3d_list (char *arg, struct pop3d_session *sess)
 {
   size_t mesgno;
   mu_message_t msg = NULL;
diff --git a/pop3d/logindelay.c b/pop3d/logindelay.c
index 094d84e..b41988a 100644
--- a/pop3d/logindelay.c
+++ b/pop3d/logindelay.c
@@ -141,13 +141,13 @@ update_login_delay (char *username)
 }
 
 void
-login_delay_capa ()
+login_delay_capa (const char *name, struct pop3d_session *session)
 {
   mu_dbm_file_t db;
-  
+
   if (login_delay && (db = open_stat_db (MU_STREAM_RDWR)) != NULL)
     {
-      pop3d_outf ("LOGIN-DELAY %s\n", mu_umaxtostr (0, login_delay));
+      pop3d_outf ("%lu\n", (unsigned long) login_delay);
       mu_dbm_destroy (&db);
     }
 }
diff --git a/pop3d/noop.c b/pop3d/noop.c
index 44a916c..166e2fb 100644
--- a/pop3d/noop.c
+++ b/pop3d/noop.c
@@ -20,7 +20,7 @@
 /* Does nothing */
 
 int
-pop3d_noop (char *arg)
+pop3d_noop (char *arg, struct pop3d_session *sess)
 {
   if (strlen (arg) != 0)
     return ERR_BAD_ARGS;
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index efe4155..c7a650e 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -18,6 +18,7 @@
 #include "mailutils/pam.h"
 #include "mailutils/libargp.h"
 #include "mailutils/pop3.h"
+#include "mailutils/kwd.h"
 #include "tcpwrap.h"
 
 mu_mailbox_t mbox;
@@ -29,13 +30,14 @@ mu_m_server_t server;
 unsigned int idle_timeout;
 int pop3d_transcript;
 int debug_mode;
-int tls_required;
 int pop3d_xlines;
 char *apop_database_name = APOP_PASSFILE;
 int apop_database_safety = MU_FILE_SAFETY_ALL;
 uid_t apop_database_owner;
 int apop_database_owner_set;
 
+enum tls_mode tls_mode;
+
 #ifdef WITH_TLS
 int tls_available;
 int tls_done;
@@ -137,13 +139,61 @@ cb_bulletin_db (void *data, mu_config_value_t *val)
 struct pop3d_srv_config
 {
   struct mu_srv_config m_cfg;
-  int tls;
+  enum tls_mode tls_mode;
 };
 
+#ifdef WITH_TLS
+static int
+cb_tls (void *data, mu_config_value_t *val)
+{
+  int *res = data;
+  static struct mu_kwd tls_kwd[] = {
+    { "no", tls_no },
+    { "false", tls_no },
+    { "off", tls_no },
+    { "0", tls_no },
+    { "ondemand", tls_ondemand },
+    { "stls", tls_ondemand },
+    { "required", tls_required },
+    { "connection", tls_connection },
+    /* For compatibility with prior versions: */
+    { "yes", tls_connection }, 
+    { "true", tls_connection },
+    { "on", tls_connection },
+    { "1", tls_connection },
+    { NULL }
+  };
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+
+  if (mu_kwd_xlat_name (tls_kwd, val->v.string, res))
+    mu_error (_("not a valid tls keyword: %s"), val->v.string);
+  return 0;
+}
+#endif
+
+static int
+cb_tls_required (void *data, mu_config_value_t *val)
+{
+  int *res = data;
+  int bv;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  if (mu_cfg_parse_boolean (val->v.string, &bv))
+    mu_error (_("Not a boolean value"));
+  else
+    *res = tls_required;
+  return 0;
+}
+
 static struct mu_cfg_param pop3d_srv_param[] = {
-  { "tls", mu_cfg_bool, NULL, mu_offsetof (struct pop3d_srv_config, tls), NULL,
-    N_("Use TLS encryption for this server")
-  },
+#ifdef WITH_TLS
+  { "tls", mu_cfg_callback,
+    NULL, mu_offsetof (struct pop3d_srv_config, tls_mode), cb_tls,
+    N_("Kind of TLS encryption to use for this server") },
+#endif
   { NULL }
 };
     
@@ -178,8 +228,11 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
     N_("arg: list") },  
     
 #ifdef WITH_TLS
-  { "tls-required", mu_cfg_bool, &tls_required, 0, NULL,
-     N_("Always require STLS before entering authentication phase.") },
+  { "tls", mu_cfg_callback, &tls_mode, 0, cb_tls,
+    N_("Kind of TLS encryption to use") },
+  { "tls-required", mu_cfg_callback, &tls_mode, 0, cb_tls_required,
+    N_("Always require STLS before entering authentication phase.\n"
+       "Deprecated, use \"tls required\" instead.") },
 #endif
 #ifdef ENABLE_LOGIN_DELAY
   { "login-delay", mu_cfg_time, &login_delay, 0, NULL,
@@ -292,19 +345,36 @@ pop3d_get_client_address (int fd, struct sockaddr_in *pcs)
       ofd       --  output descriptor
       tls       --  initiate encrypted connection */
 int
-pop3d_mainloop (int ifd, int ofd, int tls)
+pop3d_mainloop (int ifd, int ofd, enum tls_mode tls)
 {
   int status = OK;
   char buffer[512];
   static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE,
 			  SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM };
-
+  struct pop3d_session session;
+     
   mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab));
 
-  pop3d_setio (ifd, ofd, tls);
+  if (tls == tls_unspecified)
+    tls = tls_available ? tls_ondemand : tls_no;
+  else if (tls != tls_no && !tls_available)
+    {
+      mu_error (_("TLS is not configured, but requested in the "
+		  "configuration"));
+      tls = tls_no;
+    }
+  
+  pop3d_setio (ifd, ofd, tls == tls_connection);
 
-  state = tls ? AUTHORIZATION : initial_state;
+  if (tls == tls_required)
+    initial_state = INITIAL;
+  
+  state = tls == tls_connection ? AUTHORIZATION : initial_state;
 
+  pop3d_session_init (&session);
+  session.tls = tls;
+  /* FIXME: state should also be in the session? */
+  
   /* Prepare the shared secret for APOP.  */
   {
     char *local_hostname;
@@ -353,7 +423,7 @@ pop3d_mainloop (int ifd, int ofd, int tls)
       manlock_touchlock (mbox);
 
       if ((handler = pop3d_find_command (cmd)) != NULL)
-	status = handler (arg);
+	status = handler (arg, &session);
       else
 	status = ERR_BAD_CMD;
 
@@ -361,6 +431,8 @@ pop3d_mainloop (int ifd, int ofd, int tls)
 	pop3d_outf ("-ERR %s\n", pop3d_error_string (status));
     }
 
+  pop3d_session_free (&session);
+  
   pop3d_bye ();
 
   return status;
@@ -445,8 +517,9 @@ pop3d_connection (int fd, struct sockaddr *sa, int salen,
     rc = set_strerr_flt ();
   else
     rc = 1;
-  
-  pop3d_mainloop (fd, fd, cfg->tls);
+
+  pop3d_mainloop (fd, fd,
+		  cfg->tls_mode == tls_unspecified ? tls_mode : cfg->tls_mode);
 
   if (rc == 0)
     clr_strerr_flt ();
@@ -517,9 +590,6 @@ main (int argc, char **argv)
 		   argc, argv, 0, NULL, server))
     exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
 
-  if (tls_required)
-    initial_state = INITIAL;
-  
   if (expire == 0)
     expire_on_exit = 1;
 
@@ -589,7 +659,7 @@ main (int argc, char **argv)
     {
       /* Make sure we are in the root directory.  */
       chdir ("/");
-      status = pop3d_mainloop (MU_STDIN_FD, MU_STDOUT_FD, 0);
+      status = pop3d_mainloop (MU_STDIN_FD, MU_STDOUT_FD, tls_no);
     }
   
   if (status)
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index aa99ea4..c30086e 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -42,17 +42,19 @@
 # undef ENABLE_LOGIN_DELAY
 #endif
 
+struct pop3d_session;
+
 #ifdef ENABLE_LOGIN_DELAY
 # define LOGIN_STAT_FILE "/var/run/pop3-login"
 extern time_t login_delay;
 extern char *login_stat_file;
 extern int check_login_delay (char *username);
 extern void update_login_delay (char *username);
-extern void login_delay_capa (void);
+extern void login_delay_capa (const char *, struct pop3d_session *);
 #else
 # define check_login_delay(u) 0
 # define update_login_delay(u)
-# define login_delay_capa()
+# define login_delay_capa NULL
 #endif
 
 /* Minimum advertise retention time for messages.  */
@@ -166,8 +168,44 @@ extern int expire_on_exit;
 #define ERR_LOGIN_DELAY 22
 #define ERR_TERMINATE   23
 
+enum tls_mode
+  {
+    tls_unspecified,
+    tls_no,
+    tls_ondemand,
+    tls_required,
+    tls_connection
+  };
+
+enum pop3d_capa_type
+  {
+    capa_string,
+    capa_func
+  };
+
+struct pop3d_capa
+{
+  enum pop3d_capa_type type;
+  const char *name;
+  union
+  {
+    char *string;
+    void (*func) (const char *, struct pop3d_session *);
+  } value;
+};
+
+struct pop3d_session
+{
+  mu_list_t capa;
+  enum tls_mode tls;
+};
+
+void pop3d_session_init (struct pop3d_session *session);
+void pop3d_session_free (struct pop3d_session *session);
+
+
 typedef struct mu_pop_server *mu_pop_server_t;
-typedef int (*pop3d_command_handler_t) (char *);
+typedef int (*pop3d_command_handler_t) (char *, struct pop3d_session *sess);
 
 struct pop3d_command
 {
@@ -214,19 +252,19 @@ extern int apop_database_owner_set;
 
 extern pop3d_command_handler_t pop3d_find_command (const char *name);
 
-extern int pop3d_stat           (char *);
-extern int pop3d_top            (char *);
-extern int pop3d_uidl           (char *);
-extern int pop3d_user           (char *);
-extern int pop3d_apop           (char *);
-extern int pop3d_auth           (char *);
-extern int pop3d_capa           (char *);
-extern int pop3d_dele           (char *);
-extern int pop3d_list           (char *);
-extern int pop3d_noop           (char *);
-extern int pop3d_quit           (char *);
-extern int pop3d_retr           (char *);
-extern int pop3d_rset           (char *);
+extern int pop3d_stat           (char *, struct pop3d_session *);
+extern int pop3d_top            (char *, struct pop3d_session *);
+extern int pop3d_uidl           (char *, struct pop3d_session *);
+extern int pop3d_user           (char *, struct pop3d_session *);
+extern int pop3d_apop           (char *, struct pop3d_session *);
+extern int pop3d_auth           (char *, struct pop3d_session *);
+extern int pop3d_capa           (char *, struct pop3d_session *);
+extern int pop3d_dele           (char *, struct pop3d_session *);
+extern int pop3d_list           (char *, struct pop3d_session *);
+extern int pop3d_noop           (char *, struct pop3d_session *);
+extern int pop3d_quit           (char *, struct pop3d_session *);
+extern int pop3d_retr           (char *, struct pop3d_session *);
+extern int pop3d_rset           (char *, struct pop3d_session *);
 
 void pop3d_send_payload (mu_stream_t stream, mu_stream_t linestr,
 			 size_t maxlines);
@@ -242,7 +280,7 @@ extern RETSIGTYPE pop3d_master_signal  (int);
 extern RETSIGTYPE pop3d_child_signal  (int);
 
 #ifdef WITH_TLS
-extern int pop3d_stls           (char *);
+extern int pop3d_stls           (char *, struct pop3d_session *);
 extern void enable_stls (void);
 #endif /* WITH_TLS */
 extern void pop3d_outf          (const char *fmt, ...) MU_PRINTFLIKE(1,2);
diff --git a/pop3d/quit.c b/pop3d/quit.c
index e60e492..c0ac996 100644
--- a/pop3d/quit.c
+++ b/pop3d/quit.c
@@ -26,7 +26,7 @@
 static void pop3d_fix_mark ();
 
 int
-pop3d_quit (char *arg)
+pop3d_quit (char *arg, struct pop3d_session *sess)
 {
   int err = OK;
   if (strlen (arg) != 0)
diff --git a/pop3d/retr.c b/pop3d/retr.c
index aa12921..a058302 100644
--- a/pop3d/retr.c
+++ b/pop3d/retr.c
@@ -64,7 +64,7 @@ pop3d_send_payload (mu_stream_t stream, mu_stream_t linestr, size_t maxlines)
 /* Prints out the specified message */
 
 int
-pop3d_retr (char *arg)
+pop3d_retr (char *arg, struct pop3d_session *sess)
 {
   size_t mesgno;
   mu_message_t msg = NULL;
diff --git a/pop3d/rset.c b/pop3d/rset.c
index 4ea96c4..80a30f2 100644
--- a/pop3d/rset.c
+++ b/pop3d/rset.c
@@ -20,7 +20,7 @@
 /* Resets the connection so that no messages are marked as deleted */
 
 int
-pop3d_rset (char *arg)
+pop3d_rset (char *arg, struct pop3d_session *sess)
 {
   size_t i;
   size_t total = 0;
diff --git a/pop3d/stat.c b/pop3d/stat.c
index dd4d2b4..8eb7d58 100644
--- a/pop3d/stat.c
+++ b/pop3d/stat.c
@@ -20,7 +20,7 @@
 /* Prints the number of messages and the total size of all messages */
 
 int
-pop3d_stat (char *arg)
+pop3d_stat (char *arg, struct pop3d_session *sess)
 {
   size_t mesgno;
   size_t size = 0;
diff --git a/pop3d/stls.c b/pop3d/stls.c
index 1172df6..003fbe3 100644
--- a/pop3d/stls.c
+++ b/pop3d/stls.c
@@ -21,7 +21,7 @@
 #ifdef WITH_TLS
 
 int
-pop3d_stls (char *arg)
+pop3d_stls (char *arg, struct pop3d_session *session)
 {
   if (strlen (arg) != 0)
     return ERR_BAD_ARGS;
@@ -29,6 +29,15 @@ pop3d_stls (char *arg)
   if (state != initial_state)
     return ERR_WRONG_STATE;
 
+  switch (session->tls)
+    {
+    case tls_ondemand:
+    case tls_required:
+      break;
+    default:
+      return ERR_WRONG_STATE;
+    }
+  
   if (tls_done)
     return ERR_TLS_ACTIVE;
 
@@ -45,7 +54,7 @@ pop3d_stls (char *arg)
     }
 
   state = AUTHORIZATION;  /* Confirm we're in this state. Necessary for
-			     --tls-required to work */
+			     "tls required" to work */
 
   return OK;
 }
diff --git a/pop3d/top.c b/pop3d/top.c
index 53658ad..8c92f1e 100644
--- a/pop3d/top.c
+++ b/pop3d/top.c
@@ -20,7 +20,7 @@
 /* Prints the header of a message plus a specified number of lines.  */
 
 int
-pop3d_top (char *arg)
+pop3d_top (char *arg, struct pop3d_session *sess)
 {
   size_t mesgno;
   unsigned long lines;
diff --git a/pop3d/uidl.c b/pop3d/uidl.c
index 99da494..84118db 100644
--- a/pop3d/uidl.c
+++ b/pop3d/uidl.c
@@ -18,7 +18,7 @@
 #include "pop3d.h"
 
 int
-pop3d_uidl (char *arg)
+pop3d_uidl (char *arg, struct pop3d_session *sess)
 {
   size_t mesgno;
   char uidl[128];
diff --git a/pop3d/user.c b/pop3d/user.c
index d68ab90..6706ac9 100644
--- a/pop3d/user.c
+++ b/pop3d/user.c
@@ -72,7 +72,7 @@ pop3d_begin_session ()
 }
 
 int
-pop3d_user (char *arg)
+pop3d_user (char *arg, struct pop3d_session *sess)
 {
   char *buf, *pass, *cmd;
   char buffer[512];
@@ -129,7 +129,7 @@ pop3d_user (char *arg)
   else if (mu_c_strcasecmp (cmd, "QUIT") == 0)
     {
       mu_diag_output (MU_DIAG_INFO, _("possible probe of account `%s'"), arg);
-      return pop3d_quit (pass);
+      return pop3d_quit (pass, sess);
     }
   else
     {


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Jul 23 01:57:59 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1StBeZ-00079B-3X
	for mharc-commit-mailutils@gnu.org; Mon, 23 Jul 2012 01:57:59 -0400
Received: from eggs.gnu.org ([208.118.235.92]:55421)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1StBeW-00078K-4P
	for commit-mailutils@gnu.org; Mon, 23 Jul 2012 01:57:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1StBeU-0001Ja-J8
	for commit-mailutils@gnu.org; Mon, 23 Jul 2012 01:57:56 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:41841)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1StBeU-0001JW-Fr
	for commit-mailutils@gnu.org; Mon, 23 Jul 2012 01:57:54 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1StBeS-0006qW-LS
	for commit-mailutils@gnu.org; Mon, 23 Jul 2012 05:57:54 +0000
Date: Mon, 23 Jul 2012 05:57:52 +0000
Message-Id: <E1StBeS-0006qW-LS@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-624-g3412850
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 0b1e16bea8f32524dd123cc267fe1839f9bc3b0f
X-Git-Newrev: 34128509db514024afd85a714cb9cad1f71d2d82
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, 23 Jul 2012 05:57:57 -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=34128509db514024afd85a714cb9cad1f71d2d82

The branch, master has been updated
       via  34128509db514024afd85a714cb9cad1f71d2d82 (commit)
      from  0b1e16bea8f32524dd123cc267fe1839f9bc3b0f (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 34128509db514024afd85a714cb9cad1f71d2d82
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Jul 23 08:54:38 2012 +0300

    Minor changes in SMTP and URL code.
    
    * include/mailutils/smtp.h (mu_smtp_replcode)
    (mu_smtp_sget_reply)
    (mu_smtp_capa_iterator): New protos.
    * libmailutils/url/dup.c (mu_url_dup): Bugfix. Obtain the
    name using mu_url_sget_name, which will create it if necessary.
    * libproto/mailer/Makefile.am (libmu_mailer_la_SOURCES): Add
    smtp_capa_itr.c
    * libproto/mailer/smtp_capa_itr.c: New file.
    * libproto/mailer/smtp_io.c (mu_smtp_response): Fix filling of
    smtp->flbuf.
    (mu_smtp_replcode,mu_smtp_sget_reply): New functions.

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

Summary of changes:
 include/mailutils/smtp.h                         |    5 +++++
 libmailutils/url/dup.c                           |    4 +++-
 libproto/mailer/Makefile.am                      |    1 +
 libproto/mailer/{smtp_capa.c => smtp_capa_itr.c} |    7 ++++---
 libproto/mailer/smtp_io.c                        |   19 ++++++++++++++++++-
 5 files changed, 31 insertions(+), 5 deletions(-)
 copy libproto/mailer/{smtp_capa.c => smtp_capa_itr.c} (88%)

diff --git a/include/mailutils/smtp.h b/include/mailutils/smtp.h
index 4ae6a33..6d8cdd9 100644
--- a/include/mailutils/smtp.h
+++ b/include/mailutils/smtp.h
@@ -45,6 +45,10 @@ int mu_smtp_open (mu_smtp_t);
 int mu_smtp_response (mu_smtp_t smtp);
 int mu_smtp_write (mu_smtp_t smtp, const char *fmt, ...) MU_PRINTFLIKE(2,3);
 
+int mu_smtp_replcode (mu_smtp_t smtp, char *buf);
+int mu_smtp_sget_reply (mu_smtp_t smtp, const char **pbuf);
+
+
 #define MU_SMTP_TRACE_CLR 0
 #define MU_SMTP_TRACE_SET 1
 #define MU_SMTP_TRACE_QRY 2
@@ -61,6 +65,7 @@ int mu_smtp_set_secret (mu_smtp_t smtp, mu_secret_t secret);
 int mu_smtp_get_secret (mu_smtp_t smtp, mu_secret_t *secret);
 
 int mu_smtp_capa_test (mu_smtp_t smtp, const char *capa, const char **pret);
+int mu_smtp_capa_iterator (mu_smtp_t smtp, mu_iterator_t *itr);
 int mu_smtp_starttls (mu_smtp_t smtp);
 
 int mu_smtp_mail_basic (mu_smtp_t smtp, const char *email,
diff --git a/libmailutils/url/dup.c b/libmailutils/url/dup.c
index 141463e..5b78d52 100644
--- a/libmailutils/url/dup.c
+++ b/libmailutils/url/dup.c
@@ -34,11 +34,13 @@ int
 mu_url_dup (mu_url_t old_url, mu_url_t *new_url)
 {
   int rc;
+  const char *s;
   mu_url_t url = calloc (1, sizeof (*url));
 
   if (!url)
     return ENOMEM;
-  url->name = strdup (old_url->name);
+  mu_url_sget_name (old_url, &s);
+  url->name = strdup (s);
   if (!url->name)
     {
       free (url);
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index 5fae967..1436804 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -32,6 +32,7 @@ libmu_mailer_la_SOURCES = \
  smtp.c\
  smtp_auth.c\
  smtp_capa.c\
+ smtp_capa_itr.c\
  smtp_carrier.c\
  smtp_create.c\
  smtp_data.c\
diff --git a/libproto/mailer/smtp_capa.c b/libproto/mailer/smtp_capa_itr.c
similarity index 88%
copy from libproto/mailer/smtp_capa.c
copy to libproto/mailer/smtp_capa_itr.c
index 07b99cf..25152fa 100644
--- a/libproto/mailer/smtp_capa.c
+++ b/libproto/mailer/smtp_capa_itr.c
@@ -22,13 +22,14 @@
 #include <stdlib.h>
 #include <mailutils/errno.h>
 #include <mailutils/list.h>
+#include <mailutils/iterator.h>
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 
 int
-mu_smtp_capa_test (mu_smtp_t smtp, const char *name, const char **pret)
+mu_smtp_capa_iterator (mu_smtp_t smtp, mu_iterator_t *itr)
 {
-  if (!smtp || !name)
+  if (!smtp || !itr)
     return EINVAL;
   if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
     return MU_ERR_FAILURE;
@@ -40,5 +41,5 @@ mu_smtp_capa_test (mu_smtp_t smtp, const char *name, const char **pret)
     }
   if (!MU_SMTP_FISSET (smtp, _MU_SMTP_ESMTP))
     return MU_ERR_FAILURE;
-  return mu_list_locate (smtp->capa, (void*) name, (void**)pret);
+  return mu_list_get_iterator (smtp->capa, itr);
 }
diff --git a/libproto/mailer/smtp_io.c b/libproto/mailer/smtp_io.c
index da46f77..8df32af 100644
--- a/libproto/mailer/smtp_io.c
+++ b/libproto/mailer/smtp_io.c
@@ -89,7 +89,8 @@ mu_smtp_response (mu_smtp_t smtp)
 	  smtp->flbuf = p;
 	  smtp->flsize = n;
 	}
-      memcpy (smtp->flbuf, smtp->rdbuf + 4, n - 3);
+      memcpy (smtp->flbuf, smtp->rdbuf + 4, n - 1);
+      smtp->flbuf[n - 1] = 0;
       smtp->replptr = smtp->flbuf;
 
       rc = _mu_smtp_init_mlist (smtp);
@@ -125,6 +126,22 @@ mu_smtp_response (mu_smtp_t smtp)
   return 0;
 }
     
+int
+mu_smtp_replcode (mu_smtp_t smtp, char *buf)
+{
+  if (!smtp || !buf)
+    return EINVAL;
+  strcpy (buf, smtp->replcode);
+  return 0;
+}
 
+int
+mu_smtp_sget_reply (mu_smtp_t smtp, const char **pbuf)
+{
+  if (!smtp || !pbuf)
+    return EINVAL;
+  *pbuf = smtp->replptr;
+  return 0;
+}
   
   


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Jul 28 16:57:03 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1SvE4N-00013M-8v
	for mharc-commit-mailutils@gnu.org; Sat, 28 Jul 2012 16:57:03 -0400
Received: from eggs.gnu.org ([208.118.235.92]:60423)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvE4I-000132-OZ
	for commit-mailutils@gnu.org; Sat, 28 Jul 2012 16:57:02 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvE4E-0004s1-FJ
	for commit-mailutils@gnu.org; Sat, 28 Jul 2012 16:56:58 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:56068)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvE4E-0004rx-At
	for commit-mailutils@gnu.org; Sat, 28 Jul 2012 16:56:54 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvE4C-0001dG-Ds
	for commit-mailutils@gnu.org; Sat, 28 Jul 2012 20:56:54 +0000
Date: Sat, 28 Jul 2012 20:56:52 +0000
Message-Id: <E1SvE4C-0001dG-Ds@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-626-g27ac3a5
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 34128509db514024afd85a714cb9cad1f71d2d82
X-Git-Newrev: 27ac3a545e89bd4aa357d6a624363b4e9a80b859
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, 28 Jul 2012 20:57:02 -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=27ac3a545e89bd4aa357d6a624363b4e9a80b859

The branch, master has been updated
       via  27ac3a545e89bd4aa357d6a624363b4e9a80b859 (commit)
       via  e04498e53df13127402e7c7841d024ec90f27386 (commit)
      from  34128509db514024afd85a714cb9cad1f71d2d82 (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 27ac3a545e89bd4aa357d6a624363b4e9a80b859
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Jul 28 19:58:06 2012 +0300

    Implement SMTP shell in mu.
    
    * include/mailutils/smtp.h (mu_smtp_get_reply_iterator)
    (mu_smtp_cmd,mu_smtp_test_param): New protos.
    * libproto/mailer/Makefile.am (libmu_mailer_la_SOURCES): Add
    smtp_cmd.c
    * libproto/mailer/smtp_cmd.c: New file.
    * libproto/mailer/smtp_io.c (mu_smtp_get_reply_iterator): New function.
    * libproto/mailer/smtp_param.c (mu_smtp_set_param): Accept NULL
    parameter value.
    (mu_smtp_test_param): New function.
    * mu/Makefile.am [MU_COND_SUPPORT_SMTP]: Add smtp.c to MODULES.
    (mu_SOURCES): Add getans.c, getyn.c and util.c
    * mu/getans.c: New file.
    * mu/getyn.c: New file.
    * mu/smtp.c: New file.
    * mu/util.c: New file.
    * mu/mu.h (port_from_sa): New proto.
    * mu/pop.c (port_from_sa): Move to util.c

commit e04498e53df13127402e7c7841d024ec90f27386
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Jul 28 15:16:15 2012 +0300

    Drop a superfluous dependency on libgcrypt.
    
    * am/tls.m4 (MU_CHECK_GNUTLS): Newer GNU TLS does not require
    libgcrypt. It is required only for v. 2.11 and prior versions.

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

Summary of changes:
 am/tls.m4                                   |   14 +-
 include/mailutils/smtp.h                    |    3 +
 libproto/mailer/Makefile.am                 |    1 +
 libproto/mailer/{smtp_mail.c => smtp_cmd.c} |   24 +-
 libproto/mailer/smtp_io.c                   |    8 +-
 libproto/mailer/smtp_param.c                |   53 ++-
 mh/mh.h                                     |    3 +
 mu/Makefile.am                              |   12 +-
 testsuite/fldel.c => mu/getans.c            |   60 +-
 testsuite/fldel.c => mu/getyn.c             |   64 +-
 mu/mu.h                                     |    2 +
 mu/pop.c                                    |   16 -
 mu/smtp.c                                   |  986 +++++++++++++++++++++++++++
 lib/signal.c => mu/util.c                   |   34 +-
 14 files changed, 1163 insertions(+), 117 deletions(-)
 copy libproto/mailer/{smtp_mail.c => smtp_cmd.c} (77%)
 copy testsuite/fldel.c => mu/getans.c (50%)
 copy testsuite/fldel.c => mu/getyn.c (50%)
 create mode 100644 mu/smtp.c
 copy lib/signal.c => mu/util.c (63%)

diff --git a/am/tls.m4 b/am/tls.m4
index c537625..783c63a 100644
--- a/am/tls.m4
+++ b/am/tls.m4
@@ -35,9 +35,17 @@ AC_DEFUN([MU_CHECK_GNUTLS],
                      [mu_cv_lib_gnutls=no])
      if test "$mu_cv_lib_gnutls" != "no"; then
        saved_LIBS=$LIBS
-       AC_CHECK_LIB(gcrypt, main,
-                    [TLS_LIBS="-lgcrypt"],
-                    [mu_cv_lib_gnutls=no])
+       AC_PREPROC_IFELSE(
+         [AC_LANG_PROGRAM([#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+#if GNUTLS_VERSION_NUMBER <= 0x020b00
+# error "Need gcrypt"
+#endif
+],[])],
+         [],
+	 [AC_CHECK_LIB(gcrypt, main,
+                       [TLS_LIBS="-lgcrypt"],
+                       [mu_cv_lib_gnutls=no])])
        LIBS="$LIBS $TLS_LIBS"
        AC_CHECK_LIB(gnutls, gnutls_global_init,
                     [TLS_LIBS="-lgnutls $TLS_LIBS"],
diff --git a/include/mailutils/smtp.h b/include/mailutils/smtp.h
index 6d8cdd9..5ce18d2 100644
--- a/include/mailutils/smtp.h
+++ b/include/mailutils/smtp.h
@@ -47,7 +47,9 @@ int mu_smtp_write (mu_smtp_t smtp, const char *fmt, ...) MU_PRINTFLIKE(2,3);
 
 int mu_smtp_replcode (mu_smtp_t smtp, char *buf);
 int mu_smtp_sget_reply (mu_smtp_t smtp, const char **pbuf);
+int mu_smtp_get_reply_iterator (mu_smtp_t smtp, mu_iterator_t *pitr);
 
+int mu_smtp_cmd (mu_smtp_t smtp, int argc, char **argv);
 
 #define MU_SMTP_TRACE_CLR 0
 #define MU_SMTP_TRACE_SET 1
@@ -59,6 +61,7 @@ int mu_smtp_disconnect (mu_smtp_t smtp);
 int mu_smtp_ehlo (mu_smtp_t smtp);
 int mu_smtp_set_param (mu_smtp_t smtp, int code, const char *val);
 int mu_smtp_get_param (mu_smtp_t smtp, int code, const char **param);
+int mu_smtp_test_param (mu_smtp_t smtp, int pcode);
 int mu_smtp_set_url (mu_smtp_t smtp, mu_url_t url);
 int mu_smtp_get_url (mu_smtp_t smtp, mu_url_t *purl);
 int mu_smtp_set_secret (mu_smtp_t smtp, mu_secret_t secret);
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index 1436804..e091326 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -34,6 +34,7 @@ libmu_mailer_la_SOURCES = \
  smtp_capa.c\
  smtp_capa_itr.c\
  smtp_carrier.c\
+ smtp_cmd.c\
  smtp_create.c\
  smtp_data.c\
  smtp_disconnect.c\
diff --git a/libproto/mailer/smtp_mail.c b/libproto/mailer/smtp_cmd.c
similarity index 77%
copy from libproto/mailer/smtp_mail.c
copy to libproto/mailer/smtp_cmd.c
index c10d971..1dfede9 100644
--- a/libproto/mailer/smtp_mail.c
+++ b/libproto/mailer/smtp_cmd.c
@@ -30,38 +30,32 @@
 #include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
 
+/* Send an arbitrary command */
 int
-mu_smtp_mail_basic (mu_smtp_t smtp, const char *email, const char *fmt, ...)
+mu_smtp_cmd (mu_smtp_t smtp, int argc, char **argv)
 {
-  int status;
+  int status, i;
   
   if (!smtp)
     return EINVAL;
   if (MU_SMTP_FISSET (smtp, _MU_SMTP_ERR))
     return MU_ERR_FAILURE;
-  if (smtp->state != MU_SMTP_MAIL)
-    return MU_ERR_SEQ;
-  status = mu_smtp_write (smtp, "MAIL FROM:<%s>", email);
+  status = mu_smtp_write (smtp, "%s", argv[0]);
   MU_SMTP_CHECK_ERROR (smtp, status);
-  if (fmt)
+  for (i = 1; i < argc; i++)
     {
-      va_list ap;
-
-      status = mu_smtp_write (smtp, " ");
-      va_start (ap, fmt);
-      status = mu_stream_vprintf (smtp->carrier, fmt, ap);
-      va_end (ap);
+      status = mu_smtp_write (smtp, " %s", argv[i]);
       MU_SMTP_CHECK_ERROR (smtp, status);
     }
+  
   status = mu_smtp_write (smtp, "\r\n");
   MU_SMTP_CHECK_ERROR (smtp, status);
   status = mu_smtp_response (smtp);
   MU_SMTP_CHECK_ERROR (smtp, status);
 
-  if (smtp->replcode[0] != '2')
+  if (smtp->replcode[0] > '3')
     return MU_ERR_REPLY;
-
-  smtp->state = MU_SMTP_RCPT;
+  
   return 0;
 }
 
diff --git a/libproto/mailer/smtp_io.c b/libproto/mailer/smtp_io.c
index 8df32af..5a0db27 100644
--- a/libproto/mailer/smtp_io.c
+++ b/libproto/mailer/smtp_io.c
@@ -144,4 +144,10 @@ mu_smtp_sget_reply (mu_smtp_t smtp, const char **pbuf)
   return 0;
 }
   
-  
+int
+mu_smtp_get_reply_iterator (mu_smtp_t smtp, mu_iterator_t *pitr)
+{
+  if (!smtp || !pitr)
+    return EINVAL;
+  return mu_list_get_iterator (smtp->mlrepl, pitr);
+}
diff --git a/libproto/mailer/smtp_param.c b/libproto/mailer/smtp_param.c
index e9ceb1f..cf0afb8 100644
--- a/libproto/mailer/smtp_param.c
+++ b/libproto/mailer/smtp_param.c
@@ -49,6 +49,8 @@ mu_smtp_set_param (mu_smtp_t smtp, int pcode, const char *newparam)
 	    mu_secret_password_unref (smtp->secret);
 	  mu_secret_destroy (&smtp->secret);
 	}
+      if (!newparam)
+	return 0;
       MU_SMTP_FCLR (smtp, _MU_SMTP_CLNPASS);
       return mu_secret_create (&smtp->secret, newparam, strlen (newparam));
     }
@@ -56,18 +58,28 @@ mu_smtp_set_param (mu_smtp_t smtp, int pcode, const char *newparam)
     {
       mu_url_t url;
       int rc;
-	
-      rc = mu_url_create (&url, newparam);
-      if (rc)
-	return rc;
-      mu_url_destroy (&smtp->url);
-      smtp->url = url;
+
+      if (!newparam)
+	mu_url_destroy (&smtp->url);
+      else
+	{
+	  rc = mu_url_create (&url, newparam);
+	  if (rc)
+	    return rc;
+	  mu_url_destroy (&smtp->url);
+	  smtp->url = url;
+	}
       return 0;
     }
-  
-  param = strdup (newparam);
-  if (!param)
-    return ENOMEM;
+
+  if (newparam)
+    {
+      param = strdup (newparam);
+      if (!param)
+	return ENOMEM;
+    }
+  else
+    param = NULL;
   free (smtp->param[pcode]);
   smtp->param[pcode] = param;
   return 0;
@@ -99,3 +111,24 @@ mu_smtp_get_param (mu_smtp_t smtp, int pcode, const char **pparam)
   return 0;
 }
 
+int
+mu_smtp_test_param (mu_smtp_t smtp, int pcode)
+{
+  if (!smtp)
+    return EINVAL;
+  if (pcode < 0 || pcode >= MU_SMTP_MAX_PARAM)
+    return EINVAL;
+  if (pcode == MU_SMTP_PARAM_PASSWORD)
+    {
+      if (smtp->secret)
+	return 0;
+      return MU_ERR_NOENT;
+    }
+  else if (pcode == MU_SMTP_PARAM_URL)
+    {
+      if (smtp->url)
+	return 0;
+      return MU_ERR_NOENT;
+    }
+  return smtp->param[pcode] ? 0 : MU_ERR_NOENT;
+}
diff --git a/mh/mh.h b/mh/mh.h
index b20b9eb..697bfde 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -269,6 +269,9 @@ void mh_global_save_state (void);
 int mh_interactive_mode_p (void);
 int mh_getyn (const char *fmt, ...) MU_PRINTFLIKE(1,2);
 int mh_getyn_interactive (const char *fmt, ...) MU_PRINTFLIKE(1,2);
+int mu_vgetans (const char *variants, const char *fmt, va_list ap);
+int mu_getans (const char *variants, const char *fmt, ...)
+  MU_PRINTFLIKE(2,3);
 int mh_check_folder (const char *pathname, int confirm);
 int mh_makedir (const char *p);
 
diff --git a/mu/Makefile.am b/mu/Makefile.am
index c8a7ce2..4ca4100 100644
--- a/mu/Makefile.am
+++ b/mu/Makefile.am
@@ -39,6 +39,12 @@ else
  IDLE_MODULES+=dbm.c
 endif
 
+if MU_COND_SUPPORT_SMTP
+ SMTP_C=smtp.c
+else
+ IDLE_MODULES+=smtp.c
+endif
+
 MODULES = \
  acl.c\
  cflags.c\
@@ -51,16 +57,20 @@ MODULES = \
  ldflags.c\
  logger.c\
  $(POP_C)\
- send.c\
  query.c\
+ send.c\
+ $(SMTP_C)\
  wicket.c
 
 mu_SOURCES = \
  dispatch.c\
+ getans.c\
  getarg.c\
+ getyn.c\
  mu.h\
  mu.c\
  shell.c\
+ util.c\
  verbose.c\
  $(MODULES)
 
diff --git a/testsuite/fldel.c b/mu/getans.c
similarity index 50%
copy from testsuite/fldel.c
copy to mu/getans.c
index ad5645b..8eaa66c 100644
--- a/testsuite/fldel.c
+++ b/mu/getans.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010-2012 Free Software Foundation, Inc.
+   Copyright (C) 2010, 2012 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,38 +17,44 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <mailutils/mailutils.h>
+#include "mu.h"
 
 int
-main (int argc, char **argv)
+mu_vgetans (const char *variants, const char *fmt, va_list ap)
 {
-  int rc;
-  mu_folder_t f;
-  
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s URL NAME\n", argv[0]);
-      return 1;
-    }
+  char repl[64];
 
-  mu_register_all_mbox_formats ();
-  
-  MU_ASSERT (mu_folder_create (&f, argv[1]));
-  rc = mu_folder_delete (f, argv[2]);
-  if (rc)
+  while (1)
     {
-      if (rc == ENOTEMPTY)
-	{
-	  printf ("mailbox removed, but has subfolders\n");
-	  rc = 0;
-	}
-      else
-	fprintf (stderr, "%s\n", mu_strerror (rc));
+      size_t n;
+      char *p;
+      
+      mu_stream_vprintf (mu_strout, fmt, ap);
+      mu_stream_write (mu_strout, "? ", 2, NULL);
+      mu_stream_flush (mu_strout);
+      if (mu_stream_read (mu_strin, repl, sizeof repl, &n) || n == 0)
+	return 0;
+      mu_rtrim_class (repl, MU_CTYPE_ENDLN);
+
+      p = strchr (variants, *repl);
+      if (p)
+	return *p;
+      
+      mu_stream_printf (mu_strout, _("Please answer one of [%s]: "), variants);
     }
-  mu_folder_destroy (&f);
+  return 0; /* to pacify gcc */
+}
+
+int
+mu_getans (const char *variants, const char *fmt, ...)
+{
+  va_list ap;
+  int rc;
   
-  return rc != 0;
+  va_start (ap, fmt);
+  rc = mu_vgetans (variants, fmt, ap);
+  va_end (ap);
+  return rc;
 }
+
diff --git a/testsuite/fldel.c b/mu/getyn.c
similarity index 50%
copy from testsuite/fldel.c
copy to mu/getyn.c
index ad5645b..379d7bd 100644
--- a/testsuite/fldel.c
+++ b/mu/getyn.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010-2012 Free Software Foundation, Inc.
+   Copyright (C) 2010, 2012 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,38 +17,46 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <mailutils/mailutils.h>
+#include "mu.h"
 
 int
-main (int argc, char **argv)
+mu_vgetyn (const char *fmt, va_list ap)
 {
-  int rc;
-  mu_folder_t f;
-  
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s URL NAME\n", argv[0]);
-      return 1;
-    }
+  char repl[64];
 
-  mu_register_all_mbox_formats ();
-  
-  MU_ASSERT (mu_folder_create (&f, argv[1]));
-  rc = mu_folder_delete (f, argv[2]);
-  if (rc)
+  while (1)
     {
-      if (rc == ENOTEMPTY)
-	{
-	  printf ("mailbox removed, but has subfolders\n");
-	  rc = 0;
-	}
-      else
-	fprintf (stderr, "%s\n", mu_strerror (rc));
+      int rc;
+      size_t n;
+      
+      mu_stream_vprintf (mu_strout, fmt, ap);
+      mu_stream_write (mu_strout, "? ", 2, NULL);
+      mu_stream_flush (mu_strout);
+      if (mu_stream_read (mu_strin, repl, sizeof repl, &n) || n == 0)
+	return 0;
+      mu_rtrim_class (repl, MU_CTYPE_ENDLN);
+
+      rc = mu_true_answer_p (repl);
+      
+      if (rc >= 0)
+	return rc;
+      
+      /* TRANSLATORS: See msgids "nN" and "yY". */
+      mu_stream_printf (mu_strout, "%s", _("Please answer yes or no: "));
     }
-  mu_folder_destroy (&f);
-  
-  return rc != 0;
+  return 0; /* to pacify gcc */
 }
+
+int
+mu_getyn (const char *fmt, ...)
+{
+  va_list ap;
+  int rc;
+
+  va_start (ap, fmt);
+  rc = mu_vgetyn (fmt, ap);
+  va_end (ap);
+  return rc;
+}
+  
diff --git a/mu/mu.h b/mu/mu.h
index 6b69c32..2c33f4b 100644
--- a/mu/mu.h
+++ b/mu/mu.h
@@ -42,6 +42,8 @@ int mu_help (void);
 mutool_action_t dispatch_find_action (const char *name);
 char *dispatch_docstring (const char *text);
 
+int port_from_sa (struct mu_sockaddr *sa);
+
 
 #define VERBOSE_MASK(n) (1<<((n)+1))
 #define SET_VERBOSE_MASK(n) (shell_verbose_flags |= VERBOSE_MASK (n))
diff --git a/mu/pop.c b/mu/pop.c
index fd19168..d374bfc 100644
--- a/mu/pop.c
+++ b/mu/pop.c
@@ -473,22 +473,6 @@ com_disconnect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
 }
 
 static int
-port_from_sa (struct mu_sockaddr *sa)
-{
-  switch (sa->addr->sa_family)
-    {
-    case AF_INET:
-      return ntohs (((struct sockaddr_in *)sa->addr)->sin_port);
-
-#ifdef MAILUTILS_IPV6
-    case AF_INET6:
-      return ntohs (((struct sockaddr_in6 *)sa->addr)->sin6_port);
-#endif
-    }
-  return 0;
-}
-
-static int
 com_connect (int argc, char **argv)
 {
   int status;
diff --git a/mu/smtp.c b/mu/smtp.c
new file mode 100644
index 0000000..5fe1e10
--- /dev/null
+++ b/mu/smtp.c
@@ -0,0 +1,986 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010-2012 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <mailutils/cctype.h>
+#include <mailutils/mailutils.h>
+#include <mailutils/smtp.h>
+#include <argp.h>
+#include "mu.h"
+
+static char smtp_doc[] = N_("mu smtp - run a SMTP session.");
+char smtp_docstring[] = N_("run a SMTP session");
+static char smtp_args_doc[] = "";
+
+static struct argp_option smtp_options[] = {
+  { NULL }
+};
+
+static error_t
+smtp_parse_opt (int key, char *arg, struct argp_state *state)
+{
+  switch (key)
+    {
+    default:
+      return ARGP_ERR_UNKNOWN;
+    }
+  return 0;
+}
+
+static struct argp smtp_argp = {
+  smtp_options,
+  smtp_parse_opt,
+  smtp_args_doc,
+  smtp_doc,
+  NULL,
+  NULL,
+  NULL
+};
+
+enum smtp_session_status
+  {
+    smtp_session_disconnected,
+    smtp_session_connected,
+    smtp_session_logged_in
+  };
+
+static enum smtp_session_status smtp_session_status;
+static int connect_argc;
+static char **connect_argv;
+
+/* Host we are connected to. */
+#define host connect_argv[0]
+static int port = 25;
+
+static char *sender;
+static mu_list_t recipients;
+
+static char *msgfile;
+static int temp_msgfile;
+static mu_smtp_t smtp;
+
+const char *
+smtp_session_str (enum smtp_session_status stat)
+{
+  switch (stat)
+    {
+    case smtp_session_disconnected:
+      return "disconnected";
+      
+    case smtp_session_connected:
+      return "connected";
+      
+    case smtp_session_logged_in:
+      return "logged in";
+    }
+  return "unknown";
+}
+
+static void
+smtp_prompt_env ()
+{
+  const char *value;
+  
+  if (!mutool_prompt_env)
+    mutool_prompt_env = mu_calloc (2*7 + 1, sizeof(mutool_prompt_env[0]));
+
+  mutool_prompt_env[0] = "user";
+  mutool_prompt_env[1] = "[nouser]";
+  if (smtp_session_status == smtp_session_logged_in &&
+      mu_smtp_get_param (smtp, MU_SMTP_PARAM_USERNAME, &value) == 0)
+    mutool_prompt_env[1] = (char*) value;
+
+  mutool_prompt_env[2] = "host"; 
+  mutool_prompt_env[3] = (smtp_session_status != smtp_session_disconnected) ?
+                           host : "[nohost]";
+
+  mutool_prompt_env[4] = "program-name";
+  mutool_prompt_env[5] = (char*) mu_program_name;
+
+  mutool_prompt_env[6] = "canonical-program-name";
+  mutool_prompt_env[7] = "mu";
+
+  mutool_prompt_env[8] = "package";
+  mutool_prompt_env[9] = PACKAGE;
+
+  mutool_prompt_env[10] = "version";
+  mutool_prompt_env[11] = PACKAGE_VERSION;
+
+  mutool_prompt_env[12] = "status";
+  mutool_prompt_env[13] = (char*) smtp_session_str (smtp_session_status);
+
+  mutool_prompt_env[14] = NULL;
+}
+
+static void
+smtp_set_verbose (void)
+{
+  if (smtp)
+    {
+      if (QRY_VERBOSE ())
+	mu_smtp_trace (smtp, MU_SMTP_TRACE_SET);
+      else
+	mu_smtp_trace (smtp, MU_SMTP_TRACE_CLR);
+    }
+}
+
+static void
+smtp_set_verbose_mask (void)
+{
+  if (smtp)
+    {
+      mu_smtp_trace_mask (smtp, QRY_VERBOSE_MASK (MU_XSCRIPT_SECURE)
+			          ? MU_SMTP_TRACE_SET : MU_SMTP_TRACE_CLR,
+			      MU_XSCRIPT_SECURE);
+      mu_smtp_trace_mask (smtp, QRY_VERBOSE_MASK (MU_XSCRIPT_PAYLOAD)
+			          ? MU_SMTP_TRACE_SET : MU_SMTP_TRACE_CLR,
+			      MU_XSCRIPT_PAYLOAD);
+    }
+}
+
+static int
+com_verbose (int argc, char **argv)
+{
+  return shell_verbose (argc, argv,
+			smtp_set_verbose, smtp_set_verbose_mask);
+}
+
+static int
+smtp_error_handler (int rc)
+{
+  if (rc == 0 || rc == MU_ERR_REPLY)
+    {
+      char code[4];
+      const char *repl;
+      
+      mu_smtp_replcode (smtp, code);
+      mu_smtp_sget_reply (smtp, &repl);
+      mu_printf ("%s %s\n", code, repl);
+    }
+  return rc;
+}
+
+static int
+com_disconnect (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
+{
+  if (smtp)
+    {
+      mu_smtp_disconnect (smtp);
+      mu_smtp_destroy (&smtp);
+      smtp = NULL;
+      
+      mu_argcv_free (connect_argc, connect_argv);
+      connect_argc = 0;
+      connect_argv = NULL;
+      smtp_session_status = smtp_session_disconnected;
+      smtp_prompt_env ();
+    }
+  return 0;
+}
+
+static int
+com_connect (int argc, char **argv)
+{
+  int status;
+  int tls = 0;
+  int i = 1;
+  int n;
+  
+  for (i = 1; i < argc; i++)
+    {
+      if (strcmp (argv[i], "-tls") == 0)
+	{
+#ifdef WITH_TLS
+	  tls = 1;
+#else
+	  mu_error ("TLS not supported");
+	  return 0;
+#endif
+	}
+      else
+	break;
+    }
+
+  argc -= i;
+  argv += i;
+  
+  if (smtp_session_status != smtp_session_disconnected)
+    com_disconnect (0, NULL);
+  
+  status = mu_smtp_create (&smtp);
+  if (status == 0)
+    {
+      mu_stream_t tcp;
+      struct mu_sockaddr *sa;
+      struct mu_sockaddr_hints hints;
+
+      if (QRY_VERBOSE ())
+	{
+	  smtp_set_verbose ();
+	  smtp_set_verbose_mask ();
+	}
+
+      memset (&hints, 0, sizeof (hints));
+      hints.flags = MU_AH_DETECT_FAMILY;
+      hints.port = tls ? 465 : 25;
+      hints.protocol = IPPROTO_TCP;
+      hints.socktype = SOCK_STREAM;
+      status = mu_sockaddr_from_node (&sa, argv[0], argv[1], &hints);
+      if (status == 0)
+	{
+	  n = port_from_sa (sa);
+	  status = mu_tcp_stream_create_from_sa (&tcp, sa, NULL, 0);
+	  if (status)
+	    mu_sockaddr_free (sa);
+	}
+      if (status == 0)
+	{
+#ifdef WITH_TLS
+	  if (tls)
+	    {
+	      mu_stream_t tlsstream;
+	      
+	      status = mu_tls_client_stream_create (&tlsstream, tcp, tcp, 0);
+	      mu_stream_unref (tcp);
+	      if (status)
+		{
+		  mu_error ("cannot create TLS stream: %s",
+			    mu_strerror (status));
+		  return 0;
+		}
+	      tcp = tlsstream;
+	    }
+#endif
+	  mu_smtp_set_carrier (smtp, tcp);
+	  status = smtp_error_handler (mu_smtp_open (smtp));
+	}
+      else
+	{
+	  mu_smtp_destroy (&smtp);
+	  smtp = NULL;
+	}
+    }
+
+  if (status)
+    mu_error ("Failed to create smtp: %s", mu_strerror (status));
+  else
+    {
+      connect_argc = argc;
+      connect_argv = mu_calloc (argc, sizeof (*connect_argv));
+      for (i = 0; i < argc; i++)
+	connect_argv[i] = mu_strdup (argv[i]);
+      connect_argv[i] = NULL;
+      port = n;
+      smtp_session_status = smtp_session_connected;
+
+      smtp_prompt_env ();
+    }
+
+  /* Provide a default URL.  Authentication functions require it, see comment
+     in smtp_auth.c:119. */
+  mu_smtp_set_param (smtp, MU_SMTP_PARAM_URL, "smtp://");
+  
+  return status;
+}
+
+static int
+com_capa (int argc, char **argv)
+{
+  mu_iterator_t iterator = NULL;
+  int status = 0;
+  int i = 1;
+  
+  if (i < argc)
+    {
+      for (; i < argc; i++)
+	{
+	  const char *elt;
+	  int rc = mu_smtp_capa_test (smtp, argv[i], &elt);
+	  switch (rc)
+	    {
+	    case 0:
+	      if (*elt)
+		mu_printf ("%s: %s\n", argv[i], elt);
+	      else
+		mu_printf ("%s is set\n", argv[i]);
+	      break;
+
+	    case MU_ERR_NOENT:
+	      mu_printf ("%s is not set\n", argv[i]);
+	      break;
+
+	    default:
+	      return smtp_error_handler (rc);
+	    }
+	}
+    }
+  else
+    {
+      status = mu_smtp_capa_iterator (smtp, &iterator);
+
+      if (status == 0)
+	{
+	  for (mu_iterator_first (iterator);
+	       !mu_iterator_is_done (iterator); mu_iterator_next (iterator))
+	    {
+	      char *capa = NULL;
+	      mu_iterator_current (iterator, (void **) &capa);
+	      mu_printf ("CAPA: %s\n", capa ? capa : "");
+	    }
+	  mu_iterator_destroy (&iterator);
+	}
+    }
+  return status;
+}
+
+static int
+com_ehlo (int argc, char **argv)
+{
+  if (argc == 1)
+    {
+      if (mu_smtp_test_param (smtp, MU_SMTP_PARAM_DOMAIN))
+	{
+	  mu_error (_("no domain set"));
+	  return 0;
+	}
+    }
+  else
+    mu_smtp_set_param (smtp, MU_SMTP_PARAM_DOMAIN, argv[1]);
+  return com_capa (1, argv);
+}
+
+static int
+com_rset (int argc, char **argv)
+{
+  return smtp_error_handler (mu_smtp_rset (smtp));
+}
+
+static int
+com_quit (int argc, char **argv)
+{
+  int status = 0;
+  if (smtp)
+    {
+      if (smtp_error_handler (mu_smtp_quit (smtp)) == 0)
+	{
+	  status = com_disconnect (0, NULL);
+	}
+      else
+	{
+	  mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
+	}
+    }
+  else
+    mu_printf ("Try 'exit' to leave %s\n", mu_program_name);
+  return status;
+}
+
+static int
+com_from (int argc, char **argv)
+{
+  if (argc == 1)
+    {
+      if (!sender)
+	{
+	  mu_error (_("no sender address"));
+	  return 0;
+	}
+    }
+  else
+    {
+      free (sender);
+      sender = mu_strdup (argv[1]);
+    }
+  return smtp_error_handler (mu_smtp_mail_basic (smtp, sender, NULL)); 
+}
+
+static int
+send_rcpt_to (void *item, void *data)
+{
+  return smtp_error_handler (mu_smtp_rcpt_basic (smtp, (char*) item, NULL));
+}
+
+static int
+com_to (int argc, char **argv)
+{
+  int rc;
+
+  if (argc == 1)
+    {
+      if (mu_list_is_empty (recipients))
+	{
+	  mu_error (_("no recipients"));
+	  return 1;
+	}
+      mu_list_foreach (recipients, send_rcpt_to, NULL);
+      rc = 0;
+    }
+  else
+    {
+      if (!recipients)
+	mu_list_create (&recipients);
+      mu_list_set_destroy_item (recipients, mu_list_free_item);
+      rc = smtp_error_handler (mu_smtp_rcpt_basic (smtp, argv[1], NULL));
+      if (rc == 0)
+	mu_list_append (recipients, mu_strdup (argv[1]));
+    }
+  return rc;
+}
+
+static int
+edit (const char *file)
+{
+  char *ed;
+  char *edv[3];
+  int rc, status;
+  
+  ed = getenv ("VISUAL");
+  if (!ed)
+    {
+      ed = getenv ("EDITOR");
+      if (!ed)
+	ed = "/bin/ed";
+    }
+  
+  edv[0] = ed;
+  edv[1] = (char*) file;
+  edv[2] = NULL;
+
+  rc = mu_spawnvp (edv[0], edv, &status);
+  if (rc)
+    mu_diag_funcall (MU_DIAG_ERROR, "mu_spawnvp", edv[0], rc);
+  return rc;
+}
+
+struct rcptout
+{
+  mu_stream_t str;
+  int n;
+};
+
+static int
+print_rcpt (void *item, void *data)
+{
+  struct rcptout *p = data;
+  if (p->n++)
+    mu_stream_write (p->str, ", ", 2, NULL);
+  mu_stream_printf (p->str, "%s", (char *)item);
+  return 0;
+}
+    
+static int
+edit_file (const char *fname, int inplace)
+{
+  int rc;
+  
+  if (fname && !inplace)
+    {
+      mu_stream_t istr, ostr;
+      
+      rc = mu_file_stream_create (&istr, fname, MU_STREAM_READ|MU_STREAM_SEEK);
+      if (rc == 0)
+	{
+	  char *tempfile = mu_tempname (NULL);
+	  rc = mu_file_stream_create (&ostr, tempfile,
+				      MU_STREAM_CREAT|MU_STREAM_WRITE);
+	  if (rc)
+	    {
+	      free (tempfile);
+	      mu_error (_("cannot create temporary file: %s"),
+			mu_strerror (rc));
+	      return -1;
+	    }
+	  rc = mu_stream_copy (ostr, istr, 0, NULL);
+	  if (rc)
+	    {
+	      unlink (tempfile);	
+	      free (tempfile);
+	      mu_error (_("error copying to temporary file: %s"),
+			mu_strerror (rc));
+	      return -1;
+	    }
+	  mu_stream_unref (ostr);
+	  free (msgfile);
+	  msgfile = tempfile;
+	  temp_msgfile = 1;
+	}
+      else if (rc != ENOENT)
+	{
+	  mu_diag_funcall (MU_DIAG_ERROR, "mu_file_stream_create", fname, rc);
+	  return 1;
+	}
+      mu_stream_unref (istr);
+    }
+  else if (!fname)
+    {
+      struct rcptout rcptout;
+      
+      if (temp_msgfile)
+	unlink (msgfile);
+      free (msgfile);
+      msgfile = mu_tempname (NULL);
+      temp_msgfile = 1;
+
+      rc = mu_file_stream_create (&rcptout.str, msgfile,
+				  MU_STREAM_CREAT|MU_STREAM_WRITE);
+      if (rc)
+	{
+	  mu_error (_("cannot open temporary file for writing: %s"),
+		    mu_strerror (rc));
+	  return 1;
+	}
+      rcptout.n = 0;
+      if (sender)
+	mu_stream_printf (rcptout.str, "From: %s\n", sender);
+      else
+	mu_stream_printf (rcptout.str, "From: \n");
+      mu_stream_printf (rcptout.str, "To: ");
+      mu_list_foreach (recipients, print_rcpt, &rcptout);
+      mu_stream_write (rcptout.str, "\n", 1, NULL);
+      mu_stream_printf (rcptout.str, "Subject: \n\n");
+      mu_stream_unref (rcptout.str);
+    }
+  else
+    {
+      free (msgfile);
+      msgfile = mu_strdup (fname);
+      temp_msgfile = 0;
+    }
+	  
+  do
+    {
+      if (edit (msgfile))
+	return 1;
+    }
+  while ((rc = mu_getans ("seqSEQ", _("What now: [s]end, [e]dit, [q]uit")))
+	 == 'e' || rc == 'E');
+  
+  return rc == 'q' || rc == 'Q';
+}
+
+static int
+com_send (int argc, char **argv)
+{
+  int rc;
+  mu_stream_t instr;
+  
+  if (argc == 1)
+    {
+      if (msgfile)
+	{
+	  switch (mu_getans ("rReEdD",
+			     _("Previous message exists. "
+			       "What now: [r]euse, [e]dit, "
+			       "[u]se as a template or\n"
+			       "[d]rop and start from scratch")))
+	    {
+	    case 'r':
+	    case 'R':
+	      rc = 0;
+	      break;
+
+	    case 'e':
+	    case 'E':
+	      rc = edit_file (msgfile, 1);
+	      break;
+
+	    case 'd':
+	    case 'D':
+	      if (temp_msgfile)
+		unlink (msgfile);
+	      free (msgfile);
+	      msgfile = NULL;
+	      temp_msgfile = 0;
+	      rc = edit_file (NULL, 0);
+	      break;
+
+	    case 'u':
+	    case 'U':
+	      rc = edit_file (msgfile, 0);
+	    }
+	}
+      else
+	rc = edit_file (NULL, 0);
+      if (rc)
+	return 0;
+    }
+  else
+    {
+      if (temp_msgfile)
+	unlink (msgfile);
+      free (msgfile);
+      msgfile = NULL;
+      temp_msgfile = 0;
+      msgfile = mu_strdup (argv[1]);
+    }
+  
+  rc = mu_file_stream_create (&instr, msgfile, MU_STREAM_READ|MU_STREAM_SEEK);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_file_stream_create", msgfile, rc);
+      return 1;
+    }
+
+  rc = mu_smtp_send_stream (smtp, instr);
+  mu_stream_unref (instr);
+  
+  if (rc)
+    smtp_error_handler (rc);
+  else
+    rc = smtp_error_handler (mu_smtp_dot (smtp));
+  
+  return rc;
+}
+
+static int
+com_starttls (int argc, char **argv)
+{
+  if (mu_smtp_capa_test (smtp, "STARTTLS", NULL) == 0)
+    return smtp_error_handler (mu_smtp_starttls (smtp));
+  else
+    mu_error (_("remote party does not offer STARTTLS"));
+  return 1;
+}
+
+static int
+com_auth (int argc, char **argv)
+{
+  int rc, i;
+
+  rc = mu_smtp_clear_auth_mech (smtp);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_clear_auth_mech", NULL, rc);
+      return MU_ERR_FAILURE;
+    }
+  for (i = 1; i < argc; i++)
+    if ((rc = mu_smtp_add_auth_mech (smtp, argv[1])))
+      {
+	mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_add_auth_mech", NULL, rc);
+	return MU_ERR_FAILURE;
+      }
+
+  rc = mu_smtp_auth (smtp);
+	
+  switch (rc)
+    {
+    case 0:
+      smtp_session_status = smtp_session_logged_in;
+      break;
+      
+    case ENOSYS:
+      mu_error (_("authentication not implemented"));
+      break;
+      
+    case MU_ERR_NOENT:
+      mu_error (_("no suitable authentication mechanism found"));
+      break;
+
+    default:
+      smtp_error_handler (rc);
+      return rc;
+    }
+  return 0;
+}
+
+static struct mu_kwd paramtab[] = {
+  { "domain",      MU_SMTP_PARAM_DOMAIN },   
+  { "username",    MU_SMTP_PARAM_USERNAME }, 
+  { "password",    MU_SMTP_PARAM_PASSWORD }, 
+  { "service",     MU_SMTP_PARAM_SERVICE },
+  { "realm",       MU_SMTP_PARAM_REALM },    
+  { "host",        MU_SMTP_PARAM_HOST },
+  { "url",         MU_SMTP_PARAM_URL },
+  { NULL }
+};
+
+static int
+get_param (int param, char *prompt, char **retval)
+{
+  int rc;
+  
+  if (param == MU_SMTP_PARAM_PASSWORD)
+    {
+      rc = mu_getpass (mu_strin, mu_strout, prompt, retval);
+      if (rc)
+	mu_diag_funcall (MU_DIAG_ERROR, "mu_getpass", NULL, rc);
+    }
+  else
+    {
+      char *buf = NULL;
+      size_t size = 0;
+      rc = mu_stream_write (mu_strout, prompt, strlen (prompt), NULL);
+      if (rc)
+	return rc;
+      mu_stream_flush (mu_strout);
+      rc = mu_stream_getline (mu_strin, &buf, &size, NULL);
+      if (rc == 0)
+	{
+	  mu_rtrim_cset (buf, "\n");
+	  *retval  = buf;
+	}
+    }
+  return rc;
+}
+
+static int
+com_set (int argc, char **argv)
+{
+  int param, i, rc;
+  
+  for (i = 1; i < argc; i += 2)
+    {
+      if (mu_kwd_xlat_name (paramtab, argv[i], &param))
+	{
+	  mu_error (_("unrecognized parameter: %s"), argv[i]);
+	  continue;
+	}
+      if (i + 1 < argc)
+	{
+	  rc = mu_smtp_set_param (smtp, param, argv[i+1]);
+	  if (rc)
+	    mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_set_param", argv[i], rc);
+	}
+      else
+	{
+	  char *prompt, *value;
+	  mu_asprintf (&prompt, "%s: ", argv[i]);
+	  rc = get_param (param, prompt, &value);
+	  free (prompt);
+	  if (rc)
+	    mu_error (_("error reading value: %s"), mu_strerror (rc));
+	  else
+	    {
+	      rc = mu_smtp_set_param (smtp, param, value);
+	      if (param == MU_SMTP_PARAM_PASSWORD)
+		memset (value, 0, strlen (value));
+	      if (rc)
+		mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_set_param", argv[i],
+				 rc);
+	      free (value);
+	    }
+	}
+    }
+  return 0;
+}
+
+static int
+com_clear (int argc, char **argv)
+{
+  int param, i, rc;
+
+  if (argc > 1)
+    {
+      for (i = 1; i < argc; i++)
+	{
+	  if (mu_kwd_xlat_name (paramtab, argv[i], &param))
+	    {
+	      mu_error (_("unrecognized parameter: %s"), argv[i]);
+	      continue;
+	    }
+	  rc = mu_smtp_set_param (smtp, param, NULL);
+	  if (rc)
+	    mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_set_param", argv[i], rc);
+	}
+    }
+  else
+    {
+      for (i = 0; paramtab[i].name; i++)
+	{
+	  rc = mu_smtp_set_param (smtp, paramtab[i].tok, NULL);
+	  if (rc)
+	    mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_set_param",
+			     paramtab[i].name, rc);
+	}
+    }
+  return 0;
+}
+
+static int
+com_list_param (int argc, char **argv)
+{
+  int param, i, rc;
+  const char *value;
+  
+  if (argc > 1)
+    {
+      for (i = 1; i < argc; i++)
+	{
+	  if (mu_kwd_xlat_name (paramtab, argv[i], &param))
+	    {
+	      mu_error (_("unrecognized parameter: %s"), argv[i]);
+	      continue;
+	    }
+	  rc = mu_smtp_get_param (smtp, param, &value);
+	  if (rc)
+	    mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_set_param", argv[i], rc);
+	  else if (value)
+	    mu_printf ("%s = %s\n", argv[i], value);
+	  else
+	    mu_printf (_("%s not set\n"), argv[i]);
+	}
+    }
+  else
+    {
+      for (i = 0; paramtab[i].name; i++)
+	{
+	  rc = mu_smtp_get_param (smtp, paramtab[i].tok, &value);
+	  if (rc)
+	    mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_set_param",
+			     paramtab[i].name, rc);
+	  else if (value)
+	    mu_printf ("%s = %s\n", paramtab[i].name, value);
+	  else
+	    mu_printf (_("%s not set\n"), paramtab[i].name);
+	}
+    }
+  return 0;
+}
+
+static int
+com_smtp_command (int argc, char **argv)
+{
+  int rc;
+  mu_iterator_t itr;
+  
+  rc = mu_smtp_cmd (smtp, argc - 1, argv + 1);
+  smtp_error_handler (rc);
+  if (rc)
+    return rc;
+  rc = mu_smtp_get_reply_iterator (smtp, &itr);
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_smtp_get_reply_iterator", NULL, rc);
+      return 1;
+    }
+
+  for (mu_iterator_first (itr);
+       !mu_iterator_is_done (itr); mu_iterator_next (itr))
+    {
+      char *str = NULL;
+      mu_iterator_current (itr, (void **) &str);
+      mu_printf ("%s\n", str);
+    }
+  mu_iterator_destroy (&itr);
+  return 0;
+}
+
+struct mutool_command smtp_comtab[] = {
+  { "connect",    1, 4, 0, com_connect,
+    /* TRANSLATORS: -tls is a keyword. */
+    N_("[-tls] HOSTNAME [PORT]"),
+    N_("open connection") },
+
+  { "set",        2, -1, 0, com_set,
+    N_("PARAM [ARG...]"),
+    N_("Set connection parameter") },
+  { "clear",      1, -1, 0, com_clear,
+    N_("[PARAM...]"),
+    N_("Clear connection parameters") },
+  
+  { "list",       1, -1, 0, com_list_param,
+    N_("[PARAM...]"),
+    N_("List connection parameters") },
+    
+  { "auth",       2, -1, 0, com_auth,
+    N_("MECH [MECH...]"),
+    N_("Authenticate") },
+  
+  { "ehlo",       1, 2, 0, com_ehlo,
+    N_("[DOMAIN]"),
+    N_("Greet the server") },
+
+  { "capa",       1, -1, 0, com_capa,
+    N_("[NAME...]"),
+    N_("list server capabilities") },
+
+  { "starttls",   1, 1, 0, com_starttls,
+    NULL,
+    N_("initiate encrypted connection") },
+  
+  { "rset",       1, 1, 0, com_rset,
+    NULL,
+    N_("reset the session state") },
+
+  { "from",       1, 2, 0, com_from,
+    N_("[EMAIL]"),
+    N_("set sender email") },
+  
+  { "to",       1, 2, 0, com_to,
+    N_("[EMAIL]"),
+    N_("set recipient email") },
+
+  { "send",     1, 2, 0, com_send,
+    N_("[FILE]"),
+    N_("send message") },
+
+  { "smtp",     2, -1, 0, com_smtp_command,
+    N_("COMMAND [ARGS...]"),
+    N_("send an arbitrary COMMAND") },
+
+  { "quit",       1, 1, 0, com_quit,
+    NULL,
+    N_("quit the session") },
+  
+  { "verbose",    1, 4, 0, com_verbose,
+    "[on|off|mask|unmask] [secure [payload]]",
+    N_("control the protocol tracing") },
+
+  { NULL }
+};  
+
+int
+mutool_smtp (int argc, char **argv)
+{
+  int index;
+  
+  mu_registrar_record (mu_smtp_record);
+  mu_registrar_record (mu_smtps_record);
+  
+  if (argp_parse (&smtp_argp, argc, argv, 0, &index, NULL))
+    return 1;
+
+  argc -= index;
+
+  if (argc)
+    {
+      mu_error (_("bad arguments"));
+      return 1;
+    }
+  
+  mutool_shell_prompt = mu_strdup ("smtp> ");
+  smtp_prompt_env ();
+  mutool_shell ("smtp", smtp_comtab);
+
+  if (temp_msgfile)
+    unlink (msgfile);
+
+  return 0;
+}
+
+/*
+  MU Setup: smtp
+  mu-handler: mutool_smtp
+  mu-docstring: smtp_docstring
+  End MU Setup:
+*/
diff --git a/lib/signal.c b/mu/util.c
similarity index 63%
copy from lib/signal.c
copy to mu/util.c
index 6c18608..c4b0d09 100644
--- a/lib/signal.c
+++ b/mu/util.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2008, 2010-2012 Free Software Foundation, Inc.
+   Copyright (C) 2010-2012 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
@@ -14,26 +14,28 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
+#if defined(HAVE_CONFIG_H)
 # include <config.h>
 #endif
+
 #include <stdlib.h>
-#include <signal.h>
+#include <arpa/inet.h>
+#include <mailutils/mailutils.h>
+#include "mu.h"
 
-void
-mu_set_signals (RETSIGTYPE (*handler) (int signo), int *sigv, int sigc)
+int
+port_from_sa (struct mu_sockaddr *sa)
 {
-  int i;
-  struct sigaction act;
-
-  act.sa_flags = 0;
-  sigemptyset (&act.sa_mask);
-  for (i = 0; i < sigc; i++)
-    sigaddset (&act.sa_mask, i);
-      
-  for (i = 0; i < sigc; i++)
+  switch (sa->addr->sa_family)
     {
-      act.sa_handler = handler;
-      sigaction (sigv[i], &act, NULL);
+    case AF_INET:
+      return ntohs (((struct sockaddr_in *)sa->addr)->sin_port);
+
+#ifdef MAILUTILS_IPV6
+    case AF_INET6:
+      return ntohs (((struct sockaddr_in6 *)sa->addr)->sin6_port);
+#endif
     }
+  return 0;
 }
+


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Jul 29 07:53:29 2012
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1SvS3t-0000DW-I3
	for mharc-commit-mailutils@gnu.org; Sun, 29 Jul 2012 07:53:29 -0400
Received: from eggs.gnu.org ([208.118.235.92]:40937)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvS3p-0000D2-ET
	for commit-mailutils@gnu.org; Sun, 29 Jul 2012 07:53:28 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvS3m-0006Hb-Bk
	for commit-mailutils@gnu.org; Sun, 29 Jul 2012 07:53:25 -0400
Received: from vcs.savannah.gnu.org ([140.186.70.72]:42815)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvS3m-0006HX-7b
	for commit-mailutils@gnu.org; Sun, 29 Jul 2012 07:53:22 -0400
Received: from gray by vcs.savannah.gnu.org with local (Exim 4.72)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1SvS3j-0004D4-UP
	for commit-mailutils@gnu.org; Sun, 29 Jul 2012 11:53:21 +0000
Date: Sun, 29 Jul 2012 11:53:21 +0000
Message-Id: <E1SvS3j-0004D4-UP@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-627-g6e2a375
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 27ac3a545e89bd4aa357d6a624363b4e9a80b859
X-Git-Newrev: 6e2a37582ae89b43438952059412ea4a994d546c
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, 29 Jul 2012 11:53:28 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=6e2a37582ae89b43438952059412ea4a994d546c

The branch, master has been updated
       via  6e2a37582ae89b43438952059412ea4a994d546c (commit)
      from  27ac3a545e89bd4aa357d6a624363b4e9a80b859 (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 6e2a37582ae89b43438952059412ea4a994d546c
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Jul 29 14:06:18 2012 +0300

    Port 0b1e16bea to imap4d
    
    * imap4d/imap4d.c (tls_required): Remove.
    (tls_mode): New variable.
    (imap4d_srv_config) <tls>: Remove.
    (imap4d_srv_config) <tls_mode>: New member.
    (imap4d_srv_param): Change the definition of the "tls" statement.
    Mark "tls-required" as deprecated.
    (imap4d_mainloop): Change type of the tls argument.
    Initialize session and pass it to each handler.
    * imap4d/imap4d.h (imap4d_session): New struct.
    (imap4d_command) <func>: Change signature. All uses changed.
    (tls_mode): New enum.
    (tls_required): Remove.
    (tls_available): New global.
    * imap4d/io.c (io_setio): Don't call tls_encryption_on, leave it to
    the caller.
    * imap4d/login.c (imap4d_login): Use session.
    * imap4d/starttls.c (tls_available): Global. Present even if !WITH_TLS
    (tls_encryption_on): Change signature. All callers updated.

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

Summary of changes:
 imap4d/append.c       |    3 +-
 imap4d/authenticate.c |    3 +-
 imap4d/capability.c   |    3 +-
 imap4d/check.c        |    3 +-
 imap4d/close.c        |    6 ++-
 imap4d/copy.c         |    3 +-
 imap4d/create.c       |    3 +-
 imap4d/delete.c       |    3 +-
 imap4d/examine.c      |    3 +-
 imap4d/expunge.c      |    3 +-
 imap4d/fetch.c        |    3 +-
 imap4d/id.c           |    3 +-
 imap4d/idle.c         |    3 +-
 imap4d/imap4d.c       |  106 ++++++++++++++++++++++++++++++++++++-------
 imap4d/imap4d.h       |  118 ++++++++++++++++++++++++++++++++++--------------
 imap4d/io.c           |    1 -
 imap4d/list.c         |    3 +-
 imap4d/login.c        |    5 +-
 imap4d/logout.c       |    3 +-
 imap4d/lsub.c         |    3 +-
 imap4d/namespace.c    |    3 +-
 imap4d/noop.c         |    3 +-
 imap4d/rename.c       |    3 +-
 imap4d/search.c       |    3 +-
 imap4d/select.c       |    3 +-
 imap4d/starttls.c     |   12 +++--
 imap4d/status.c       |    3 +-
 imap4d/store.c        |    3 +-
 imap4d/subscribe.c    |    3 +-
 imap4d/uid.c          |    3 +-
 imap4d/unsubscribe.c  |    3 +-
 imap4d/util.c         |    4 +-
 32 files changed, 237 insertions(+), 90 deletions(-)

diff --git a/imap4d/append.c b/imap4d/append.c
index 365c246..897c673 100644
--- a/imap4d/append.c
+++ b/imap4d/append.c
@@ -195,7 +195,8 @@ imap4d_append0 (mu_mailbox_t mbox, int flags, char *date_time, char *text,
 
 /* APPEND mbox [(flags)] [date_time] message_literal */
 int
-imap4d_append (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_append (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int i;
   char *mboxname;
diff --git a/imap4d/authenticate.c b/imap4d/authenticate.c
index 3cec356..1dbe120 100644
--- a/imap4d/authenticate.c
+++ b/imap4d/authenticate.c
@@ -90,7 +90,8 @@ imap4d_auth_capability ()
 */
 
 int
-imap4d_authenticate (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_authenticate (struct imap4d_session *session,
+		     struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *auth_type;
   struct imap4d_auth adata;
diff --git a/imap4d/capability.c b/imap4d/capability.c
index cb47c67..0e62350 100644
--- a/imap4d/capability.c
+++ b/imap4d/capability.c
@@ -68,7 +68,8 @@ print_capa (void *item, void *data)
 }
 
 int
-imap4d_capability (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_capability (struct imap4d_session *session,
+	           struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/check.c b/imap4d/check.c
index 6acb7b5..548378f 100644
--- a/imap4d/check.c
+++ b/imap4d/check.c
@@ -29,7 +29,8 @@
 */
 
 int
-imap4d_check (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_check (struct imap4d_session *session,
+              struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/close.c b/imap4d/close.c
index 47e2822..7fb42d1 100644
--- a/imap4d/close.c
+++ b/imap4d/close.c
@@ -77,7 +77,8 @@ imap4d_close0 (struct imap4d_command *command, imap4d_tokbuf_t tok,
       EXPUNGE responses are sent. */
 
 int
-imap4d_close (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_close (struct imap4d_session *session,
+              struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   return imap4d_close0 (command, tok, 1);
 }
@@ -101,7 +102,8 @@ imap4d_close (struct imap4d_command *command, imap4d_tokbuf_t tok)
       selected mailbox.
 */
 int
-imap4d_unselect (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_unselect (struct imap4d_session *session,
+                 struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   return imap4d_close0 (command, tok, 0);
 }
diff --git a/imap4d/copy.c b/imap4d/copy.c
index 12ad324..10c0607 100644
--- a/imap4d/copy.c
+++ b/imap4d/copy.c
@@ -34,7 +34,8 @@
  */
 
 int
-imap4d_copy (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_copy (struct imap4d_session *session,
+             struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *text;
diff --git a/imap4d/create.c b/imap4d/create.c
index 08e753f..09e11c5 100644
--- a/imap4d/create.c
+++ b/imap4d/create.c
@@ -33,7 +33,8 @@
    deleted, its unique identifiers MUST be greater than any unique identifiers
    used in the previous incarnation of the mailbox.  */
 int
-imap4d_create (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_create (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *name;
   int isdir = 0;
diff --git a/imap4d/delete.c b/imap4d/delete.c
index 33107e3..ae62008 100644
--- a/imap4d/delete.c
+++ b/imap4d/delete.c
@@ -28,7 +28,8 @@
                BAD - command unknown or arguments invalid
 */  
 int
-imap4d_delete (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_delete (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc = RESP_OK;
   const char *msg = "Completed";
diff --git a/imap4d/examine.c b/imap4d/examine.c
index e4bacc2..a0d689a 100644
--- a/imap4d/examine.c
+++ b/imap4d/examine.c
@@ -31,7 +31,8 @@
                BAD - command unknown or arguments invalid
 */
 int
-imap4d_examine (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_examine (struct imap4d_session *session,
+                struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 3)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/expunge.c b/imap4d/expunge.c
index 6b73c0b..28ff581 100644
--- a/imap4d/expunge.c
+++ b/imap4d/expunge.c
@@ -31,7 +31,8 @@
 */
 
 int
-imap4d_expunge (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_expunge (struct imap4d_session *session,
+                struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/fetch.c b/imap4d/fetch.c
index 0ab9876..0fe988d 100644
--- a/imap4d/fetch.c
+++ b/imap4d/fetch.c
@@ -1856,7 +1856,8 @@ imap4d_fetch0 (imap4d_tokbuf_t tok, int isuid, char **err_text)
    mailbox.  The data items to be fetched can be either a single atom
    or a parenthesized list.  */
 int
-imap4d_fetch (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_fetch (struct imap4d_session *session,
+              struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *err_text = "Completed";
diff --git a/imap4d/id.c b/imap4d/id.c
index 1d87f1e..d16f8ba 100644
--- a/imap4d/id.c
+++ b/imap4d/id.c
@@ -163,7 +163,8 @@ get_id_value (const char *name)
 }
 
 int
-imap4d_id (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_id (struct imap4d_session *session,
+           struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc = eat_args (tok);
   if (rc != RESP_OK)
diff --git a/imap4d/idle.c b/imap4d/idle.c
index 9787e97..5561980 100644
--- a/imap4d/idle.c
+++ b/imap4d/idle.c
@@ -17,7 +17,8 @@
 #include "imap4d.h"
 
 int
-imap4d_idle (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_idle (struct imap4d_session *session,
+             struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   time_t start;
   char *token_str = NULL;
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index d05c862..b90ff43 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -17,6 +17,7 @@
 #include "imap4d.h"
 #include <mailutils/gsasl.h>
 #include "mailutils/libargp.h"
+#include "mailutils/kwd.h"
 #include "tcpwrap.h"
 
 mu_m_server_t server;
@@ -30,8 +31,8 @@ char *modify_homedir;           /* Expression to produce imap4d_homedir */
 int state = STATE_NONAUTH;      /* Current IMAP4 state */
 struct mu_auth_data *auth_data; 
 
+enum tls_mode tls_mode;
 int login_disabled;             /* Disable LOGIN command */
-int tls_required;               /* Require STARTTLS */
 int create_home_dir;            /* Create home directory if it does not
 				   exist */
 int home_dir_mode = S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
@@ -94,8 +95,6 @@ static const char *imap4d_capa[] = {
   NULL
 };
 
-static int imap4d_mainloop (int, int, int);
-
 static error_t
 imap4d_parse_opt (int key, char *arg, struct argp_state *state)
 {
@@ -251,14 +250,61 @@ cb_mailbox_mode (void *data, mu_config_value_t *val)
 struct imap4d_srv_config
 {
   struct mu_srv_config m_cfg;
-  int tls;
+  enum tls_mode tls_mode;
 };
 
+#ifdef WITH_TLS
+static int
+cb_tls (void *data, mu_config_value_t *val)
+{
+  int *res = data;
+  static struct mu_kwd tls_kwd[] = {
+    { "no", tls_no },
+    { "false", tls_no },
+    { "off", tls_no },
+    { "0", tls_no },
+    { "ondemand", tls_ondemand },
+    { "stls", tls_ondemand },
+    { "required", tls_required },
+    { "connection", tls_connection },
+    /* For compatibility with prior versions: */
+    { "yes", tls_connection }, 
+    { "true", tls_connection },
+    { "on", tls_connection },
+    { "1", tls_connection },
+    { NULL }
+  };
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+
+  if (mu_kwd_xlat_name (tls_kwd, val->v.string, res))
+    mu_error (_("not a valid tls keyword: %s"), val->v.string);
+  return 0;
+}
+#endif
+
+static int
+cb_tls_required (void *data, mu_config_value_t *val)
+{
+  int *res = data;
+  int bv;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  if (mu_cfg_parse_boolean (val->v.string, &bv))
+    mu_error (_("Not a boolean value"));
+  else
+    *res = tls_required;
+  return 0;
+}
+
 static struct mu_cfg_param imap4d_srv_param[] = {
-  { "tls", mu_cfg_bool, NULL, mu_offsetof (struct imap4d_srv_config, tls),
-    NULL,
-    N_("Use TLS encryption for this server")
-  },
+#ifdef WITH_TLS
+  { "tls", mu_cfg_callback,
+    NULL, mu_offsetof (struct imap4d_srv_config, tls_mode), cb_tls,
+    N_("Kind of TLS encryption to use for this server") },
+#endif
   { NULL }
 };
 
@@ -287,8 +333,13 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
   { "home-dir-mode", mu_cfg_callback, NULL, 0, cb_mode,
     N_("File mode for creating user home directories (octal)."),
     N_("mode") },
-  { "tls-required", mu_cfg_bool, &tls_required, 0, NULL,
-    N_("Always require STARTTLS before entering authentication phase.") },
+#ifdef WITH_TLS
+  { "tls", mu_cfg_callback, &tls_mode, 0, cb_tls,
+    N_("Kind of TLS encryption to use") },
+  { "tls-required", mu_cfg_callback, &tls_mode, 0, cb_tls_required,
+    N_("Always require STLS before entering authentication phase.\n"
+       "Deprecated, use \"tls required\" instead.") },
+#endif
   { "preauth", mu_cfg_callback, NULL, 0, cb_preauth,
     N_("Configure PREAUTH mode.  MODE is one of:\n"
        "  prog:///<full-program-name: string>\n"
@@ -480,11 +531,12 @@ imap4d_child_signal_setup (RETSIGTYPE (*handler) (int signo))
 }
 
 static int
-imap4d_mainloop (int ifd, int ofd, int tls)
+imap4d_mainloop (int ifd, int ofd, enum tls_mode tls)
 {
   imap4d_tokbuf_t tokp;
   char *text;
   int signo;
+  struct imap4d_session session;
 
   if (!test_mode)
     test_mode = isatty (ifd);
@@ -521,7 +573,29 @@ imap4d_mainloop (int ifd, int ofd, int tls)
       imap4d_child_signal_setup (imap4d_child_signal);
     }
   
-  io_setio (ifd, ofd, tls);
+  if (tls == tls_unspecified)
+    tls = tls_available ? tls_ondemand : tls_no;
+  else if (tls != tls_no && !tls_available)
+    {
+      mu_error (_("TLS is not configured, but requested in the "
+		  "configuration"));
+      tls = tls_no;
+    }
+
+  switch (tls)
+    {
+    case tls_required:
+      imap4d_capability_add (IMAP_CAPA_XTLSREQUIRED);
+    case tls_no:
+      imap4d_capability_remove (IMAP_CAPA_STARTTLS);
+      tls_available = 0;
+    }
+  
+  session.tls_mode = tls;
+  
+  io_setio (ifd, ofd, tls == tls_connection);
+  if (tls == tls_connection)
+    tls_encryption_on (&session);
 
   if (imap4d_preauth_setup (ifd) == 0)
     {
@@ -555,7 +629,7 @@ imap4d_mainloop (int ifd, int ofd, int tls)
       imap4d_readline (tokp);
       /* check for updates */
       imap4d_sync ();
-      util_do_command (tokp);
+      util_do_command (&session, tokp);
       imap4d_sync ();
       io_flush ();
     }
@@ -578,7 +652,7 @@ imap4d_connection (int fd, struct sockaddr *sa, int salen,
   else
     rc = 1;
   
-  imap4d_mainloop (fd, fd, cfg->tls);
+  imap4d_mainloop (fd, fd, cfg->tls_mode);
 
   if (rc == 0)
     clr_strerr_flt ();
@@ -687,10 +761,6 @@ main (int argc, char **argv)
 
   if (login_disabled)
     imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
-#ifdef WITH_TLS
-  if (tls_required)
-    imap4d_capability_add (IMAP_CAPA_XTLSREQUIRED);
-#endif
 
   namespace_init ();
 
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index bca33df..7345551 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -115,10 +115,13 @@ extern "C" {
 
 typedef struct imap4d_tokbuf *imap4d_tokbuf_t;
 
+struct imap4d_session;
+  
 struct imap4d_command
 {
   const char *name;
-  int (*func) (struct imap4d_command *, imap4d_tokbuf_t);
+  int (*func) (struct imap4d_session *, struct imap4d_command *,
+	       imap4d_tokbuf_t);
   int states;
   int failure;
   int success;
@@ -175,6 +178,20 @@ enum imap4d_preauth
     preauth_prog
   };
 
+  /* TLS modes */
+enum tls_mode
+  {
+    tls_unspecified,
+    tls_no,
+    tls_ondemand,
+    tls_required,
+    tls_connection
+  };
+
+struct imap4d_session
+{
+  enum tls_mode tls_mode;
+};
   
 extern struct imap4d_command imap4d_command_table[];
 extern mu_mailbox_t mbox;
@@ -190,7 +207,6 @@ extern const char *program_version;
 extern int mailbox_mode[NS_MAX];
   
 extern int login_disabled;
-extern int tls_required;
 extern enum imap4d_preauth preauth_mode;
 extern char *preauth_program;
 extern int preauth_only;
@@ -207,6 +223,8 @@ extern jmp_buf child_jmp;
 extern int test_mode;
 extern int silent_expunge;
 
+int tls_available;
+
 /* Input functions */
 extern mu_stream_t iostream;
 extern int  io_untagged_response (int, const char *, ...) MU_PRINTFLIKE(2,3);
@@ -271,51 +289,81 @@ int imap4d_with_parsebuf (imap4d_tokbuf_t tok, int arg,
 #define imap4d_parsebuf_data(p) ((p)->data)
 
   /* Imap4 commands */
-extern int  imap4d_append (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_authenticate (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_append (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_authenticate (struct imap4d_session *,
+				 struct imap4d_command *, imap4d_tokbuf_t);
 extern void imap4d_auth_capability (void);
-extern int  imap4d_capability (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_check (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_close (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_unselect (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_copy (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_capability (struct imap4d_session *,
+			       struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_check (struct imap4d_session *,
+			  struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_close (struct imap4d_session *,
+			  struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_unselect (struct imap4d_session *,
+			     struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_copy (struct imap4d_session *,
+			 struct imap4d_command *, imap4d_tokbuf_t);
 extern int  imap4d_copy0 (imap4d_tokbuf_t, int isuid, char **err_text);
-extern int  imap4d_create (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_delete (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_examine (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_expunge (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_fetch (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_create (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_delete (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_examine (struct imap4d_session *,
+			    struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_expunge (struct imap4d_session *,
+			    struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_fetch (struct imap4d_session *,
+			  struct imap4d_command *, imap4d_tokbuf_t);
 extern int  imap4d_fetch0 (imap4d_tokbuf_t tok, int isuid, char **err_text);
-extern int  imap4d_list (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_login (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_logout (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_noop (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_rename (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_list (struct imap4d_session *,
+			 struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_login (struct imap4d_session *,
+			  struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_logout (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_noop (struct imap4d_session *,
+			 struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_rename (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
 extern int  imap4d_preauth_setup (int fd);
-extern int  imap4d_search (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_search (struct imap4d_session *,
+			     struct imap4d_command *, imap4d_tokbuf_t);
 extern int  imap4d_search0 (imap4d_tokbuf_t, int isuid, char **repyptr);
-extern int  imap4d_select (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_select (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
 extern int  imap4d_select0 (struct imap4d_command *, const char *, int);
 extern int  imap4d_select_status (void);
 #ifdef WITH_TLS
-extern int  imap4d_starttls (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_starttls (struct imap4d_session *,
+			     struct imap4d_command *, imap4d_tokbuf_t);
 extern void starttls_init (void);
-void tls_encryption_on (void);
+void tls_encryption_on (struct imap4d_session *);
 #endif /* WITH_TLS */
-extern int  imap4d_status (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_store (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_status (struct imap4d_session *,
+			   struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_store (struct imap4d_session *,
+			  struct imap4d_command *, imap4d_tokbuf_t);
 extern int  imap4d_store0 (imap4d_tokbuf_t, int, char **);
 
 mu_property_t open_subscription (void);
-extern int  imap4d_subscribe (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_unsubscribe (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_lsub (struct imap4d_command *, imap4d_tokbuf_t);
-
-extern int  imap4d_uid (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_namespace (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_version (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_idle (struct imap4d_command *, imap4d_tokbuf_t);
-extern int  imap4d_id (struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_subscribe (struct imap4d_session *,
+			      struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_unsubscribe (struct imap4d_session *,
+				struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_lsub (struct imap4d_session *,
+			 struct imap4d_command *, imap4d_tokbuf_t);
+
+extern int  imap4d_uid (struct imap4d_session *,
+			struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_namespace (struct imap4d_session *,
+			      struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_version (struct imap4d_session *,
+			    struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_idle (struct imap4d_session *,
+			 struct imap4d_command *, imap4d_tokbuf_t);
+extern int  imap4d_id (struct imap4d_session *,
+		       struct imap4d_command *, imap4d_tokbuf_t);
   
 extern int imap4d_check_home_dir (const char *dir, uid_t uid, gid_t gid);
 
@@ -364,7 +412,7 @@ extern void imap4d_capability_init (void);
 
 extern int  util_start (char *);
 extern int  util_getstate (void);
-extern int  util_do_command (imap4d_tokbuf_t);
+extern int  util_do_command (struct imap4d_session *, imap4d_tokbuf_t);
 extern char *util_getfullpath (const char *);
 extern struct imap4d_command *util_getcommand (char *, 
                                                struct imap4d_command []);
diff --git a/imap4d/io.c b/imap4d/io.c
index 7adcbf1..9257400 100644
--- a/imap4d/io.c
+++ b/imap4d/io.c
@@ -48,7 +48,6 @@ io_setio (int ifd, int ofd, int tls)
 	  mu_error (_("failed to create TLS stream: %s"), mu_strerror (rc));
 	  imap4d_bye (ERR_STREAM_CREATE);
 	}
-      tls_encryption_on ();
     }
   else
 #endif
diff --git a/imap4d/list.c b/imap4d/list.c
index 160bf62..957fbeb 100644
--- a/imap4d/list.c
+++ b/imap4d/list.c
@@ -131,7 +131,8 @@ list_fun (mu_folder_t folder, struct mu_list_response *resp, void *data)
   but it does not match the hierarchy delimiter.  */
 
 int
-imap4d_list (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_list (struct imap4d_session *session,
+             struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *ref;
   char *wcard;
diff --git a/imap4d/login.c b/imap4d/login.c
index 15c75f5..5221e42 100644
--- a/imap4d/login.c
+++ b/imap4d/login.c
@@ -30,12 +30,13 @@
                BAD - command unknown or arguments invalid
 */  
 int
-imap4d_login (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_login (struct imap4d_session *session,
+              struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *username, *pass;
   int rc;
 
-  if (login_disabled || tls_required)    
+  if (login_disabled || session->tls_mode == tls_required)    
     return io_completion_response (command, RESP_NO, "Command disabled");
 
   if (imap4d_tokbuf_argc (tok) != 4)
diff --git a/imap4d/logout.c b/imap4d/logout.c
index 51c441e..5f6495a 100644
--- a/imap4d/logout.c
+++ b/imap4d/logout.c
@@ -29,7 +29,8 @@
 */
 
 int
-imap4d_logout (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_logout (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/lsub.c b/imap4d/lsub.c
index a84be7c..160f7cd 100644
--- a/imap4d/lsub.c
+++ b/imap4d/lsub.c
@@ -30,7 +30,8 @@
                BAD - command unknown or arguments invalid
 */
 int
-imap4d_lsub (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_lsub (struct imap4d_session *session,
+             struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *ref;
diff --git a/imap4d/namespace.c b/imap4d/namespace.c
index 7a9164f..ba0a5c1 100644
--- a/imap4d/namespace.c
+++ b/imap4d/namespace.c
@@ -112,7 +112,8 @@ namespace_enumerate_all (nsfp_t f, void *closure)
 */
 
 int
-imap4d_namespace (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_namespace (struct imap4d_session *session,
+                  struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/noop.c b/imap4d/noop.c
index b7314fe..82823e0 100644
--- a/imap4d/noop.c
+++ b/imap4d/noop.c
@@ -18,7 +18,8 @@
 #include "imap4d.h"
 
 int
-imap4d_noop (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_noop (struct imap4d_session *session,
+             struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 2)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/rename.c b/imap4d/rename.c
index 3bc2040..b12eef0 100644
--- a/imap4d/rename.c
+++ b/imap4d/rename.c
@@ -101,7 +101,8 @@ make_interdir (const char *name, int delim, int perms)
   of the mailbox.  */
 
 int
-imap4d_rename (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_rename (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *oldname;
   char *newname;
diff --git a/imap4d/search.c b/imap4d/search.c
index 14559d1..ba20e2f 100644
--- a/imap4d/search.c
+++ b/imap4d/search.c
@@ -258,7 +258,8 @@ static void do_search (struct parsebuf *pb);
 */
 
 int
-imap4d_search (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_search (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *err_text= "";
diff --git a/imap4d/select.c b/imap4d/select.c
index 75f3c7f..92acbf0 100644
--- a/imap4d/select.c
+++ b/imap4d/select.c
@@ -22,7 +22,8 @@ static int select_flags;
 /* select          ::= "SELECT" SPACE mailbox  */
 
 int
-imap4d_select (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_select (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   if (imap4d_tokbuf_argc (tok) != 3)
     return io_completion_response (command, RESP_BAD, "Invalid arguments");
diff --git a/imap4d/starttls.c b/imap4d/starttls.c
index 3b0be65..799bf44 100644
--- a/imap4d/starttls.c
+++ b/imap4d/starttls.c
@@ -16,9 +16,10 @@
 
 #include "imap4d.h"
 
+int tls_available;
+
 #ifdef WITH_TLS
 
-static int tls_available;
 static int tls_done;
 
 /*
@@ -32,7 +33,8 @@ static int tls_done;
                BAD - command unknown or arguments invalid
 */
 int
-imap4d_starttls (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_starttls (struct imap4d_session *session,
+                 struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int status;
 
@@ -48,7 +50,7 @@ imap4d_starttls (struct imap4d_command *command, imap4d_tokbuf_t tok)
   io_flush ();
 
   if (imap4d_init_tls_server () == 0)
-    tls_encryption_on ();
+    tls_encryption_on (session);
   else
     {
       mu_diag_output (MU_DIAG_ERROR, _("session terminated"));
@@ -60,7 +62,7 @@ imap4d_starttls (struct imap4d_command *command, imap4d_tokbuf_t tok)
 }
 
 void
-tls_encryption_on ()
+tls_encryption_on (struct imap4d_session *session)
 {
   tls_done = 1;
   imap4d_capability_remove (IMAP_CAPA_STARTTLS);
@@ -68,7 +70,7 @@ tls_encryption_on ()
   login_disabled = 0;
   imap4d_capability_remove (IMAP_CAPA_LOGINDISABLED);
 
-  tls_required = 0;
+  session->tls_mode = tls_no;
   imap4d_capability_remove (IMAP_CAPA_XTLSREQUIRED);
 }
 
diff --git a/imap4d/status.c b/imap4d/status.c
index 265a073..38758b7 100644
--- a/imap4d/status.c
+++ b/imap4d/status.c
@@ -65,7 +65,8 @@ status_get_handler (const char *name)
                BAD - command unknown or arguments invalid
 */
 int
-imap4d_status (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_status (struct imap4d_session *session,
+               struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *name;
   char *mailbox_name;
diff --git a/imap4d/store.c b/imap4d/store.c
index 52831d6..43258fa 100644
--- a/imap4d/store.c
+++ b/imap4d/store.c
@@ -164,7 +164,8 @@ imap4d_store0 (imap4d_tokbuf_t tok, int isuid, char **ptext)
 }
 
 int
-imap4d_store (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_store (struct imap4d_session *session,
+              struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *err_text = NULL;
diff --git a/imap4d/subscribe.c b/imap4d/subscribe.c
index 4c324ca..a139761 100644
--- a/imap4d/subscribe.c
+++ b/imap4d/subscribe.c
@@ -54,7 +54,8 @@ open_subscription ()
 		BAD - command unknown or arguments invalid
 */
 int
-imap4d_subscribe (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_subscribe (struct imap4d_session *session,
+                  struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *name;
diff --git a/imap4d/uid.c b/imap4d/uid.c
index 75b596d..80486f0 100644
--- a/imap4d/uid.c
+++ b/imap4d/uid.c
@@ -22,7 +22,8 @@
  */
 
 int
-imap4d_uid (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_uid (struct imap4d_session *session,
+            struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   char *cmd;
   int rc = RESP_NO;
diff --git a/imap4d/unsubscribe.c b/imap4d/unsubscribe.c
index 0379347..2983d93 100644
--- a/imap4d/unsubscribe.c
+++ b/imap4d/unsubscribe.c
@@ -34,7 +34,8 @@
       only if the unsubscription is successful.
 */
 int
-imap4d_unsubscribe (struct imap4d_command *command, imap4d_tokbuf_t tok)
+imap4d_unsubscribe (struct imap4d_session *session,
+                    struct imap4d_command *command, imap4d_tokbuf_t tok)
 {
   int rc;
   char *name;
diff --git a/imap4d/util.c b/imap4d/util.c
index badb7db..8c9937b 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -37,7 +37,7 @@ util_getfullpath (const char *name)
 }
 
 int
-util_do_command (imap4d_tokbuf_t tok)
+util_do_command (struct imap4d_session *session, imap4d_tokbuf_t tok)
 {
   char *tag, *cmd;
   struct imap4d_command *command;
@@ -73,7 +73,7 @@ util_do_command (imap4d_tokbuf_t tok)
   if (command->states && (command->states & state) == 0)
     return io_completion_response (command, RESP_BAD, "Wrong state");
 
-  return command->func (command, tok);
+  return command->func (session, command, tok);
 }
 
 struct imap4d_command *


hooks/post-receive
-- 
GNU Mailutils


