From MAILER-DAEMON Sun Oct 09 02:18:17 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bt7RB-0002ly-OE
	for mharc-commit-mailutils@gnu.org; Sun, 09 Oct 2016 02:18:17 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39544)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bt7Qv-0002lp-7k
	for commit-mailutils@gnu.org; Sun, 09 Oct 2016 02:18:16 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bt7Qg-0003KF-In
	for commit-mailutils@gnu.org; Sun, 09 Oct 2016 02:18:00 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:44219)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bt7Qg-0003K7-5z
	for commit-mailutils@gnu.org; Sun, 09 Oct 2016 02:17:46 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 019AF22015F; Sun,  9 Oct 2016 06:17:45 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-763-g8905bb4
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 296d0bc958142cafe0e839cd43236c14c8310ee2
X-Git-Newrev: 8905bb4805cf4ebcff9ba3d99073b81c906399f6
Message-Id: <20161009061746.019AF22015F@vcs.savannah.gnu.org>
Date: Sun,  9 Oct 2016 06:17:45 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 09 Oct 2016 06:18:16 -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=8905bb4805cf4ebcff9ba3d99073b81c906399f6

The branch, master has been updated
       via  8905bb4805cf4ebcff9ba3d99073b81c906399f6 (commit)
       via  aac8beae014b6345bc3682c6d0f5b544b2a84956 (commit)
       via  87ef8884693eb0cdcdafa2365c86709f33e3a375 (commit)
       via  8b8f29eb6485e5ab09e2215d595fbbf45c27c97b (commit)
      from  296d0bc958142cafe0e839cd43236c14c8310ee2 (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 8905bb4805cf4ebcff9ba3d99073b81c906399f6
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Oct 8 23:36:50 2016 +0300

    Fix mu_parseopt. Add testsuite for it.
    
    * include/mailutils/opt.h (mu_parseopt) <po_permuted>: New member.
    * libmailutils/opt/help.c (print_option): Fix display of optional
    arguments.
    * libmailutils/opt/opt.c (next_opt,parse): Fix start-of-arguments
    index.
    Move permutation into a separate function.
    * libmailutils/opt/progname.c (mu_set_progname): Remove eventual lt-
    prefix.
    * libmailutils/tests/Makefile.am: Add new tests.
    * libmailutils/tests/parseopt.c: Use environment to control
    mu_parseopt flags.
    * libmailutils/tests/testsuite.at: Add new tests.
    * libmailutils/tests/strtoc.at: Update.
    
    * libmailutils/tests/parseopt00.at: New file.
    * libmailutils/tests/parseopt01.at: New file.
    * libmailutils/tests/parseopt02.at: New file.
    * libmailutils/tests/parseopt03.at: New file.
    * libmailutils/tests/parseopt04.at: New file.
    * libmailutils/tests/parseopt05.at: New file.
    * libmailutils/tests/parseopt06.at: New file.
    * libmailutils/tests/parseopt07.at: New file.
    * libmailutils/tests/parseopt08.at: New file.
    * libmailutils/tests/parseopt09.at: New file.
    * libmailutils/tests/parseopt10.at: New file.
    * libmailutils/tests/parseopt11.at: New file.
    * libmailutils/tests/parseopt12.at: New file.
    * libmailutils/tests/parseopt13.at: New file.
    * libmailutils/tests/parseopt14.at: New file.
    * libmailutils/tests/parseopt15.at: New file.
    * libmailutils/tests/parseopt16.at: New file.
    * libmailutils/tests/parseopt17.at: New file.
    * libmailutils/tests/parseopt18.at: New file.
    * libmailutils/tests/parseopt19.at: New file.
    * libmailutils/tests/parseopt20.at: New file.
    * libmailutils/tests/parseopt21.at: New file.
    * libmailutils/tests/parseopt22.at: New file.

commit aac8beae014b6345bc3682c6d0f5b544b2a84956
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sat Oct 8 16:21:23 2016 +0300

    Use mu_c_type_t throughout the code.  Get rid of mu_cfg_param_data_type.
    
    * include/mailutils/cfg.h (mu_cfg_param_data_type): Remove.
    (mu_cfg_param_type): New enum.
    (mu_cfg_param) <type>: Change type to int.
    (mu_cfg_cidr): Remove.
    (mu_cfg_parse_boolean): Remove.  All uses updated.
    * include/mailutils/util.h (mu_c_void): New constant.
    (mu_c_type_str): New extern/
    * libmailutils/string/str_to_c.c (mu_c_type_str): New global.
    * libmailutils/cfg/format.c (mu_cfg_data_type_string): Rename
    to mu_c_type_string; change argument type.
    All uses updated.
    * libmailutils/cfg/parser.y: Use mu_str_to_c for value
    conversion.
    
    * libmailutils/tests/.gitignore: Update.
    * libmailutils/tests/Makefile.am: Add strtoc.at; build strtoc
    * libmailutils/tests/strtoc.at: New file.
    * libmailutils/tests/strtoc.c: New file.
    * libmailutils/tests/testsuite.at: Include strtoc.at
    
    * comsat/comsat.c: Use mu_c_type_t types.
    * dotlock/dotlock.c: Likewise.
    * imap4d/imap4d.c: Likewise.
    * lib/manlock.c: Likewise.
    * lib/tcpwrap.c: Likewise.
    * libmailutils/server/msrv.c: Likewise.
    * libmu_argp/muinit.c: Likewise.
    * libmu_cfg/common.c: Likewise.
    * libmu_cfg/gsasl.c: Likewise.
    * libmu_cfg/ldap.c: Likewise.
    * libmu_cfg/pam.c: Likewise.
    * libmu_cfg/radius.c: Likewise.
    * libmu_cfg/sieve.c: Likewise.
    * libmu_cfg/sql.c: Likewise.
    * libmu_cfg/tls.c: Likewise.
    * libmu_cfg/virtdomain.c: Likewise.
    * maidag/maidag.c: Likewise.
    * mimeview/mimeview.c: Likewise.
    * movemail/movemail.c: Likewise.
    * pop3d/pop3d.c: Likewise.
    * readmsg/readmsg.c: Likewise.
    * sieve/sieve.c: Likewise.

commit 87ef8884693eb0cdcdafa2365c86709f33e3a375
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 7 21:58:50 2016 +0300

    Add generic library for option parsing.
    
    * configure.ac: Build libmailutils/opt
    * include/mailutils/Makefile.am: Add opt.h
    * include/mailutils/opt.h: New file.
    * include/mailutils/util.h (mu_c_type_t): New datatype.
    (mu_str_to_c): New proto.
    * libmailutils/Makefile.am: Add opt to subdirs.
    
    * libmailutils/opt/Makefile.am: New file.
    * libmailutils/opt/help.c: New file.
    * libmailutils/opt/opt.c: New file.
    * libmailutils/opt/progname.c: New file.
    
    * libmailutils/string/Makefile.am: Add new files.
    * libmailutils/string/str_to_c.c: New file.
    * libmailutils/string/to_sn.c: New file.
    * libmailutils/string/to_un.c: New file.
    
    * libmailutils/tests/.gitignore: Update.
    * libmailutils/tests/Makefile.am: Update.
    * libmailutils/tests/parseopt.c: New file.

commit 8b8f29eb6485e5ab09e2215d595fbbf45c27c97b
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 6 09:25:43 2016 +0300

    Bugfixes
    
    * mh/rmf.c (current_folder_path): Treat name as folder while expanding.
    * mail/unset.c (mail_unset): Fix the behavior when no arguments were
    given.

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

Summary of changes:
 comsat/comsat.c                                    |   16 +-
 configure.ac                                       |    1 +
 dotlock/dotlock.c                                  |    6 +-
 imap4d/imap4d.c                                    |   32 +-
 include/mailutils/Makefile.am                      |    1 +
 include/mailutils/cfg.h                            |   40 +-
 include/mailutils/opt.h                            |  169 ++++++
 include/mailutils/util.h                           |   31 +-
 lib/manlock.c                                      |    4 +-
 lib/tcpwrap.c                                      |    8 +-
 libmailutils/Makefile.am                           |    3 +-
 libmailutils/cfg/format.c                          |   41 +-
 libmailutils/cfg/parser.y                          |  388 +-----------
 libmailutils/{mailer => opt}/Makefile.am           |   14 +-
 libmailutils/opt/help.c                            |  345 +++++++++++
 libmailutils/opt/opt.c                             |  638 ++++++++++++++++++++
 .../virtdomain.c => libmailutils/opt/progname.c    |   39 +-
 libmailutils/server/msrv.c                         |   14 +-
 libmailutils/string/Makefile.am                    |    5 +-
 libmailutils/string/str_to_c.c                     |  295 +++++++++
 libmailutils/string/to_sn.c                        |   37 ++
 libmailutils/string/to_un.c                        |   34 ++
 libmailutils/tests/.gitignore                      |    2 +
 libmailutils/tests/Makefile.am                     |   26 +
 libmailutils/tests/parseopt.c                      |  118 ++++
 libmailutils/tests/{strout.at => parseopt00.at}    |   30 +-
 libmailutils/tests/{strerr.at => parseopt01.at}    |   34 +-
 libmailutils/tests/{strerr.at => parseopt02.at}    |   34 +-
 .../tests/parseopt03.at                            |   35 +-
 .../tests/parseopt04.at                            |   35 +-
 .../tests/parseopt05.at                            |   35 +-
 .../tests/parseopt06.at                            |   35 +-
 .../tests/parseopt07.at                            |   35 +-
 libmailutils/tests/{strerr.at => parseopt08.at}    |   34 +-
 .../tests/parseopt09.at                            |   35 +-
 .../tests/parseopt10.at                            |   35 +-
 .../tests/parseopt11.at                            |   35 +-
 .../tests/parseopt12.at                            |   35 +-
 .../tests/parseopt13.at                            |   35 +-
 libmailutils/tests/{strerr.at => parseopt14.at}    |   26 +-
 .../tests/parseopt15.at                            |   35 +-
 libmailutils/tests/{strerr.at => parseopt16.at}    |   30 +-
 .../tests/parseopt17.at                            |   35 +-
 libmailutils/tests/{strerr.at => parseopt18.at}    |   32 +-
 .../tests/parseopt19.at                            |   34 +-
 libmailutils/tests/{strout.at => parseopt20.at}    |   26 +-
 .../tests/parseopt21.at                            |   19 +-
 libmailutils/tests/{strout.at => parseopt22.at}    |   26 +-
 .../version.at => libmailutils/tests/strtoc.at     |    8 +-
 libmailutils/tests/strtoc.c                        |  354 +++++++++++
 libmailutils/tests/testsuite.at                    |   28 +
 libmu_argp/muinit.c                                |    2 +-
 libmu_cfg/common.c                                 |   32 +-
 libmu_cfg/gsasl.c                                  |   12 +-
 libmu_cfg/ldap.c                                   |   18 +-
 libmu_cfg/pam.c                                    |    2 +-
 libmu_cfg/radius.c                                 |    8 +-
 libmu_cfg/sieve.c                                  |    4 +-
 libmu_cfg/sql.c                                    |   20 +-
 libmu_cfg/tls.c                                    |   10 +-
 libmu_cfg/virtdomain.c                             |    2 +-
 maidag/maidag.c                                    |   18 +-
 mail/unset.c                                       |    2 +-
 mh/rmf.c                                           |    4 +-
 mimeview/mimeview.c                                |    4 +-
 movemail/movemail.c                                |   16 +-
 pop3d/pop3d.c                                      |   20 +-
 readmsg/readmsg.c                                  |   14 +-
 sieve/sieve.c                                      |   10 +-
 69 files changed, 2664 insertions(+), 976 deletions(-)
 create mode 100644 include/mailutils/opt.h
 copy libmailutils/{mailer => opt}/Makefile.am (77%)
 create mode 100644 libmailutils/opt/help.c
 create mode 100644 libmailutils/opt/opt.c
 copy libmu_cfg/virtdomain.c => libmailutils/opt/progname.c (57%)
 create mode 100644 libmailutils/string/str_to_c.c
 create mode 100644 libmailutils/string/to_sn.c
 create mode 100644 libmailutils/string/to_un.c
 create mode 100644 libmailutils/tests/parseopt.c
 copy libmailutils/tests/{strout.at => parseopt00.at} (73%)
 copy libmailutils/tests/{strerr.at => parseopt01.at} (68%)
 copy libmailutils/tests/{strerr.at => parseopt02.at} (68%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt03.at (66%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt04.at (65%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt05.at (65%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt06.at (66%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt07.at (66%)
 copy libmailutils/tests/{strerr.at => parseopt08.at} (68%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt09.at (66%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt10.at (65%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt11.at (65%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt12.at (66%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt13.at (66%)
 copy libmailutils/tests/{strerr.at => parseopt14.at} (68%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt15.at (64%)
 copy libmailutils/tests/{strerr.at => parseopt16.at} (72%)
 copy imap4d/tests/create01.at => libmailutils/tests/parseopt17.at (67%)
 copy libmailutils/tests/{strerr.at => parseopt18.at} (67%)
 copy imap4d/tests/create02.at => libmailutils/tests/parseopt19.at (65%)
 copy libmailutils/tests/{strout.at => parseopt20.at} (73%)
 copy testsuite/lstuid00.at => libmailutils/tests/parseopt21.at (73%)
 copy libmailutils/tests/{strout.at => parseopt22.at} (75%)
 copy mail/tests/version.at => libmailutils/tests/strtoc.at (85%)
 create mode 100644 libmailutils/tests/strtoc.c

diff --git a/comsat/comsat.c b/comsat/comsat.c
index 48add9a..0911a37 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -128,7 +128,7 @@ biffrc_error_ctl (mu_config_value_t *val, int flag)
   
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  if (mu_cfg_parse_boolean (val->v.string, &res))
+  if (mu_str_to_c (val->v.string, mu_c_bool, &res, NULL))
     mu_diag_output (MU_LOG_ERROR, _("not a boolean"));
   else if (res)
     biffrc_errors |= flag;
@@ -150,9 +150,9 @@ cb_biffrc_errors_to_err (void *data, mu_config_value_t *val)
 }
 
 struct mu_cfg_param comsat_cfg_param[] = {
-  { "allow-biffrc", mu_cfg_bool, &allow_biffrc, 0, NULL,
+  { "allow-biffrc", mu_c_bool, &allow_biffrc, 0, NULL,
     N_("Read .biffrc file from the user home directory.") },
-  { "require-tty", mu_cfg_bool, &require_tty, 0, NULL,
+  { "require-tty", mu_c_bool, &require_tty, 0, NULL,
     N_("Notify only if the user is logged on one of the ttys.") },
   { "biffrc-errors-to-tty", mu_cfg_callback, NULL, 0, cb_biffrc_errors_to_tty,
     N_("Send biffrc errors to user's tty."),
@@ -160,17 +160,17 @@ struct mu_cfg_param comsat_cfg_param[] = {
   { "biffrc-errors-to-err", mu_cfg_callback, NULL, 0, cb_biffrc_errors_to_err,
     N_("Send biffrc errors to Mailutils error output."),
     N_("arg: bool") },
-  { "max-lines", mu_cfg_int, &maxlines, 0, NULL,
+  { "max-lines", mu_c_int, &maxlines, 0, NULL,
     N_("Maximum number of message body lines to be output.") },
-  { "max-requests", mu_cfg_uint, &maxrequests, 0, NULL,
+  { "max-requests", mu_c_uint, &maxrequests, 0, NULL,
     N_("Maximum number of incoming requests per request control interval.") },
-  { "request-control-interval", mu_cfg_time, &request_control_interval,
+  { "request-control-interval", mu_c_time, &request_control_interval,
     0, NULL,
     N_("Set control interval.") },
-  { "overflow-control-interval", mu_cfg_time, &overflow_control_interval,
+  { "overflow-control-interval", mu_c_time, &overflow_control_interval,
     0, NULL,
     N_("Set overflow control interval.") },
-  { "overflow-delay-time", mu_cfg_time, &overflow_delay_time,
+  { "overflow-delay-time", mu_c_time, &overflow_delay_time,
     0, NULL,
     N_("Time to sleep after the first overflow occurs.") },
   { ".server", mu_cfg_section, NULL, 0, NULL,
diff --git a/configure.ac b/configure.ac
index d473f80..7bd3641 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1519,6 +1519,7 @@ AC_CONFIG_FILES([
  libmailutils/mailer/Makefile
  libmailutils/mime/Makefile
  libmailutils/msgset/Makefile
+ libmailutils/opt/Makefile
  libmailutils/property/Makefile
  libmailutils/server/Makefile
  libmailutils/string/Makefile
diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index eaf5254..c6a96c5 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -122,11 +122,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
 
 
 struct mu_cfg_param dotlock_cfg_param[] = {
-  { "force", mu_cfg_time, &force, 0, NULL,
+  { "force", mu_c_time, &force, 0, NULL,
     N_("Forcibly break an existing lock older than the specified time.") },
-  { "retry", mu_cfg_int, &retries, 0, NULL,
+  { "retry", mu_c_int, &retries, 0, NULL,
     N_("Number of times to retry acquiring the lock.") },
-  { "debug", mu_cfg_bool, &debug, 0, NULL,
+  { "debug", mu_c_bool, &debug, 0, NULL,
     N_("Print details of failure reasons to stderr.") },
   { NULL }
 };
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index bf7c8c2..a256dd4 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -321,7 +321,7 @@ cb_tls_required (void *data, mu_config_value_t *val)
 
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  if (mu_cfg_parse_boolean (val->v.string, &bv))
+  if (mu_str_to_c (val->v.string, mu_c_bool, &bv, NULL))
     mu_error (_("Not a boolean value"));
   else if (bv)
     {
@@ -384,28 +384,28 @@ static struct mu_cfg_param imap4d_srv_param[] = {
 };
 
 static struct mu_cfg_param imap4d_cfg_param[] = {
-  { "allow-users", MU_CFG_LIST_OF(mu_cfg_string), &auth_allow_user_list,
+  { "allow-users", MU_CFG_LIST_OF(mu_c_string), &auth_allow_user_list,
     0, NULL, 
     N_("Allow access to users from this list.") },
-  { "deny-users", MU_CFG_LIST_OF(mu_cfg_string), &auth_deny_user_list,
+  { "deny-users", MU_CFG_LIST_OF(mu_c_string), &auth_deny_user_list,
     0, NULL, 
     N_("Deny access to users from this list.") },
-  { "allow-groups", MU_CFG_LIST_OF(mu_cfg_string), &auth_allow_group_list,
+  { "allow-groups", MU_CFG_LIST_OF(mu_c_string), &auth_allow_group_list,
     0, NULL, 
     N_("Allow access if the user group is in this list.") },
-  { "deny-groups", MU_CFG_LIST_OF(mu_cfg_string), &auth_deny_group_list,
+  { "deny-groups", MU_CFG_LIST_OF(mu_c_string), &auth_deny_group_list,
     0, NULL, 
     N_("Deny access if the user group is in this list.") },
   
-  { "homedir", mu_cfg_string, &modify_homedir, 0, NULL,
+  { "homedir", mu_c_string, &modify_homedir, 0, NULL,
     N_("Modify home directory.") },
-  { "personal-namespace", MU_CFG_LIST_OF(mu_cfg_string), &namespace[NS_PRIVATE],
+  { "personal-namespace", MU_CFG_LIST_OF(mu_c_string), &namespace[NS_PRIVATE],
     0, NULL, 
     N_("Set personal namespace.") },
-  { "other-namespace", MU_CFG_LIST_OF(mu_cfg_string), &namespace[NS_OTHER],
+  { "other-namespace", MU_CFG_LIST_OF(mu_c_string), &namespace[NS_OTHER],
     0, NULL, 
     N_("Set other users' namespace.") },
-  { "shared-namespace", MU_CFG_LIST_OF(mu_cfg_string), &namespace[NS_SHARED],
+  { "shared-namespace", MU_CFG_LIST_OF(mu_c_string), &namespace[NS_SHARED],
     0, NULL,
     N_("Set shared namespace.") },
   { "other-mailbox-mode", mu_cfg_callback, &mailbox_mode[NS_OTHER], 0,
@@ -414,9 +414,9 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
   { "shared-mailbox-mode", mu_cfg_callback, &mailbox_mode[NS_SHARED], 0,
     cb_mailbox_mode,
     N_("File mode for mailboxes in shared namespace.") },
-  { "login-disabled", mu_cfg_bool, &login_disabled, 0, NULL,
+  { "login-disabled", mu_c_bool, &login_disabled, 0, NULL,
     N_("Disable LOGIN command.") },
-  { "create-home-dir", mu_cfg_bool, &create_home_dir, 0, NULL,
+  { "create-home-dir", mu_c_bool, &create_home_dir, 0, NULL,
     N_("If true, create non-existing user home directories.") },
   { "home-dir-mode", mu_cfg_callback, NULL, 0, cb_mode,
     N_("File mode for creating user home directories (octal)."),
@@ -437,19 +437,19 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
        "  ident[://:<port: string-or-number>]\n"
        "  stdio"),
     N_("mode") },
-  { "preauth-only", mu_cfg_bool, &preauth_only, 0, NULL,
+  { "preauth-only", mu_c_bool, &preauth_only, 0, NULL,
     N_("Use only preauth mode.  If unable to setup it, disconnect "
        "immediately.") },
-  { "ident-keyfile", mu_cfg_string, &ident_keyfile, 0, NULL,
+  { "ident-keyfile", mu_c_string, &ident_keyfile, 0, NULL,
     N_("Name of DES keyfile for decoding encrypted ident responses.") },
-  { "ident-encrypt-only", mu_cfg_bool, &ident_encrypt_only, 0, NULL,
+  { "ident-encrypt-only", mu_c_bool, &ident_encrypt_only, 0, NULL,
     N_("Use only encrypted ident responses.") },
-  { "id-fields", MU_CFG_LIST_OF(mu_cfg_string), &imap4d_id_list, 0, NULL,
+  { "id-fields", MU_CFG_LIST_OF(mu_c_string), &imap4d_id_list, 0, NULL,
     N_("List of fields to return in response to ID command.") },
   { "mandatory-locking", mu_cfg_section },
   { ".server", mu_cfg_section, NULL, 0, NULL,
     N_("Server configuration.") },
-  { "transcript", mu_cfg_bool, &imap4d_transcript, 0, NULL,
+  { "transcript", mu_c_bool, &imap4d_transcript, 0, NULL,
     N_("Set global transcript mode.") },
   TCP_WRAPPERS_CONFIG
   { NULL }
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 361ebdc..ba87486 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -79,6 +79,7 @@ pkginclude_HEADERS = \
  nntp.h\
  observer.h\
  opool.h\
+ opt.h\
  pam.h\
  parse822.h\
  pop3.h\
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index c6eaf2c..7ea8e08 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -22,6 +22,7 @@
 #include <mailutils/list.h>
 #include <mailutils/debug.h>
 #include <mailutils/opool.h>
+#include <mailutils/util.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -113,27 +114,6 @@ void mu_cfg_destroy_tree (mu_cfg_tree_t **tree);
 int mu_cfg_preorder (mu_list_t nodelist, struct mu_cfg_iter_closure *);
 
 
-/* Table-driven parsing */
-enum mu_cfg_param_data_type
-  {
-    mu_cfg_string,
-    mu_cfg_short,
-    mu_cfg_ushort,
-    mu_cfg_int,
-    mu_cfg_uint,
-    mu_cfg_long,
-    mu_cfg_ulong,
-    mu_cfg_size,
-    mu_cfg_off,
-    mu_cfg_time,
-    mu_cfg_bool,
-    mu_cfg_ipv4,
-    mu_cfg_cidr,
-    mu_cfg_host,
-    mu_cfg_callback,
-    mu_cfg_section
-  };
-
 #define MU_CFG_LIST_MASK 0x8000
 #define MU_CFG_LIST_OF(t) ((t) | MU_CFG_LIST_MASK)
 #define MU_CFG_TYPE(t) ((t) & ~MU_CFG_LIST_MASK)
@@ -141,10 +121,16 @@ enum mu_cfg_param_data_type
   
 typedef int (*mu_cfg_callback_t) (void *, mu_config_value_t *);
 
+enum mu_cfg_param_type
+  {
+    mu_cfg_section = mu_c_void + 1,
+    mu_cfg_callback
+  };
+  
 struct mu_cfg_param
 {
   const char *ident;
-  enum mu_cfg_param_data_type type;
+  int type;       /* One of enum mu_c_type or mu_cfg_param_type values */
   void *data;
   size_t offset;
   mu_cfg_callback_t callback;
@@ -197,14 +183,6 @@ struct mu_cfg_cont
   } v;
 };
 
-typedef struct mu_cfg_cidr mu_cfg_cidr_t;
-
-struct mu_cfg_cidr
-{
-  struct in_addr addr;
-  unsigned long mask;
-};
-
 #define MU_CFG_PATH_DELIM '.'
 #define MU_CFG_PATH_DELIM_STR "."
   
@@ -271,8 +249,6 @@ int mu_parse_config (const char *file, const char *progname,
 		     struct mu_cfg_param *progparam, int flags,
 		     void *target_ptr) MU_CFG_DEPRECATED;
 
-int mu_cfg_parse_boolean (const char *str, int *res);
-
 extern int mu_cfg_parser_verbose;
 extern size_t mu_cfg_error_count;
 
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
new file mode 100644
index 0000000..de84d21
--- /dev/null
+++ b/include/mailutils/opt.h
@@ -0,0 +1,169 @@
+/* opt.h -- general-purpose command line option parser 
+   Copyright (C) 2016 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/>.
+*/
+
+#ifndef _MAILUTILS_OPT_H
+#define _MAILUTILS_OPT_H
+#include <stdio.h>
+#include <mailutils/types.h>
+#include <mailutils/list.h>
+#include <mailutils/util.h>
+#include <mailutils/cctype.h>
+
+extern char *mu_progname;
+extern char *mu_absprogname;
+
+void mu_set_progname (char const *arg);
+
+#define MU_OPTION_DEFAULT        0
+#define MU_OPTION_ARG_OPTIONAL   0x01
+#define MU_OPTION_HIDDEN         0x02
+#define MU_OPTION_ALIAS          0x04
+#define MU_OPTION_IMMEDIATE      0x08
+
+struct mu_parseopt;
+
+struct mu_option
+{
+  char *opt_long;         /* Long option name */
+  int opt_short;          /* Short option character */
+  char *opt_arg;          /* Argument name */
+  int opt_flags;          /* Flags (see above) */  
+  char *opt_doc;          /* Human-readable documentation */
+  mu_c_type_t opt_type;   /* Option type */
+  void *opt_ptr;          /* Data pointer */
+  void (*opt_set) (struct mu_parseopt *, struct mu_option *, char const *);
+                          /* Function to set the option */
+};
+
+#define MU_OPTION_GROUP(text) { NULL, 0, NULL, 0, text }
+#define MU_OPTION_END { NULL, 0, NULL, 0, NULL }
+
+#define MU_OPTION_IS_END(opt)					\
+  (!(opt)->opt_long && !(opt)->opt_short && !(opt)->opt_doc)
+
+#define MU_OPTION_IS_OPTION(opt) \
+  ((opt)->opt_short || (opt)->opt_long)
+#define MU_OPTION_IS_GROUP_HEADER(opt)			\
+  (!MU_OPTION_IS_OPTION(opt) && (opt)->opt_doc)
+#define MU_OPTION_IS_VALID_SHORT_OPTION(opt) \
+  ((opt)->opt_short > 0 && (opt)->opt_short < 127 && \
+   mu_isalnum ((opt)->opt_short))
+#define MU_OPTION_IS_VALID_LONG_OPTION(opt) \
+  ((opt)->opt_long != NULL)
+
+typedef struct mu_option_cache *mu_option_cache_ptr_t;
+
+struct mu_option_cache
+{
+  struct mu_option *cache_opt;
+  char *cache_arg;
+};
+
+#define MU_PARSEOPT_DEFAULT        0
+/* Don't ignore the first element of ARGV.  By default it is the program
+   name */
+#define MU_PARSEOPT_ARGV0          0x00000001
+/* Ignore command line errors. */
+#define MU_PARSEOPT_IGNORE_ERRORS  0x00000002
+/* Don't order arguments so that options come first. */
+#define MU_PARSEOPT_IN_ORDER       0x00000004
+/* Don't provide standard options: -h, --help, --usage, --version */
+#define MU_PARSEOPT_NO_STDOPT      0x00000008
+/* Don't exit on errors */
+#define MU_PARSEOPT_NO_ERREXIT     0x00000010
+/* Apply all options immediately */
+#define MU_PARSEOPT_IMMEDIATE      0x00000020
+
+/* Don't sort options */
+#define MU_PARSEOPT_NO_SORT        0x00001000
+
+#define MU_PARSEOPT_PROG_NAME      0x00002000
+#define MU_PARSEOPT_PROG_DOC       0x00004000
+#define MU_PARSEOPT_PROG_ARGS      0x00008000
+#define MU_PARSEOPT_BUG_ADDRESS    0x00010000
+#define MU_PARSEOPT_PACKAGE_NAME   0x00020000
+#define MU_PARSEOPT_PACKAGE_URL    0x00040000
+#define MU_PARSEOPT_DATA           0x00080000
+#define MU_PARSEOPT_HELP_HOOK      0x00100000
+
+/* Reuse mu_parseopt struct initialized previously */
+#define MU_PARSEOPT_REUSE          0x80000000
+/* Mask for immutable flag bits */
+#define MU_PARSEOPT_IMMUTABLE_MASK 0xFFFFF000
+
+
+struct mu_parseopt
+{
+  /* Input data: */
+  int po_argc;                     /* Number of argiments */
+  char **po_argv;                  /* Array of arguments */
+  size_t po_optc;                  /* Number of elements in optv */
+  struct mu_option **po_optv;      /* Array of ptrs to option structures */ 
+  int po_flags;                        
+
+  char *po_data;                   /* Call-specific data */
+  
+  /* Informational: */
+  char const *po_prog_name;
+  char const *po_prog_doc;	
+  char const *po_prog_args;
+  char const *po_bug_address;
+  char const *po_package_name;
+  char const *po_package_url;
+
+  void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_Stream_t ?*/
+  
+  /* Output data */
+  int po_ind;                      /* Index of the next option */
+  int po_opterr;                   /* Index of the element in po_argv that
+				      caused last error, or -1 if no errors */
+  mu_list_t po_optlist;
+  
+  /* Auxiliary data */
+  char *po_cur;                    /* Points to the next character */
+  int po_chr;                      /* Single-char option */
+  
+  /* The following two keep the position of the first non-optional argument
+     and the number of contiguous non-optional arguments after it.
+     Obviously, the following holds true:
+
+         arg_start + arg_count == opt_ind
+
+     If permutation is not allowed (MU_OPTION_PARSE_IN_ORDER flag is set),
+     arg_count is always 0.
+  */
+  int po_arg_start;
+  int po_arg_count;
+
+  unsigned po_permuted:1;           /* Whether the arguments were permuted */
+};
+
+int mu_parseopt (struct mu_parseopt *p,
+		 int argc, char **argv, struct mu_option **optv,
+		 int flags);
+
+int mu_parseopt_apply (struct mu_parseopt *p);
+void mu_parseopt_free (struct mu_parseopt *p);
+
+void mu_option_describe_options (struct mu_option **optbuf, size_t optcnt);
+void mu_program_help (struct mu_parseopt *p);
+void mu_program_usage (struct mu_parseopt *p);
+
+void mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
+			  char const *arg);
+
+#endif
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
index b5bc303..1d994dd 100644
--- a/include/mailutils/util.h
+++ b/include/mailutils/util.h
@@ -152,6 +152,36 @@ int mu_getpass (mu_stream_t in, mu_stream_t out, const char *prompt,
 		char **passptr);
 
   /* ----------------------- */
+  /* String conversions.     */
+  /* ----------------------- */
+
+enum mu_c_type
+  {
+    mu_c_string,
+    mu_c_short,
+    mu_c_ushort,
+    mu_c_int,
+    mu_c_uint,
+    mu_c_long,
+    mu_c_ulong,
+    mu_c_size,
+    mu_c_off,
+    mu_c_time,
+    mu_c_bool,
+    mu_c_ipv4,
+    mu_c_cidr,
+    mu_c_host,
+    mu_c_incr,        /* C int value, incremented each time mu_str_to_c is
+			 invoked */
+    mu_c_void         /* No type.  Keep it the last */
+  };
+
+typedef enum mu_c_type mu_c_type_t;
+extern char const *mu_c_type_str[];
+int mu_str_to_c (char const *string, mu_c_type_t type, void *tgt,
+		 char **errmsg);
+  
+  /* ----------------------- */
   /* Assorted functions.     */
   /* ----------------------- */
 int mu_getmaxfd (void);
@@ -208,7 +238,6 @@ int mu_file_safety_compose (int *res, const char *name, int defval);
 int mu_file_mode_to_safety_criteria (int mode);
 int mu_safety_criteria_to_file_mode (int crit);
   
-  
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/manlock.c b/lib/manlock.c
index cdb65b1..ded7e0b 100644
--- a/lib/manlock.c
+++ b/lib/manlock.c
@@ -185,9 +185,9 @@ manlock_open_mailbox (mu_mailbox_t *pmbox, const char *mailbox_name, int def,
 
 
 struct mu_cfg_param manlock_param[] = {
-  { "enable", mu_cfg_bool, &manlock_mandatory_locking, 0, NULL,
+  { "enable", mu_c_bool, &manlock_mandatory_locking, 0, NULL,
     N_("Enable mandatory locking.") },
-  { "lock-directory", mu_cfg_string, &manlock_lock_dir, 0, NULL,
+  { "lock-directory", mu_c_string, &manlock_lock_dir, 0, NULL,
     N_("Set directory for mandatory lock files.") },
   { NULL }
 };
diff --git a/lib/tcpwrap.c b/lib/tcpwrap.c
index 585d1a1..f4df64e 100644
--- a/lib/tcpwrap.c
+++ b/lib/tcpwrap.c
@@ -53,17 +53,17 @@ mu_tcpwrapper_access (int fd)
 }
 
 struct mu_cfg_param tcpwrapper_param[] = {
-  { "enable", mu_cfg_bool, &mu_tcp_wrapper_enable, 0, NULL,	      
+  { "enable", mu_c_bool, &mu_tcp_wrapper_enable, 0, NULL,	      
     N_("Enable TCP wrapper access control.  Default is \"yes\".") },	      
-  { "daemon", mu_cfg_string, &mu_tcp_wrapper_daemon, 0, NULL,     
+  { "daemon", mu_c_string, &mu_tcp_wrapper_daemon, 0, NULL,     
     N_("Set daemon name for TCP wrapper lookups.  Default is program name."), 
     N_("name") },							      
-  { "allow-table", mu_cfg_string, &hosts_allow_table,
+  { "allow-table", mu_c_string, &hosts_allow_table,
     0, NULL,
     N_("Use file for positive client address access control "		      
        "(default: /etc/hosts.allow)."),					      
     N_("file") },							      
-  { "deny-table", mu_cfg_string, &hosts_deny_table,
+  { "deny-table", mu_c_string, &hosts_deny_table,
     0, NULL,                                             
     N_("Use file for negative client address access control "		      
        "(default: /etc/hosts.deny)."),					      
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index 9d0c3bf..7a5270c 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -18,7 +18,7 @@
 
 SUBDIRS = \
  auth base address list sockaddr cidr cfg diag\
- filter mailbox mailer mime msgset server string stream stdstream\
+ filter mailbox mailer mime msgset opt server string stream stdstream\
  property url imapio datetime . tests 
 
 lib_LTLIBRARIES = libmailutils.la
@@ -42,6 +42,7 @@ libmailutils_la_LIBADD = \
  mailer/libmailer.la\
  mime/libmime.la\
  msgset/libmsgset.la\
+ opt/libopt.la\
  property/libproperty.la\
  server/libserver.la\
  string/libstring.la\
diff --git a/libmailutils/cfg/format.c b/libmailutils/cfg/format.c
index 27801d2..d94c878 100644
--- a/libmailutils/cfg/format.c
+++ b/libmailutils/cfg/format.c
@@ -263,35 +263,38 @@ mu_cfg_format_node (mu_stream_t stream, const mu_cfg_node_t *node, int flags)
 
 
 const char *
-mu_cfg_data_type_string (enum mu_cfg_param_data_type type)
+mu_c_type_string (int type)
 {
   switch (type)
     {
-    case mu_cfg_string:
+    case mu_c_string:
       return N_("string");
-    case mu_cfg_short:
-    case mu_cfg_ushort:
-    case mu_cfg_int:
-    case mu_cfg_uint:
-    case mu_cfg_long:
-    case mu_cfg_ulong:
-    case mu_cfg_size:
-    case mu_cfg_off:
+    case mu_c_short:
+    case mu_c_ushort:
+    case mu_c_int:
+    case mu_c_uint:
+    case mu_c_long:
+    case mu_c_ulong:
+    case mu_c_size:
+    case mu_c_off:
+    case mu_c_incr:
       return N_("number");
-    case mu_cfg_time:
+    case mu_c_time:
       return N_("time");
-    case mu_cfg_bool:
+    case mu_c_bool:
       return N_("boolean");
-    case mu_cfg_ipv4:
+    case mu_c_ipv4:
       return N_("ipv4");
-    case mu_cfg_cidr:
+    case mu_c_cidr:
       return N_("cidr");
-    case mu_cfg_host:
+    case mu_c_host:
       return N_("host");
-    case mu_cfg_callback:
-      return N_("string");
     case mu_cfg_section:
       return N_("section");
+    case mu_cfg_callback:
+      return N_("callback");
+    default:
+      break;
     }
   return N_("unknown");
 }
@@ -361,13 +364,13 @@ format_param (mu_stream_t stream, struct mu_cfg_param *param, int level)
 		      param->ident,
 		      gettext (param->argname ?
 			       param->argname : N_("arg")),
-	gettext (mu_cfg_data_type_string (MU_CFG_TYPE (param->type))));
+	gettext (mu_c_type_string (MU_CFG_TYPE (param->type))));
   else
     mu_stream_printf (stream, "%s <%s: %s>;\n",
 		      param->ident,
 		      gettext (param->argname ?
 			       param->argname : N_("arg")),
-		      gettext (mu_cfg_data_type_string (param->type)));
+		      gettext (mu_c_type_string (param->type)));
 }
 
 static void format_container (mu_stream_t stream, struct mu_cfg_cont *cont,
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index fe76ef1..6877063 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -40,6 +40,7 @@
 #include <mailutils/cctype.h>
 #include <mailutils/stream.h>
 #include <mailutils/stdstream.h>
+#include <mailutils/cidr.h>
 
 int mu_cfg_parser_verbose;
 static mu_list_t /* of mu_cfg_node_t */ parse_node_list; 
@@ -781,385 +782,52 @@ pop_section (struct scan_tree_data *dat)
   return sec;
 }
 
-#define STRTONUM(s, type, base, res, limit, loc)			\
-  {									\
-    type sum = 0;							\
-    									\
-    for (; *s; s++)							\
-      {									\
-	type x;								\
-									\
-	if ('0' <= *s && *s <= '9')					\
-	  x = sum * base + *s - '0';					\
-	else if (base == 16 && 'a' <= *s && *s <= 'f')			\
-	  x = sum * base + *s - 'a';					\
-	else if (base == 16 && 'A' <= *s && *s <= 'F')			\
-	  x = sum * base + *s - 'A';					\
-	else								\
-	  break;							\
-	if (x <= sum)							\
-	  {								\
-	    mu_diag_at_locus (MU_LOG_ERROR, loc,			\
-			      _("numeric overflow"));		        \
-	    mu_cfg_error_count++;					\
-	    return 1;							\
-	  }								\
-	else if (limit && x > limit)					\
-	  {								\
-	    mu_diag_at_locus (MU_LOG_ERROR, loc,			\
-			      _("value out of allowed range"));		\
-	    mu_cfg_error_count++;					\
-	    return 1;							\
-	  }								\
-	sum = x;							\
-      }									\
-    res = sum;								\
-  }
-
-#define STRxTONUM(s, type, res, limit, loc)				\
-  {									\
-    int base;								\
-    if (*s == '0')							\
-      {									\
-	s++;								\
-	if (*s == 0)							\
-	  base = 10;							\
-	else if (*s == 'x' || *s == 'X')				\
-	  {								\
-	    s++;							\
-	    base = 16;							\
-	  }								\
-	else								\
-	  base = 8;							\
-      } else								\
-      base = 10;							\
-    STRTONUM (s, type, base, res, limit, loc);				\
-  }
-
-#define GETUNUM(str, type, res, loc)					\
-  {									\
-    type tmpres;							\
-    const char *s = str;						\
-    STRxTONUM (s, type, tmpres, 0, loc);				\
-    if (*s)								\
-      {									\
-	mu_diag_at_locus (MU_LOG_ERROR, loc,			        \
-			  _("not a number (stopped near `%s')"),	\
-			  s);						\
-	mu_cfg_error_count++;						\
-	return 1;							\
-      }									\
-    res = tmpres;							\
-  }
-
-#define GETSNUM(str, type, res, loc)					\
-  {									\
-    unsigned type tmpres;						\
-    const char *s = str;						\
-    int sign;							        \
-    unsigned type limit;						\
-    									\
-    if (*s == '-')							\
-      {									\
-	sign = 1;							\
-	s++;								\
-	limit = TYPE_MINIMUM (type);					\
-	limit = - limit;						\
-      }									\
-    else								\
-      {									\
-	sign = 0;							\
-	limit = TYPE_MAXIMUM (type);					\
-      }									\
-    									\
-    STRxTONUM (s, unsigned type, tmpres, limit, loc);			\
-    if (*s)								\
-      {									\
-	mu_diag_at_locus (MU_LOG_ERROR, loc,			        \
-			  _("not a number (stopped near `%s')"),	\
-			  s);						\
-	mu_cfg_error_count++;						\
-	return 1;							\
-      }									\
-    res = sign ? - tmpres : tmpres;					\
-  }
-
-static int
-parse_ipv4 (struct scan_tree_data *sdata, const struct mu_locus *locus,
-	    const char *str, struct in_addr *res)
-{
-  struct in_addr addr;
-  if (inet_aton (str, &addr) == 0)
-    {
-      mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus, _("not an IPv4"));
-      mu_cfg_error_count++;
-      return 1;
-    }
-  addr.s_addr = ntohl (addr.s_addr);
-  *res = addr;
-  return 0;
-}
-
-static int
-parse_host (struct scan_tree_data *sdata, const struct mu_locus *locus,
-	    const char *str, struct in_addr *res)
-{
-  struct in_addr addr;
-  struct hostent *hp = gethostbyname (str);
-  if (hp)
-    {
-      addr.s_addr = *(unsigned long *)hp->h_addr;
-    }
-  else if (inet_aton (str, &addr) == 0)
-    {
-      mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
-			_("cannot resolve hostname `%s'"),
-			str);
-      mu_cfg_error_count++;
-      return 1;
-    }
-  addr.s_addr = ntohl (addr.s_addr);
-  *res = addr;
-  return 0;
-}
-
 static int
-parse_cidr (struct scan_tree_data *sdata, const struct mu_locus *locus,
-	    const char *str, mu_cfg_cidr_t *res)
+valcvt (const struct mu_locus *locus,
+	void *tgt, mu_c_type_t type, mu_config_value_t *val)
 {
-  struct in_addr addr;
-  unsigned long mask;
-  char astr[16];
-  const char *p, *s;
-  
-  p = strchr (str, '/');
-  if (p)
-    {
-      int len = p - str;
-      if (len > sizeof astr - 1)
-	{
-	  mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
-			    _("not a valid IPv4 address in CIDR"));
-	  mu_cfg_error_count++;
-	  return 1;
-	}
-      memcpy (astr, str, len);
-      astr[len] = 0;
-      if (inet_aton (astr, &addr) == 0)
-	{
-	  mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
-			    _("not a valid IPv4 address in CIDR"));
-	  mu_cfg_error_count++;
-	  return 1;
-	}
-      addr.s_addr = ntohl (addr.s_addr);
-      
-      p++;
-      s = p;
-      STRxTONUM (s, unsigned long, mask, 0, locus);
-      if (*s == '.')
-	{
-	  struct in_addr a;
-	  if (inet_aton (p, &a) == 0)
-	    {
-	      mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
-				_("not a valid network in CIDR"));
-	      mu_cfg_error_count++;
-	      return 1;
-	    }
-	  a.s_addr = ntohl (a.s_addr);
-	  for (mask = 0; (a.s_addr & 1) == 0 && mask < 32; )
-	    {
-	      mask++;
-	      a.s_addr >>= 1;
-	    }
-	  mask = 32 - mask;
-	}
-      else if (mask > 32)
-	{
-	  mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
-			    _("not a valid network mask in CIDR"));
-	  mu_cfg_error_count++;
-	  return 1;
-	}
-    }
-  else
-    {
-      int i;
-      unsigned short x;
-      addr.s_addr = 0;
-      
-      p = str;
-      for (i = 0; i < 3; i++)
-	{
-	  STRxTONUM (p, unsigned short, x, 255, locus);
-	  if (*p != '.')
-	    break;
-	  addr.s_addr = (addr.s_addr << 8) + x;
-	}
-      
-      if (*p)
-	{
-	  mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus,
-			    _("not a CIDR (stopped near `%s')"),
-			    p);
-	  mu_cfg_error_count++;
-	  return 1;
-	}
-      
-      mask = i * 8;
-      
-      addr.s_addr <<= (4 - i) * 8;
-    }
+  int rc;
+  char *errmsg;
   
-  res->addr = addr;
-  res->mask = mask;
-  return 0;
-}
-
-int
-mu_cfg_parse_boolean (const char *str, int *res)
-{
-  if (strcmp (str, "yes") == 0
-      || strcmp (str, "on") == 0
-      || strcmp (str, "t") == 0
-      || strcmp (str, "true") == 0
-      || strcmp (str, "1") == 0)
-    *res = 1;
-  else if (strcmp (str, "no") == 0
-	   || strcmp (str, "off") == 0
-	   || strcmp (str, "nil") == 0
-	   || strcmp (str, "false") == 0
-	   || strcmp (str, "0") == 0)
-    *res = 0;
-  else
-    return 1;
-  return 0;
-}
-
-static int
-parse_bool (struct scan_tree_data *sdata, const struct mu_locus *locus,
-	    const char *str, int *res)
-{
-  if (mu_cfg_parse_boolean (str, res))
-    {
-      mu_diag_at_locus (MU_LOG_ERROR, locus, _("not a boolean"));
-      mu_cfg_error_count++;
-      return 1;
-    }
-  return 0;
-}
-
-static int
-valcvt (struct scan_tree_data *sdata, const struct mu_locus *locus,
-	void *tgt,
-	enum mu_cfg_param_data_type type, mu_config_value_t *val)
-{
   if (val->type != MU_CFG_STRING)
     {
       mu_diag_at_locus (MU_LOG_ERROR, locus, _("expected string value"));
       mu_cfg_error_count++;
       return 1;
     }
-  switch (type)
+
+  rc = mu_str_to_c (val->v.string, type, tgt, &errmsg);
+  if (rc)
     {
-    case mu_cfg_string:
-      {
-	char *s = mu_strdup (val->v.string);
-	/* FIXME: free tgt? */
-	*(char**)tgt = s;
-	break;
-      }
-      
-    case mu_cfg_short:
-      GETUNUM (val->v.string, short, *(short*)tgt, locus);
-      break;
-      
-    case mu_cfg_ushort:
-      GETUNUM (val->v.string, unsigned short, *(unsigned short*)tgt, locus);
-      break;
-      
-    case mu_cfg_int:
-      GETSNUM (val->v.string, int, *(int*)tgt, locus);
-      break;
-      
-    case mu_cfg_uint:
-      GETUNUM (val->v.string, unsigned int, *(unsigned int*)tgt, locus);
-      break;
-      
-    case mu_cfg_long:
-      GETSNUM (val->v.string, long, *(long*)tgt, locus);
-      break;
-      
-    case mu_cfg_ulong:
-      GETUNUM (val->v.string, unsigned long, *(unsigned long*)tgt, locus);
-      break;
-      
-    case mu_cfg_size:
-      GETUNUM (val->v.string, size_t, *(size_t*)tgt, locus);
-      break;
-      
-    case mu_cfg_off:
-      mu_diag_at_locus (MU_LOG_ERROR, locus, _("not implemented yet"));
-      mu_cfg_error_count++;
-      /* GETSNUM(node->tag_label, off_t, *(off_t*)tgt); */
-      return 1;
-      
-    case mu_cfg_time:
-      GETUNUM (val->v.string, time_t, *(time_t*)tgt, locus);
-      break;
-      
-    case mu_cfg_bool:
-      if (parse_bool (sdata, locus, val->v.string, (int*) tgt))
-	return 1;
-      break;
-      
-    case mu_cfg_ipv4:
-      if (parse_ipv4 (sdata, locus, val->v.string, (struct in_addr *)tgt))
-	return 1;
-      break;
-      
-    case mu_cfg_cidr:
-      if (parse_cidr (sdata, locus, val->v.string, (mu_cfg_cidr_t *)tgt))
-	return 1;
-      break;
-      
-    case mu_cfg_host:
-      if (parse_host (sdata, locus, val->v.string, (struct in_addr *)tgt))
-	return 1;
-      break;
-      
-    default:
-      return 1;
+      mu_diag_at_locus (MU_LOG_ERROR, locus, "%s",
+			errmsg ? errmsg : mu_strerror (rc));
+      free (errmsg);
     }
-  return 0;
+  return rc;
 }
 
 struct set_closure
 {
   mu_list_t list;
-  enum mu_cfg_param_data_type type;
+  int type;
   struct scan_tree_data *sdata;
   const struct mu_locus *locus;
 };
 
 static size_t config_type_size[] = {
-  sizeof (char*),          /* mu_cfg_string */
-  sizeof (short),          /* mu_cfg_short */
-  sizeof (unsigned short), /* mu_cfg_ushort */
-  sizeof (int),            /* mu_cfg_int */
-  sizeof (unsigned),       /* mu_cfg_uint */
-  sizeof (long),           /* mu_cfg_long */
-  sizeof (unsigned long),  /* mu_cfg_ulong */
-  sizeof (size_t),         /* mu_cfg_size */
-  sizeof (mu_off_t),       /* mu_cfg_off */
-  sizeof (time_t),         /* mu_cfg_time */
-  sizeof (int),            /* mu_cfg_bool */
-  sizeof (struct in_addr), /* mu_cfg_ipv4 */
-  sizeof (mu_cfg_cidr_t),  /* mu_cfg_cidr */
-  sizeof (struct in_addr), /* mu_cfg_host */
-  0,                       /* mu_cfg_callback */
-  0,                       /* mu_cfg_section */
+  [mu_c_string] = sizeof (char*),          
+  [mu_c_short]  = sizeof (short),          
+  [mu_c_ushort] = sizeof (unsigned short), 
+  [mu_c_int]    = sizeof (int),            
+  [mu_c_uint]   = sizeof (unsigned),       
+  [mu_c_long]   = sizeof (long),           
+  [mu_c_ulong]  = sizeof (unsigned long),  
+  [mu_c_size]   = sizeof (size_t),         
+  [mu_c_time]   = sizeof (time_t),         
+  [mu_c_bool]   = sizeof (int),            
+  [mu_c_ipv4]   = sizeof (struct in_addr), 
+  [mu_c_cidr]   = sizeof (struct mu_cidr), 
+  [mu_c_host]   = sizeof (struct in_addr), 
 };
 
 static int
@@ -1188,7 +856,7 @@ _set_fun (void *item, void *data)
       return 1;
     }
   
-  if (valcvt (clos->sdata, clos->locus, &tgt, clos->type, val) == 0)
+  if (valcvt (clos->locus, &tgt, clos->type, val) == 0)
     mu_list_append (clos->list, tgt);
   return 0;
 }
@@ -1274,7 +942,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
 	return 1;
     }
   else
-    return valcvt (sdata, &node->locus, tgt, clos.type, node->label);
+    return valcvt (&node->locus, tgt, clos.type, node->label);
   
   return 0;
 }
diff --git a/libmailutils/mailer/Makefile.am b/libmailutils/opt/Makefile.am
similarity index 77%
copy from libmailutils/mailer/Makefile.am
copy to libmailutils/opt/Makefile.am
index 2f78194..d229c45 100644
--- a/libmailutils/mailer/Makefile.am
+++ b/libmailutils/opt/Makefile.am
@@ -1,5 +1,5 @@
 # GNU Mailutils -- a suite of utilities for electronic mail
-# Copyright (C) 2010-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -15,10 +15,12 @@
 # Public License along with this library.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-noinst_LTLIBRARIES = libmailer.la
+noinst_LTLIBRARIES = libopt.la
 
-libmailer_la_SOURCES = \
- mailer.c\
- progmailer.c
+libopt_la_SOURCES = \
+ opt.c\
+ help.c\
+ progname.c
 
-AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
+AM_CPPFLAGS = \
+  @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
new file mode 100644
index 0000000..c3d9a6f
--- /dev/null
+++ b/libmailutils/opt/help.c
@@ -0,0 +1,345 @@
+/* help.c -- general-purpose command line option parser
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/alloc.h>
+#include <mailutils/opt.h>
+#include <mailutils/cctype.h>
+#include <mailutils/nls.h>
+
+#define LMARGIN 2
+#define DESCRCOLUMN 30
+#define RMARGIN 79
+#define GROUPCOLUMN 2
+#define USAGECOLUMN 13
+
+static void
+indent (size_t start, size_t col)
+{
+  for (; start < col; start++)
+    putchar (' ');
+}
+
+static void
+print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
+{
+  while (*descr)
+    {
+      size_t s = 0;
+      size_t i;
+      size_t width = rmargin - lmargin;
+      
+      for (i = 0; ; i++)
+	{
+	  if (descr[i] == 0 || descr[i] == ' ' || descr[i] == '\t')
+	    {
+	      if (i > width)
+		break;
+	      s = i;
+	      if (descr[i] == 0)
+		break;
+	    }
+	}
+      fwrite (descr, 1, s, stdout);
+      fputc ('\n', stdout);
+      descr += s;
+      if (*descr)
+	{
+	  indent (0, lmargin);
+	  descr++;
+	}
+    }
+}
+
+
+static size_t
+print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
+	      int *argsused)
+{
+  struct mu_option *opt = optbuf[num];
+  size_t next, i;
+  int delim;
+  int w;
+  
+  if (MU_OPTION_IS_GROUP_HEADER (opt))
+    {
+      if (num)
+	putchar ('\n');
+      indent (0, GROUPCOLUMN);
+      print_option_descr (gettext (opt->opt_doc), GROUPCOLUMN, RMARGIN);
+      putchar ('\n');
+      return num + 1;
+    }
+
+  /* count aliases */
+  for (next = num + 1;
+       next < optcnt && optbuf[next]->opt_flags & MU_OPTION_ALIAS;
+       next++);
+
+  if (opt->opt_flags & MU_OPTION_HIDDEN)
+    return next;
+
+  w = 0;
+  for (i = num; i < next; i++)
+    {
+      if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]))
+	{
+	  if (w == 0)
+	    {
+	      indent (0, LMARGIN);
+	      w = LMARGIN;
+	    }
+	  else
+	    w += printf (", ");
+	  w += printf ("-%c", optbuf[i]->opt_short);
+	  delim = ' ';
+	}
+    }
+  
+  for (i = num; i < next; i++)
+    {
+      if (MU_OPTION_IS_VALID_LONG_OPTION (optbuf[i]))
+	{
+	  if (w == 0)
+	    {
+	      indent (0, LMARGIN);
+	      w = LMARGIN;
+	    }
+	  else
+	    w += printf (", ");
+	  w += printf ("--%s", optbuf[i]->opt_long);
+	  delim = '=';
+	}
+    }
+  
+  if (opt->opt_arg)
+    {
+      *argsused = 1;
+      if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
+	{
+	  if (delim == '=')
+	    w += printf ("[=%s]", gettext (opt->opt_arg));
+	  else
+	    w += printf ("[%s]", gettext (opt->opt_arg));
+	}
+      else
+	w += printf ("%c%s", delim, gettext (opt->opt_arg));
+    }
+  if (w >= DESCRCOLUMN)
+    {
+      putchar ('\n');
+      w = 0;
+    }
+  indent (w, DESCRCOLUMN);
+  print_option_descr (gettext (opt->opt_doc), DESCRCOLUMN, RMARGIN);
+
+  return next;
+}
+
+void
+mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
+{
+  unsigned i;
+  int argsused = 0;
+
+  for (i = 0; i < optcnt; )
+    i = print_option (optbuf, optcnt, i, &argsused);
+  putchar ('\n');
+
+  if (argsused)
+    {
+      print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN);
+      putchar ('\n');
+    }
+}
+
+void
+mu_program_help (struct mu_parseopt *po)
+{
+  printf ("%s", _("Usage:"));
+  if (po->po_prog_name)
+    printf (" %s", po->po_prog_name);
+  printf (" [%s]...", _("OPTION"));
+  if (po->po_prog_args)
+    printf (" %s", gettext (po->po_prog_args));
+  putchar ('\n');
+  
+  if (po->po_prog_doc)
+    print_option_descr (gettext (po->po_prog_doc), 0, RMARGIN);
+  putchar ('\n');
+
+  mu_option_describe_options (po->po_optv, po->po_optc);
+
+  if (po->po_help_hook)
+    po->po_help_hook (stdout);
+
+  if (po->po_bug_address)
+    /* TRANSLATORS: The placeholder indicates the bug-reporting address
+       for this package.  Please add _another line_ saying
+       "Report translation bugs to <...>\n" with the address for translation
+       bugs (typically your translation team's web or email address).  */
+    printf (_("Report bugs to %s.\n"), po->po_bug_address);
+
+  if (po->po_package_name && po->po_package_url)
+    printf (_("%s home page: <%s>\n"),
+	    po->po_package_name, po->po_package_url);
+}
+
+static struct mu_option **option_tab;
+
+static int
+cmpidx_short (const void *a, const void *b)
+{
+  unsigned const *ai = (unsigned const *)a;
+  unsigned const *bi = (unsigned const *)b;
+
+  return option_tab[*ai]->opt_short - option_tab[*bi]->opt_short;
+}
+  
+static int
+cmpidx_long (const void *a, const void *b)
+{
+  unsigned const *ai = (unsigned const *)a;
+  unsigned const *bi = (unsigned const *)b;
+  struct mu_option const *ap = option_tab[*ai];
+  struct mu_option const *bp = option_tab[*bi];
+  return strcmp (ap->opt_long, bp->opt_long);
+}
+
+void
+mu_program_usage (struct mu_parseopt *po)
+{
+  unsigned i;
+  unsigned n;
+  char buf[RMARGIN+1];
+  unsigned *idxbuf;
+  unsigned nidx;
+
+  struct mu_option **optbuf = po->po_optv;
+  size_t optcnt = po->po_optc;
+  
+#define FLUSH								\
+  do									\
+    {									\
+      buf[n] = 0;							\
+      printf ("%s\n", buf);						\
+      n = USAGECOLUMN;							\
+      memset (buf, ' ', n);						\
+    }									\
+  while (0)
+#define ADDC(c)							        \
+  do									\
+    {									\
+      if (n == RMARGIN) FLUSH;						\
+      buf[n++] = c;							\
+    }									\
+  while (0)
+
+  option_tab = optbuf;
+  
+  idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
+
+  n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"),	mu_progname);
+  
+  /* Print a list of short options without arguments. */
+  for (i = nidx = 0; i < optcnt; i++)
+    if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && !optbuf[i]->opt_arg)
+      idxbuf[nidx++] = i;
+
+  if (nidx)
+    {
+      qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
+
+      ADDC ('[');
+      ADDC ('-');
+      for (i = 0; i < nidx; i++)
+	{
+	  ADDC (optbuf[idxbuf[i]]->opt_short);
+	}
+      ADDC (']');
+    }
+
+  /* Print a list of short options with arguments. */
+  for (i = nidx = 0; i < optcnt; i++)
+    {
+      if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && optbuf[i]->opt_arg)
+	idxbuf[nidx++] = i;
+    }
+
+  if (nidx)
+    {
+      qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
+    
+      for (i = 0; i < nidx; i++)
+	{
+	  struct mu_option *opt = optbuf[idxbuf[i]];
+	  const char *arg = gettext (opt->opt_arg);
+	  size_t len = 5 + strlen (arg) + 1;
+	  
+	  if (n + len > RMARGIN) FLUSH;
+	  buf[n++] = ' ';
+	  buf[n++] = '[';
+	  buf[n++] = '-';
+	  buf[n++] = opt->opt_short;
+	  buf[n++] = ' ';
+	  strcpy (&buf[n], arg);
+	  n += strlen (arg);
+	  buf[n++] = ']';
+	}
+    }
+  
+  /* Print a list of long options */
+  for (i = nidx = 0; i < optcnt; i++)
+    {
+      if (MU_OPTION_IS_VALID_LONG_OPTION (optbuf[i]))
+	idxbuf[nidx++] = i;
+    }
+
+  if (nidx)
+    {
+      qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_long);
+	
+      for (i = 0; i < nidx; i++)
+	{
+	  struct mu_option *opt = optbuf[idxbuf[i]];
+	  const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL;
+	  size_t len = 3 + strlen (opt->opt_long)
+	                 + (arg ? 1 + strlen (arg) : 0);
+	  if (n + len > RMARGIN) FLUSH;
+	  buf[n++] = ' ';
+	  buf[n++] = '[';
+	  buf[n++] = '-';
+	  buf[n++] = '-';
+	  strcpy (&buf[n], opt->opt_long);
+	  n += strlen (opt->opt_long);
+	  if (opt->opt_arg)
+	    {
+	      buf[n++] = '=';
+	      strcpy (&buf[n], arg);
+	      n += strlen (arg);
+	    }
+	  buf[n++] = ']';
+	}
+    }
+
+  FLUSH;
+  free (idxbuf);
+}
+
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
new file mode 100644
index 0000000..ba54f75
--- /dev/null
+++ b/libmailutils/opt/opt.c
@@ -0,0 +1,638 @@
+/* opt.c -- general-purpose command line option parser
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <mailutils/alloc.h>
+#include <mailutils/opt.h>
+#include <mailutils/nls.h>
+#include <mailutils/errno.h>
+
+#define EXIT_SUCCESS 0
+#define EXIT_ERROR   1
+
+/* Compare pointers to two option structs */
+static int
+optcmp (const void *a, const void *b)
+{
+  struct mu_option const *ap = *(struct mu_option const **)a;
+  struct mu_option const *bp = *(struct mu_option const **)b;
+
+  while (ap->opt_flags & MU_OPTION_ALIAS)
+    ap--;
+  while (bp->opt_flags & MU_OPTION_ALIAS)
+    bp--;
+  
+  if (MU_OPTION_IS_VALID_SHORT_OPTION (ap)
+      && MU_OPTION_IS_VALID_SHORT_OPTION (bp))
+    return ap->opt_short - bp->opt_short;
+  if (MU_OPTION_IS_VALID_LONG_OPTION (ap)
+      && MU_OPTION_IS_VALID_LONG_OPTION (bp))
+    return strcmp (ap->opt_long, bp->opt_long);
+  if (MU_OPTION_IS_VALID_LONG_OPTION (ap))
+    return 1;
+  return -1;
+}
+
+/* Sort a group of options in OPTBUF, starting at index START (first
+   option slot after a group header (if any).  The group spans up to
+   next group header or end of options */
+static size_t
+sort_group (struct mu_option **optbuf, size_t start)
+{
+  size_t i;
+  
+  for (i = start; optbuf[i] && !MU_OPTION_IS_GROUP_HEADER (optbuf[i]); i++)
+    ;
+  
+  qsort (&optbuf[start], i - start, sizeof (optbuf[0]), optcmp);
+  return i;
+}
+
+/* Print help summary and exit. */
+static void
+fn_help (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
+{
+  mu_program_help (po);
+  exit (EXIT_SUCCESS);
+}
+
+/* Print usage summary and exit. */
+static void
+fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
+{
+  mu_program_usage (po);
+  exit (EXIT_SUCCESS);
+}
+
+/* Default options */
+struct mu_option mu_default_options[] = {
+  MU_OPTION_GROUP(""),
+  { "help",    'h', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"),
+    mu_c_string, NULL, fn_help },
+  { "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
+    mu_c_string, NULL, /* FIXME: fn_version */ },
+  { "usage",   0,   NULL, MU_OPTION_IMMEDIATE, N_("give a short usage message"),
+    mu_c_string, NULL, fn_usage
+  },
+  MU_OPTION_END
+};
+
+/* Output error message */
+static void
+parse_error (struct mu_parseopt *po, char const *fmt, ...)
+{
+  va_list ap;
+
+  if (po->po_flags & MU_PARSEOPT_IGNORE_ERRORS)
+    return;
+
+  if (po->po_prog_name)
+    fprintf (stderr, "%s: ", po->po_prog_name);
+  va_start (ap, fmt);
+  vfprintf (stderr, fmt, ap);
+  va_end (ap);
+  fputc ('\n', stderr);
+}
+
+static void
+mu_option_cache_destroy (void *ptr)
+{
+  struct mu_option_cache *cache = ptr;
+  free (cache->cache_arg);
+  free (cache);
+}
+
+static int parseopt_apply (void *item, void *data);
+
+/* If OPT is an immediate option, evaluate it right away.  Otherwise,
+   add option OPT with argument ARG to the cache in PO. */
+void
+add_option_cache (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  struct mu_option_cache *cache = mu_alloc (sizeof (*cache));
+  cache->cache_opt = opt;
+  cache->cache_arg = arg ? mu_strdup (arg) : NULL;
+
+  if (opt->opt_flags & MU_OPTION_IMMEDIATE)
+    {
+      parseopt_apply (cache, po);
+      mu_option_cache_destroy (cache);
+    }
+  else
+    {
+      mu_list_append (po->po_optlist, cache);
+    }
+}
+
+/* Find first option for which I is an alias */
+struct mu_option *
+option_unalias (struct mu_parseopt *po, int i)
+{
+  while (i > 0 && po->po_optv[i]->opt_flags & MU_OPTION_ALIAS)
+    --i;
+  return po->po_optv[i];
+}
+
+/* Find a descriptor of short option CHR */
+struct mu_option *
+find_short_option (struct mu_parseopt *po, int chr)
+{
+  size_t i;
+
+  for (i = 0; i < po->po_optc; i++)
+    {
+      if (MU_OPTION_IS_VALID_SHORT_OPTION (po->po_optv[i])
+	  && po->po_optv[i]->opt_short == chr)
+	return option_unalias (po, i);
+    }
+  parse_error (po, _("unrecognized option '-%c'"), chr);
+  return NULL;
+}
+
+/* Find a descriptor of long option OPTSTR.  If it has argument, return
+   it in *ARGPTR. */
+struct mu_option *
+find_long_option (struct mu_parseopt *po, char const *optstr,
+		  char **argptr)
+{
+  size_t i;
+  size_t optlen;
+  size_t ind;
+  int found = 0;
+  
+  optlen = strcspn (optstr, "=");
+  
+  for (i = 0; i < po->po_optc; i++)
+    {
+      if (MU_OPTION_IS_VALID_LONG_OPTION (po->po_optv[i])
+	  && optlen <= strlen (po->po_optv[i]->opt_long)
+	  && memcmp (po->po_optv[i]->opt_long, optstr, optlen) == 0)
+	{
+	  switch (found)
+	    {
+	    case 0:
+	      ind = i;
+	      found++;
+	      break;
+
+	    case 1:
+	      if (po->po_flags & MU_PARSEOPT_IGNORE_ERRORS)
+		return NULL;
+	      parse_error (po,
+			   _("option '--%*.*s' is ambiguous; possibilities:"),
+			   optlen, optlen, optstr);
+	      fprintf (stderr, "--%s\n", po->po_optv[ind]->opt_long);
+	      found++;
+
+	    case 2:
+	      fprintf (stderr, "--%s\n", po->po_optv[i]->opt_long);
+	    }
+	}
+    }
+
+  switch (found)
+    {
+    case 0:
+      parse_error (po, _("unrecognized option '--%s'"), optstr);
+      break;
+      
+    case 1:
+      if (optstr[optlen])
+	++optlen;
+      *argptr = (char *)(optstr + optlen);
+      return option_unalias (po, ind);
+
+    case 2:
+      break;
+    }
+
+  return NULL;  
+}
+
+static void
+permute (struct mu_parseopt *po)
+{
+  if (!(po->po_flags & MU_PARSEOPT_IN_ORDER) && po->po_arg_count)
+    {
+      /* Array to save arguments in */
+      char *save[2];
+      /* Number of arguments processed (at most two) */
+      int n = po->po_ind - (po->po_arg_start + po->po_arg_count);
+      
+      if (n > 2)
+	abort ();
+      
+      /* Store the processed elements away */
+      save[0] = po->po_argv[po->po_arg_start + po->po_arg_count];
+      if (n == 2)
+	save[1] = po->po_argv[po->po_arg_start + po->po_arg_count + 1];
+
+      /* Shift the array */
+      memmove (po->po_argv + po->po_arg_start + n,
+	       po->po_argv + po->po_arg_start,
+	       po->po_arg_count * sizeof (po->po_argv[0]));
+      
+      /* Place stored elements in the vacating slots */
+      po->po_argv[po->po_arg_start] = save[0];
+      if (n == 2)
+	po->po_argv[po->po_arg_start + 1] = save[1];
+      
+      /* Fix up start index */
+      po->po_arg_start += n;
+      po->po_permuted = 1;
+    }
+}
+
+/* Consume next option from PO.  On success, update PO members as
+   described below and return 0.  On end of options, return 1.
+
+   If the consumed option is a short option, then 
+
+     po_chr  keeps its option character, and
+     po_cur  points to the next option character to be processed
+
+   Otherwise, if the consumed option is a long one, then
+
+     po_chr  is 0
+     po_cur  points to the first character after --
+*/   
+static int
+next_opt (struct mu_parseopt *po)
+{
+  if (!*po->po_cur)
+    {
+      permute (po);
+      
+      while (1)
+	{
+	  po->po_cur = po->po_argv[po->po_ind++];
+	  if (!po->po_cur)
+	    return 1;
+	  if (po->po_cur[0] == '-' && po->po_cur[1])
+	    break;
+	  if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
+	    {
+	      if (!po->po_permuted)
+		po->po_arg_start = po->po_ind - 1;
+	      po->po_arg_count++;
+	      continue;
+	    }
+	  else
+	    return 1;
+	}
+
+      if (*++po->po_cur == '-')
+	{
+	  if (*++po->po_cur == 0)
+	    {
+	      /* End of options */
+	      permute (po);
+	      ++po->po_ind;
+	      return 1;
+	    }
+
+	  /* It's a long option */
+	  po->po_chr = 0;
+	  return 0;
+	}
+    }
+
+  po->po_chr = *po->po_cur++;
+
+  return 0;
+}
+
+/* Parse options */
+static int
+parse (struct mu_parseopt *po)
+{
+  int rc;
+
+  rc = mu_list_create (&po->po_optlist);
+  if (rc)
+    return rc;
+  mu_list_set_destroy_item (po->po_optlist, mu_option_cache_destroy);
+  
+  po->po_ind = 0;
+  if (!(po->po_flags & MU_PARSEOPT_ARGV0))
+    {
+      po->po_ind++;
+      if (!(po->po_flags & MU_PARSEOPT_PROG_NAME))
+	{
+	  char *p = strrchr (po->po_argv[0], '/');
+	  if (p)
+	    p++;
+	  else
+	    p = (char*) po->po_argv[0];
+	  if (strlen (p) > 3 && memcmp (p, "lt-", 3) == 0)
+	    p += 3;
+	  po->po_prog_name = p;
+	}
+    }
+  else if (!(po->po_flags & MU_PARSEOPT_PROG_NAME))
+    po->po_prog_name = NULL;
+
+  po->po_arg_start = po->po_ind;
+  po->po_arg_count = 0;
+  po->po_permuted = 0;
+  
+  po->po_cur = "";
+
+  po->po_opterr = -1;
+  
+  while (next_opt (po) == 0)
+    {
+      struct mu_option *opt;
+      char *long_opt;
+      
+      if (po->po_chr)
+	{
+	  opt = find_short_option (po, po->po_chr);
+	  long_opt = NULL;
+	}
+      else
+	{
+	  long_opt = po->po_cur;
+	  opt = find_long_option (po, long_opt, &po->po_cur);
+	}
+
+      if (opt)
+	{
+	  char *arg = NULL;
+	  
+	  if (opt->opt_arg)
+	    {
+	      if (po->po_cur[0])
+		{
+		  arg = po->po_cur;
+		  po->po_cur = "";
+		}
+	      else if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
+		/* ignore it */;
+	      else if (po->po_ind < po->po_argc)
+		arg = po->po_argv[po->po_ind++];
+	      else
+		{
+		  if (long_opt)
+		    parse_error (po,
+				 _("option '--%s' requires an argument"),
+				 long_opt);
+		  else
+		    parse_error (po,
+				 _("option '-%c' requires an argument"),
+				 po->po_chr);
+		  po->po_opterr = po->po_ind;
+		  if (po->po_flags & MU_PARSEOPT_NO_ERREXIT)
+		    {
+		      if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
+			po->po_arg_count++;
+		      continue;
+		    }
+		  exit (EXIT_ERROR);
+		}	
+	    }
+	  else
+	    {
+	      if (long_opt
+		  && po->po_cur[0]
+		  && !(po->po_flags & MU_OPTION_ARG_OPTIONAL))
+		{
+		  parse_error (po,
+			       _("option '--%s' doesn't allow an argument"),
+			       long_opt);
+		  po->po_opterr = po->po_ind;
+		  if (po->po_flags & MU_PARSEOPT_NO_ERREXIT)
+		    {
+		      if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
+			po->po_arg_count++;
+		      continue;
+		    }
+		  exit (EXIT_ERROR);
+		}
+	      arg = NULL;
+	    }
+	  
+	  add_option_cache (po, opt, arg);
+	}
+      else
+	{
+	  po->po_opterr = po->po_ind;
+	  if (po->po_flags & MU_PARSEOPT_NO_ERREXIT)
+	    {
+	      if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
+		po->po_arg_count++;
+	      continue;
+	    }
+	  exit (EXIT_ERROR);
+	}
+    }
+
+  if (!po->po_permuted)
+    po->po_arg_start = po->po_ind - 1 - po->po_arg_count;
+  return 0;
+}
+
+/* Initialize structure mu_parseopt with given options and flags. */
+static int
+parseopt_init (struct mu_parseopt *po, struct mu_option **options,
+	       int flags)
+{
+  struct mu_option *opt;
+  size_t i, j;
+
+  memset (po, 0, sizeof *po);
+  po->po_argc = 0;
+  po->po_argv = NULL;
+  po->po_optc = 0;
+  po->po_flags = flags;
+    
+  /* Fix up flags */
+  if (flags & MU_PARSEOPT_IGNORE_ERRORS)
+    flags |= MU_PARSEOPT_NO_ERREXIT;
+
+  if (!(flags & MU_PARSEOPT_PROG_DOC))
+    po->po_prog_doc = NULL;
+  if (!(flags & MU_PARSEOPT_PROG_ARGS))
+    po->po_prog_args = NULL;
+  if (!(flags & MU_PARSEOPT_BUG_ADDRESS))
+    po->po_bug_address = NULL;
+  if (!(flags & MU_PARSEOPT_PACKAGE_NAME))
+    po->po_package_name = NULL;
+  if (!(flags & MU_PARSEOPT_PACKAGE_URL))
+    po->po_package_url = NULL;
+  if (!(flags & MU_PARSEOPT_PACKAGE_URL))
+    po->po_data = NULL;
+  if (!(flags & MU_PARSEOPT_HELP_HOOK))
+    po->po_help_hook = NULL;
+  
+  /* Count the options */
+  po->po_optc = 0;
+  for (i = 0; options[i]; i++)
+    for (opt = options[i]; !MU_OPTION_IS_END (opt); opt++)
+      ++po->po_optc;
+
+  if (!(flags & MU_PARSEOPT_NO_STDOPT))
+    for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++)
+      ++po->po_optc;
+  
+  /* Allocate the working buffer of option pointers */
+  po->po_optv = mu_calloc (po->po_optc + 1, sizeof (*po->po_optv));
+  if (!po->po_optv)
+    return -1;
+
+  /* Fill in the array */
+  j = 0;
+  for (i = 0; options[i]; i++)
+    for (opt = options[i]; !MU_OPTION_IS_END (opt); opt++, j++)
+      {
+	if (!opt->opt_set)
+	  opt->opt_set = mu_option_set_value;
+	po->po_optv[j] = opt;
+      }
+  
+  if (!(flags & MU_PARSEOPT_NO_STDOPT))
+    for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++, j++)
+      po->po_optv[j] = &mu_default_options[i];
+  
+  po->po_optv[j] = NULL;
+
+  /* Ensure sane start of options.  This is necessary, in particular,
+     because optcmp backs up until it finds an element with cleared
+     MU_OPTION_ALIAS bit. */
+  po->po_optv[0]->opt_flags &= MU_OPTION_ALIAS;
+  if (!(flags & MU_PARSEOPT_NO_SORT))
+    {
+      /* Sort the options */
+      size_t start;
+
+      for (start = 0; start < po->po_optc; )
+	{
+	  if (MU_OPTION_IS_GROUP_HEADER (po->po_optv[start]))
+	    start = sort_group (po->po_optv, start + 1);
+	  else 
+	    start = sort_group (po->po_optv, start);
+	}
+    }
+  return 0;
+}
+
+/* Parse command line from ARGC/ARGV. Valid options are given in
+   OPTIONS.  FLAGS control the parsing. */
+int
+mu_parseopt (struct mu_parseopt *po,
+	     int argc, char **argv, struct mu_option **options,
+	     int flags)
+{
+  int rc;
+
+  if (flags & MU_PARSEOPT_REUSE)
+    {
+      mu_list_clear (po->po_optlist);
+      po->po_flags = (po->po_flags & MU_PARSEOPT_IMMUTABLE_MASK)
+	                | (flags & ~MU_PARSEOPT_IMMUTABLE_MASK);
+    }
+  else
+    {
+      rc = parseopt_init (po, options, flags);
+      if (rc)
+	return rc;
+    }
+  po->po_argc = argc;
+  po->po_argv = argv;
+  
+  rc = parse (po);
+
+  if (rc == 0)
+    {
+      if (po->po_opterr >= 0)
+	rc = -1; 
+      else
+	{
+	  if (po->po_flags & MU_PARSEOPT_IMMEDIATE)
+	    rc = mu_parseopt_apply (po);
+	}
+    }
+
+  return rc;
+}
+
+void
+mu_parseopt_free (struct mu_parseopt *popt)
+{
+  free (popt->po_optv);
+  mu_list_destroy (&popt->po_optlist);
+}
+
+static int
+parseopt_apply (void *item, void *data)
+{
+  struct mu_option_cache *cp = item;
+  struct mu_parseopt *popt = data;
+  cp->cache_opt->opt_set (popt, cp->cache_opt, cp->cache_arg);
+  return 0;
+}
+
+int
+mu_parseopt_apply (struct mu_parseopt *popt)
+{
+  return mu_list_foreach (popt->po_optlist, parseopt_apply, popt);
+}
+
+void
+mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
+		     char const *arg)
+{
+  if (opt->opt_ptr)
+    {
+      char *errmsg;
+      int rc;
+      
+      if (arg == NULL)
+	{
+	  if (opt->opt_arg == NULL)
+	    arg = "1";
+	  else
+	    {
+	      *(void**)opt->opt_ptr = NULL;
+	      return;
+	    }
+	}
+      rc = mu_str_to_c (arg, opt->opt_type, opt->opt_ptr, &errmsg);
+      if (rc)
+	{
+	  char const *errtext;
+	  if (errmsg)
+	    errtext = errmsg;
+	  else
+	    errtext = mu_strerror (rc);
+
+	  if (opt->opt_long)
+	    parse_error (po, "--%s: %s", opt->opt_long, errtext);
+	  else
+	    parse_error (po, "-%c: %s", opt->opt_short, errtext);
+	  free (errmsg);
+
+	  if (!(po->po_flags & MU_PARSEOPT_NO_ERREXIT))
+	    exit (EXIT_ERROR);
+	}
+    }
+}
diff --git a/libmu_cfg/virtdomain.c b/libmailutils/opt/progname.c
similarity index 57%
copy from libmu_cfg/virtdomain.c
copy to libmailutils/opt/progname.c
index c2dc2cc..19d430e 100644
--- a/libmu_cfg/virtdomain.c
+++ b/libmailutils/opt/progname.c
@@ -1,6 +1,5 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
-   Inc.
+/* help.c -- general-purpose command line option parser
+   Copyright (C) 2016 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -15,22 +14,32 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 */
-
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
 #include <stdlib.h>
-#include "mailutils/libcfg.h"
+#include <string.h>
+#include <mailutils/alloc.h>
+#include <mailutils/opt.h>
 
-static struct mu_gocs_virtual virtdomain_settings;
+char *mu_progname;
+char *mu_absprogname;
 
-static struct mu_cfg_param mu_virtdomain_param[] = {
-  { "passwd-dir", mu_cfg_string, &virtdomain_settings, 0, NULL,
-    N_("Name of the directory where virtual domain password files are "
-       "located."),
-    N_("dir") },
-  { NULL }
-};
+void
+mu_set_progname (char const *arg)
+{
+  char *p;
 
-DCL_CFG_CAPA (virtdomain);
-     
+  free (mu_absprogname);
+  mu_absprogname = mu_strdup (arg);
+  
+  p = strrchr (arg, '/');
+  if (p)
+    ++p;
+  else
+    p = (char*) arg;
+  if (strlen (p) > 3 && memcmp (p, "lt-", 3) == 0)
+    p += 3;
+  free (mu_progname);
+  mu_progname = mu_strdup (p);
+}
diff --git a/libmailutils/server/msrv.c b/libmailutils/server/msrv.c
index 3ef1f78..a60fd53 100644
--- a/libmailutils/server/msrv.c
+++ b/libmailutils/server/msrv.c
@@ -890,24 +890,24 @@ _cb_port (void *data, mu_config_value_t *val)
 }
 
 static struct mu_cfg_param dot_server_cfg_param[] = {
-  { "max-children", mu_cfg_size,
+  { "max-children", mu_c_size,
     NULL, mu_offsetof (struct _mu_m_server,max_children), NULL,
     N_("Maximum number of children processes to run simultaneously.") },
   { "mode", mu_cfg_callback,
     NULL, mu_offsetof (struct _mu_m_server,mode), _cb_daemon_mode,
     N_("Set daemon mode (either inetd (or interactive) or daemon)."),
     N_("mode") },
-  { "foreground", mu_cfg_bool,
+  { "foreground", mu_c_bool,
     NULL, mu_offsetof (struct _mu_m_server, foreground), NULL,
     N_("Run in foreground.") },
-  { "pidfile", mu_cfg_string,
+  { "pidfile", mu_c_string,
     NULL, mu_offsetof (struct _mu_m_server,pidfile), NULL,
     N_("Store PID of the master process in this file."),
     N_("file") },
   { "port", mu_cfg_callback,
     NULL, mu_offsetof (struct _mu_m_server, hints), _cb_port,
     N_("Default port number.") },
-  { "timeout", mu_cfg_time,
+  { "timeout", mu_c_time,
     NULL, mu_offsetof (struct _mu_m_server,timeout), NULL,
     N_("Set idle timeout.") },
   { "server", mu_cfg_section, NULL, 0, NULL,
@@ -918,13 +918,13 @@ static struct mu_cfg_param dot_server_cfg_param[] = {
 };
     
 static struct mu_cfg_param server_cfg_param[] = {
-  { "single-process", mu_cfg_bool, 
+  { "single-process", mu_c_bool, 
     NULL, mu_offsetof (struct mu_srv_config, single_process), NULL,
     N_("Do not spawn sub-process to handle requests in this server.") },
-  { "transcript", mu_cfg_bool,
+  { "transcript", mu_c_bool,
     NULL, mu_offsetof (struct mu_srv_config, transcript), NULL,
     N_("Log the session transcript.") },
-  { "timeout", mu_cfg_time,
+  { "timeout", mu_c_time,
     NULL, mu_offsetof (struct mu_srv_config, timeout), NULL,
     N_("Set idle timeout.") },
   { "acl", mu_cfg_section,
diff --git a/libmailutils/string/Makefile.am b/libmailutils/string/Makefile.am
index a9fbd56..47e578e 100644
--- a/libmailutils/string/Makefile.am
+++ b/libmailutils/string/Makefile.am
@@ -25,6 +25,7 @@ libstring_la_SOURCES = \
  cstrupper.c\
  hexstr.c\
  stpcpy.c\
+ str_to_c.c\
  strltrim.c\
  strskip.c\
  stripws.c\
@@ -40,4 +41,6 @@ libstring_la_SOURCES = \
  wordsplit.c\
  xdecode.c
 
-AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
+EXTRA_DIST=to_sn.c to_un.c
+
+AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils -I${srcdir}
diff --git a/libmailutils/string/str_to_c.c b/libmailutils/string/str_to_c.c
new file mode 100644
index 0000000..4a3b23b
--- /dev/null
+++ b/libmailutils/string/str_to_c.c
@@ -0,0 +1,295 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <string.h>
+#include <mailutils/cidr.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/util.h>
+#include <mailutils/alloc.h>
+#include <mailutils/cctype.h>
+#include <mailutils/io.h>
+#include <mailutils/nls.h>
+
+typedef int (*str_to_c_t) (void *tgt, char const *string, char **errmsg);
+
+static int
+to_string (void *tgt, char const *string, char **errmsg)
+{
+  char **cptr = tgt;
+  if (string)
+    {
+      *cptr = mu_strdup (string);
+      if (!*cptr)
+	return errno;
+    }
+  else
+    *cptr = NULL;
+  return 0;
+}
+
+#define STR_TO_FUN to_short
+#define STR_TO_TYPE signed short
+#define STR_TO_MIN SHRT_MIN
+#define STR_TO_MAX SHRT_MAX
+#include "to_sn.c"
+
+#define STR_TO_FUN to_ushort
+#define STR_TO_TYPE unsigned short
+#define STR_TO_MAX USHRT_MAX
+#include "to_un.c"
+
+#define STR_TO_FUN to_int
+#define STR_TO_TYPE signed int
+#define STR_TO_MIN INT_MIN
+#define STR_TO_MAX INT_MAX
+#include "to_sn.c"
+
+#define STR_TO_FUN to_uint
+#define STR_TO_TYPE unsigned int
+#define STR_TO_MAX UINT_MAX
+#include "to_un.c"
+
+#define STR_TO_FUN to_long
+#define STR_TO_TYPE signed long
+#define STR_TO_MIN LONG_MIN
+#define STR_TO_MAX LONG_MAX
+#include "to_sn.c"
+
+#define STR_TO_FUN to_ulong
+#define STR_TO_TYPE unsigned long
+#define STR_TO_MAX ULONG_MAX
+#include "to_un.c"
+
+#define STR_TO_FUN to_size_t
+#define STR_TO_TYPE size_t
+#define STR_TO_MAX ((size_t)-1)
+#include "to_un.c"
+
+static int
+time_multiplier (const char *str, unsigned *m, unsigned *plen)
+{
+  static struct timetab
+  {
+    char *name;
+    unsigned mul;
+  } tab[] = {
+    { "seconds", 1 },
+    { "minutes", 60 },
+    { "hours", 60*60 },
+    { "days",  24*60*60 },
+    { "weeks", 7*24*60*60 },
+    { "months", 31*7*24*60*60 },
+    { NULL }
+  };
+  struct timetab *p;
+  int slen;
+
+  for (slen = 0; str[slen]; slen++)
+    if (mu_isspace (str[slen]))
+      break;
+
+  for (p = tab; p->name; p++)
+    {
+      if (p->name[0] == mu_tolower (str[0]))
+	{
+	  int nlen = strlen (p->name);
+
+	  if (nlen > slen)
+	    nlen = slen;
+			
+	  if (strncasecmp (p->name, str, nlen) == 0) {
+	    *m = p->mul;
+	    if (plen)
+	      *plen = nlen;
+	    return 0;
+	  }
+	}
+    }
+  return 1;
+}
+
+static int
+to_time_t (void *tgt, char const *string, char **errmsg)
+{
+  time_t *ptr = tgt;
+  int rc = 0;
+  time_t interval = 0;
+
+  while (*string)
+    {
+      char *p;
+      unsigned long n;
+      unsigned mul, len;
+
+      while (*string && mu_isspace (*string))
+	string++;
+
+      if (!mu_isdigit (*string) && time_multiplier (string, &mul, &len) == 0)
+	{
+	  n = 1;
+	  string += len;
+	}
+      else
+	{
+	  n = strtoul (string, &p, 10);
+	  if (*p && !mu_isspace (*p))
+	    {
+	      string = p;
+	      rc = 1;
+	      break;
+	    }
+	  
+	  while (*p && mu_isspace (*p))
+	    p++;
+
+	  string = p;
+	  if (*string)
+	    {
+	      if ((rc = time_multiplier (string, &mul, &len)))
+		break;
+	      string += len;
+	    }
+	  else
+	    mul = 1;
+	}
+      interval += n * mul;
+    }
+
+  if (rc)
+    {
+      if (errmsg)
+	mu_asprintf (errmsg, _("invalid time specification near %s"), string);
+      return EINVAL;
+    }
+  
+  *ptr = interval;
+  return 0;
+}
+  
+static int
+to_bool (void *tgt, char const *string, char **errmsg)
+{
+  int *ptr = tgt;
+  
+  if (strcmp (string, "yes") == 0
+      || strcmp (string, "on") == 0
+      || strcmp (string, "t") == 0
+      || strcmp (string, "true") == 0
+      || strcmp (string, "1") == 0)
+    *ptr = 1;
+  else if (strcmp (string, "no") == 0
+	   || strcmp (string, "off") == 0
+	   || strcmp (string, "nil") == 0
+	   || strcmp (string, "false") == 0
+	   || strcmp (string, "0") == 0)
+    *ptr = 0;
+  else
+    return EINVAL;
+  
+  return 0;
+}
+
+#if 0
+static int
+to_ipv4 (void *tgt, char const *string, char **errmsg)
+{
+  struct in_addr *ptr = tgt;
+  struct in_addr addr;
+  
+  if (inet_aton (string, &addr) == 0)
+    {
+      mu_diag_at_locus (MU_LOG_ERROR, &mu_cfg_locus, _("not an IPv4"));
+      mu_cfg_error_count++;
+      return 1;
+    }
+  addr.s_addr = ntohl (addr.s_addr);
+
+  *ptr = addr;
+  return 0;
+}
+#endif
+
+static int
+to_cidr (void *tgt, char const *string, char **errmsg)
+{
+  struct mu_cidr *ptr = tgt;
+  return mu_cidr_from_string (ptr, string);
+}
+
+static int
+to_incr (void *tgt, char const *string, char **errmsg)
+{
+  ++*(int*)tgt;
+  return 0;
+}
+
+static str_to_c_t str_to_c[] = {
+  [mu_c_string] = to_string, 
+  [mu_c_short]  = to_short,  
+  [mu_c_ushort] = to_ushort, 
+  [mu_c_int]    = to_int,    
+  [mu_c_uint]   = to_uint,   
+  [mu_c_long]   = to_long,   
+  [mu_c_ulong]  = to_ulong,  
+  [mu_c_size]   = to_size_t,   
+  /* FIXME  [mu_c_off]    = { to_off,    generic_dealloc }, */
+  [mu_c_time]   = to_time_t, 
+  [mu_c_bool]   = to_bool,
+  /* FIXME [mu_c_ipv4]   = to_ipv4, */
+  [mu_c_cidr]   = to_cidr,
+  /* FIXME  [mu_c_host]   = { to_host,   generic_dealloc } */
+  [mu_c_incr]   = to_incr
+};
+
+char const *mu_c_type_str[] = {
+  [mu_c_string]  = "mu_c_string",
+  [mu_c_short]   = "mu_c_short",  
+  [mu_c_ushort]  = "mu_c_ushort", 
+  [mu_c_int]     = "mu_c_int",    
+  [mu_c_uint]    = "mu_c_uint",   
+  [mu_c_long]    = "mu_c_long",   
+  [mu_c_ulong]   = "mu_c_ulong",  
+  [mu_c_size]    = "mu_c_size",   
+  [mu_c_off]     = "mu_c_off",    
+  [mu_c_time]    = "mu_c_time",   
+  [mu_c_bool]    = "mu_c_bool",   
+  [mu_c_ipv4]    = "mu_c_ipv4",   
+  [mu_c_cidr]    = "mu_c_cidr",   
+  [mu_c_host]    = "mu_c_host",   
+  [mu_c_incr]    = "mu_c_incr",   
+  [mu_c_void]    = "mu_c_void"
+};
+
+int
+mu_str_to_c (char const *string, enum mu_c_type type, void *tgt, char **errmsg)
+{
+  if (errmsg)
+    *errmsg = NULL;
+  if ((size_t)type >= sizeof (str_to_c) / sizeof (str_to_c[0]))
+    return EINVAL;
+  if (!str_to_c[type])
+    return ENOSYS;
+  return str_to_c[type] (tgt, string, errmsg);
+}
diff --git a/libmailutils/string/to_sn.c b/libmailutils/string/to_sn.c
new file mode 100644
index 0000000..f3cbfec
--- /dev/null
+++ b/libmailutils/string/to_sn.c
@@ -0,0 +1,37 @@
+#ifndef STR_TO_FUN
+# error "STR_TO_FUN not defined"
+#endif
+#ifndef STR_TO_TYPE
+# error "STR_TO_TYPE not defined"
+#endif
+#ifndef STR_TO_MIN
+# error "STR_TO_MIN not defined"
+#endif
+#ifndef STR_TO_MAX
+# error "STR_TO_MAX not defined"
+#endif
+
+static int
+STR_TO_FUN (void *tgt, char const *string, char **errmsg)
+{
+  STR_TO_TYPE *ptr = tgt;
+  intmax_t v;
+  char *p;
+  
+  errno = 0;
+  v = strtoimax (string, &p, 10);
+  if (errno)
+    return errno;
+  if (*p)
+    return EINVAL;
+  if (STR_TO_MIN <= v && v <= STR_TO_MAX)
+    {
+      *ptr = (STR_TO_TYPE) v;
+      return 0;
+    }
+  return ERANGE;
+}
+#undef STR_TO_FUN
+#undef STR_TO_TYPE
+#undef STR_TO_MIN
+#undef STR_TO_MAX
diff --git a/libmailutils/string/to_un.c b/libmailutils/string/to_un.c
new file mode 100644
index 0000000..b6878c0
--- /dev/null
+++ b/libmailutils/string/to_un.c
@@ -0,0 +1,34 @@
+#ifndef STR_TO_FUN
+# error "STR_TO_FUN not defined"
+#endif
+#ifndef STR_TO_TYPE
+# error "STR_TO_TYPE not defined"
+#endif
+#ifndef STR_TO_MAX
+# error "STR_TO_MAX not defined"
+#endif
+
+static int
+STR_TO_FUN (void *tgt, char const *string, char **errmsg)
+{
+  STR_TO_TYPE *ptr = tgt;
+  uintmax_t v;
+  char *p;
+  
+  errno = 0;
+  v = strtoumax (string, &p, 10);
+  if (errno)
+    return errno;
+  if (*p)
+    return EINVAL;
+  if (v <= STR_TO_MAX)
+    {
+      *ptr = (STR_TO_TYPE) v;
+      return 0;
+    }
+  return ERANGE;
+}
+
+#undef STR_TO_FUN
+#undef STR_TO_TYPE
+#undef STR_TO_MAX
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index fe72adf..51e4e68 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -20,11 +20,13 @@ mailcap
 mimehdr
 modtofsaf
 msgset
+parseopt
 prop
 scantime
 strftime
 strin
 strout
+strtoc
 tempfile
 url-comp
 url-parse
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 699d496..5655d80 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -56,11 +56,13 @@ noinst_PROGRAMS = \
  modtofsaf\
  msgset\
  modmesg\
+ parseopt\
  prop\
  scantime\
  strftime\
  strin\
  strout\
+ strtoc\
  tempfile\
  url-comp\
  url-parse\
@@ -102,12 +104,36 @@ TESTSUITE_AT = \
  modmesg03.at\
  modtofsaf.at\
  msgset.at\
+ parseopt00.at\
+ parseopt01.at\
+ parseopt02.at\
+ parseopt03.at\
+ parseopt04.at\
+ parseopt05.at\
+ parseopt06.at\
+ parseopt07.at\
+ parseopt08.at\
+ parseopt09.at\
+ parseopt10.at\
+ parseopt11.at\
+ parseopt12.at\
+ parseopt13.at\
+ parseopt14.at\
+ parseopt15.at\
+ parseopt16.at\
+ parseopt17.at\
+ parseopt18.at\
+ parseopt19.at\
+ parseopt20.at\
+ parseopt21.at\
+ parseopt22.at\
  prop.at\
  scantime.at\
  strftime.at\
  strerr.at\
  strin.at\
  strout.at\
+ strtoc.at\
  testsuite.at\
  url.at\
  url-comp.at\
diff --git a/libmailutils/tests/parseopt.c b/libmailutils/tests/parseopt.c
new file mode 100644
index 0000000..d3caf65
--- /dev/null
+++ b/libmailutils/tests/parseopt.c
@@ -0,0 +1,118 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/mailutils.h>
+#include <mailutils/opt.h>
+
+char *file_name;
+char *opt_value = "initial";
+char *find_value;
+int jobs = 0;
+int x_option;
+int a_option;
+int d_option;
+
+struct mu_option group_a[] = {
+  MU_OPTION_GROUP("Group A"),
+  { "file", 'f', "FILE", MU_OPTION_DEFAULT,
+    "set file name",
+    mu_c_string, &file_name
+  },
+  { "optional", 'o', "FILE", MU_OPTION_ARG_OPTIONAL,
+    "optional argument",
+    mu_c_string, &opt_value },
+  { NULL, 'x', NULL, MU_OPTION_DEFAULT,
+    "short-only option",
+    mu_c_incr, &x_option },
+  { "all", 'a', NULL, MU_OPTION_DEFAULT,
+    "no arguments to this one",
+    mu_c_bool, &a_option },
+  MU_OPTION_END
+};
+
+struct mu_option group_b[] = {
+  MU_OPTION_GROUP("Group B"),
+  { "debug", 'd', NULL, MU_OPTION_DEFAULT,
+    "another option",
+    mu_c_incr, &d_option },
+  { "verbose", 'v', NULL, MU_OPTION_ALIAS },
+  { "find", 'F', "VALUE", MU_OPTION_DEFAULT,
+    "find VALUE",
+    mu_c_string, &find_value },
+  { "jobs", 'j', "N", MU_OPTION_DEFAULT,
+    "sets numeric value",
+    mu_c_int, &jobs },
+  MU_OPTION_END
+};
+
+struct mu_option *optv[] = { group_a, group_b, NULL };
+
+#define S(s) ((s)?(s):"(null)")
+
+int
+main (int argc, char *argv[])
+{
+  struct mu_parseopt po;
+  int rc;
+  int i;
+  int flags = MU_PARSEOPT_DEFAULT;
+  
+  mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
+
+  if (getenv ("MU_PARSEOPT_DEFAULT"))
+    flags = MU_PARSEOPT_DEFAULT;
+  else
+    {
+      if (getenv ("MU_PARSEOPT_IN_ORDER"))
+	flags |= MU_PARSEOPT_IN_ORDER;
+      if (getenv ("MU_PARSEOPT_IGNORE_ERRORS"))
+	flags |= MU_PARSEOPT_IGNORE_ERRORS;
+      if (getenv ("MU_PARSEOPT_IN_ORDER"))
+	flags |= MU_PARSEOPT_IN_ORDER;
+      if (getenv ("MU_PARSEOPT_NO_ERREXIT"))
+	flags |= MU_PARSEOPT_NO_ERREXIT;
+      if (getenv ("MU_PARSEOPT_NO_STDOPT"))
+	flags |= MU_PARSEOPT_NO_STDOPT;
+    }
+  
+  rc = mu_parseopt (&po, argc, argv, optv, flags);
+  printf ("rc=%d\n", rc);
+  mu_parseopt_apply (&po);
+
+  argc -= po.po_arg_start;
+  argv += po.po_arg_start;
+
+  mu_parseopt_free (&po);
+
+  printf ("file_name=%s\n", S(file_name));
+  printf ("opt_value=%s\n", S(opt_value));
+  printf ("x_option=%d\n", x_option);
+  printf ("a_option=%d\n", a_option);
+  printf ("find_value=%s\n", S(find_value));
+  printf ("d_option=%d\n", d_option);
+  printf ("jobs=%d\n", jobs);
+  
+  printf ("argv:\n");
+  for (i = 0; i < argc; i++)
+    {
+      printf ("%d: %s\n", i, argv[i]);
+    }
+
+  return 0;
+}
diff --git a/libmailutils/tests/strout.at b/libmailutils/tests/parseopt00.at
similarity index 73%
copy from libmailutils/tests/strout.at
copy to libmailutils/tests/parseopt00.at
index b71219d..245b637 100644
--- a/libmailutils/tests/strout.at
+++ b/libmailutils/tests/parseopt00.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,23 +14,21 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strout])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([empty command line])
+AT_KEYWORDS([parseopt parseopt00])
 AT_CHECK([
-strout now is the time for all good men
+MU_PARSEOPT_DEFAULT=1
+parseopt
 ],
 [0],
-[now
-is
-the
-time
-for
-all
-good
-men
+[rc=0
+file_name=(null)
+opt_value=initial
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
 ])
-
 AT_CLEANUP
-
-
diff --git a/libmailutils/tests/strerr.at b/libmailutils/tests/parseopt01.at
similarity index 68%
copy from libmailutils/tests/strerr.at
copy to libmailutils/tests/parseopt01.at
index c100777..ca9517d 100644
--- a/libmailutils/tests/strerr.at
+++ b/libmailutils/tests/parseopt01.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,24 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strerr])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([command line without options])
+AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
 AT_CHECK([
-strout -err now is the time for all good men
+MU_PARSEOPT_DEFAULT=1
+parseopt command line arguments
 ],
 [0],
-[],
-[strout: now
-strout: is
-strout: the
-strout: time
-strout: for
-strout: all
-strout: good
-strout: men
+[rc=0
+file_name=(null)
+opt_value=initial
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
-
diff --git a/libmailutils/tests/strerr.at b/libmailutils/tests/parseopt02.at
similarity index 68%
copy from libmailutils/tests/strerr.at
copy to libmailutils/tests/parseopt02.at
index c100777..fb91d53 100644
--- a/libmailutils/tests/strerr.at
+++ b/libmailutils/tests/parseopt02.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,24 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strerr])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([short options])
+AT_KEYWORDS([parseopt parseopt_short parseopt02])
 AT_CHECK([
-strout -err now is the time for all good men
+MU_PARSEOPT_DEFAULT=1
+parseopt -f file -x -a -d command line arguments
 ],
 [0],
-[],
-[strout: now
-strout: is
-strout: the
-strout: time
-strout: for
-strout: all
-strout: good
-strout: men
+[rc=0
+file_name=file
+opt_value=initial
+x_option=1
+a_option=1
+find_value=(null)
+d_option=1
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt03.at
similarity index 66%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt03.at
index 053c741..08d2cfc 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt03.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([short option with argument])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_arg parseopt03])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt -ffile -x -a -d command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=file
+opt_value=initial
+x_option=1
+a_option=1
+find_value=(null)
+d_option=1
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt04.at
similarity index 65%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt04.at
index 053c741..319b196 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt04.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([short option with optional argument])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_arg parseopt04])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt -ofile command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=(null)
+opt_value=file
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt05.at
similarity index 65%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt05.at
index 053c741..830ddbb 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt05.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([short option without optional argument])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_noarg parseopt05])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt -o command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=(null)
+opt_value=(null)
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt06.at
similarity index 66%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt06.at
index 053c741..87bdfbe 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt06.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([incremental short option])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_incr parseopt06])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt -d -d command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=(null)
+opt_value=initial
+x_option=0
+a_option=0
+find_value=(null)
+d_option=2
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt07.at
similarity index 66%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt07.at
index 053c741..ae0fbb3 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt07.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([short option clustering])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_cluster parseopt07])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt -xffile -dado10 command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=file
+opt_value=10
+x_option=1
+a_option=1
+find_value=(null)
+d_option=2
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/libmailutils/tests/strerr.at b/libmailutils/tests/parseopt08.at
similarity index 68%
copy from libmailutils/tests/strerr.at
copy to libmailutils/tests/parseopt08.at
index c100777..0b020f1 100644
--- a/libmailutils/tests/strerr.at
+++ b/libmailutils/tests/parseopt08.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,24 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strerr])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([long options])
+AT_KEYWORDS([parseopt parseopt_long parseopt08])
 AT_CHECK([
-strout -err now is the time for all good men
+MU_PARSEOPT_DEFAULT=1
+parseopt --file=file --all command line arguments
 ],
 [0],
-[],
-[strout: now
-strout: is
-strout: the
-strout: time
-strout: for
-strout: all
-strout: good
-strout: men
+[rc=0
+file_name=file
+opt_value=initial
+x_option=0
+a_option=1
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt09.at
similarity index 66%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt09.at
index 053c741..7f6ca10 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt09.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([long option with argument])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt --file file command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=file
+opt_value=initial
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt10.at
similarity index 65%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt10.at
index 053c741..dbd0d42 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt10.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([long option with optional argument])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_arg parseopt10])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt --optional=file command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=(null)
+opt_value=file
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt11.at
similarity index 65%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt11.at
index 053c741..5284e52 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt11.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([long option without optional argument])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_noarg parseopt11])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt --optional command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=(null)
+opt_value=(null)
+x_option=0
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt12.at
similarity index 66%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt12.at
index 053c741..a8d56ca 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt12.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([incremental long option])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_incr parseopt12])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt --debug --debug command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=(null)
+opt_value=initial
+x_option=0
+a_option=0
+find_value=(null)
+d_option=2
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt13.at
similarity index 66%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt13.at
index 053c741..d67865f 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt13.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([abbreviated long options])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt13])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt --fil=file --fin=Word command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=file
+opt_value=initial
+x_option=0
+a_option=0
+find_value=Word
+d_option=0
+jobs=0
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/libmailutils/tests/strerr.at b/libmailutils/tests/parseopt14.at
similarity index 68%
copy from libmailutils/tests/strerr.at
copy to libmailutils/tests/parseopt14.at
index c100777..a06e425 100644
--- a/libmailutils/tests/strerr.at
+++ b/libmailutils/tests/parseopt14.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strerr])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([ambiguous abbreviated long options])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt_long_ambig parseopt14])
 AT_CHECK([
-strout -err now is the time for all good men
+MU_PARSEOPT_DEFAULT=1
+parseopt --fi=file --fi=Word command line arguments
 ],
-[0],
+[1],
 [],
-[strout: now
-strout: is
-strout: the
-strout: time
-strout: for
-strout: all
-strout: good
-strout: men
+[parseopt: option '--fi' is ambiguous; possibilities:
+--file
+--find
 ])
-
 AT_CLEANUP
-
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt15.at
similarity index 64%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt15.at
index 053c741..5c51090 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt15.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([mixed long and short options])
+AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt15.at])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+MU_PARSEOPT_DEFAULT=1
+parseopt --file=filename -o -xa --find word -j10 command line arguments
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=filename
+opt_value=(null)
+x_option=1
+a_option=1
+find_value=word
+d_option=0
+jobs=10
+argv:
+0: command
+1: line
+2: arguments
 ])
-
 AT_CLEANUP
-
diff --git a/libmailutils/tests/strerr.at b/libmailutils/tests/parseopt16.at
similarity index 72%
copy from libmailutils/tests/strerr.at
copy to libmailutils/tests/parseopt16.at
index c100777..af13145 100644
--- a/libmailutils/tests/strerr.at
+++ b/libmailutils/tests/parseopt16.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,24 +14,20 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strerr])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([option aliases])
+AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt16.at])
 AT_CHECK([
-strout -err now is the time for all good men
+parseopt -vvv
 ],
 [0],
-[],
-[strout: now
-strout: is
-strout: the
-strout: time
-strout: for
-strout: all
-strout: good
-strout: men
+[rc=0
+file_name=(null)
+opt_value=initial
+x_option=0
+a_option=0
+find_value=(null)
+d_option=3
+jobs=0
+argv:
 ])
-
 AT_CLEANUP
-
-
diff --git a/imap4d/tests/create01.at b/libmailutils/tests/parseopt17.at
similarity index 67%
copy from imap4d/tests/create01.at
copy to libmailutils/tests/parseopt17.at
index 02bf259..b82df13 100644
--- a/imap4d/tests/create01.at
+++ b/libmailutils/tests/parseopt17.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create])
-AT_KEYWORDS([create create00])
-
+AT_SETUP([argument permutation])
+AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt17.at])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create flat
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name flat
+parseopt more --file=file arguments follow -x -o options
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./flat
+[rc=0
+file_name=file
+opt_value=(null)
+x_option=1
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: more
+1: arguments
+2: follow
+3: options
 ])
-
 AT_CLEANUP
-
diff --git a/libmailutils/tests/strerr.at b/libmailutils/tests/parseopt18.at
similarity index 67%
copy from libmailutils/tests/strerr.at
copy to libmailutils/tests/parseopt18.at
index c100777..e9f753a 100644
--- a/libmailutils/tests/strerr.at
+++ b/libmailutils/tests/parseopt18.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,24 +14,24 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strerr])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([double-dash])
+AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
 AT_CHECK([
-strout -err now is the time for all good men
+parseopt -x --file=foobar -- -a --optional arg
 ],
 [0],
-[],
-[strout: now
-strout: is
-strout: the
-strout: time
-strout: for
-strout: all
-strout: good
-strout: men
+[rc=0
+file_name=foobar
+opt_value=initial
+x_option=1
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: -a
+1: --optional
+2: arg
 ])
-
 AT_CLEANUP
 
-
diff --git a/imap4d/tests/create02.at b/libmailutils/tests/parseopt19.at
similarity index 65%
copy from imap4d/tests/create02.at
copy to libmailutils/tests/parseopt19.at
index 053c741..94a59f7 100644
--- a/imap4d/tests/create02.at
+++ b/libmailutils/tests/parseopt19.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,25 +14,25 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([create nested])
-AT_KEYWORDS([create create01])
-
+AT_SETUP([double-dash with permutation])
+AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt19.at])
 AT_CHECK([
-AT_DATA([input],[dnl
-1 create en/to/tre
-X LOGOUT
-])
-
-imap4d IMAP4D_OPTIONS < input | tr -d '\r'
-find . -name tre
+parseopt -x more --file=foobar -- -a --optional arg
 ],
 [0],
-[* PREAUTH IMAP4rev1 Test mode
-1 OK CREATE Completed
-* BYE Session terminating.
-X OK LOGOUT Completed
-./en/to/tre
+[rc=0
+file_name=foobar
+opt_value=initial
+x_option=1
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: more
+1: -a
+2: --optional
+3: arg
 ])
-
 AT_CLEANUP
 
diff --git a/libmailutils/tests/strout.at b/libmailutils/tests/parseopt20.at
similarity index 73%
copy from libmailutils/tests/strout.at
copy to libmailutils/tests/parseopt20.at
index b71219d..092a8db 100644
--- a/libmailutils/tests/strout.at
+++ b/libmailutils/tests/parseopt20.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,23 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strout])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([short option without required argument])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_noarg parseopt20])
 AT_CHECK([
-strout now is the time for all good men
+parseopt -f
 ],
-[0],
-[now
-is
-the
-time
-for
-all
-good
-men
+[1],
+[],
+[parseopt: option '-f' requires an argument
 ])
-
-AT_CLEANUP
-
-
+AT_CLEANUP
\ No newline at end of file
diff --git a/testsuite/lstuid00.at b/libmailutils/tests/parseopt21.at
similarity index 73%
copy from testsuite/lstuid00.at
copy to libmailutils/tests/parseopt21.at
index 763743f..5982013 100644
--- a/testsuite/lstuid00.at
+++ b/libmailutils/tests/parseopt21.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,18 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([Assigning UIDs])
-
+AT_SETUP([long option without required argument])
+AT_KEYWORDS([parseopt parseopt_long parseopt_long_noarg parseopt21])
 AT_CHECK([
-MUT_MBCOPY($abs_top_srcdir/testsuite/spool/mbox1)
-lstuid mbox:mbox1
+parseopt --file
 ],
-[0],
-[1: 1
-2: 2
-3: 3
-4: 4
-5: 5
+[1],
+[],
+[parseopt: option '--file' requires an argument
 ])
-
 AT_CLEANUP
\ No newline at end of file
diff --git a/libmailutils/tests/strout.at b/libmailutils/tests/parseopt22.at
similarity index 75%
copy from libmailutils/tests/strout.at
copy to libmailutils/tests/parseopt22.at
index b71219d..d07f1d5 100644
--- a/libmailutils/tests/strout.at
+++ b/libmailutils/tests/parseopt22.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2011-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,23 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([strout])
-AT_KEYWORDS([stdstream])
-
+AT_SETUP([unrecognized option])
+AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
 AT_CHECK([
-strout now is the time for all good men
+parseopt -X
 ],
-[0],
-[now
-is
-the
-time
-for
-all
-good
-men
+[1],
+[],
+[parseopt: unrecognized option '-X'
 ])
-
-AT_CLEANUP
-
-
+AT_CLEANUP
\ No newline at end of file
diff --git a/mail/tests/version.at b/libmailutils/tests/strtoc.at
similarity index 85%
copy from mail/tests/version.at
copy to libmailutils/tests/strtoc.at
index a2367ab..583f05d 100644
--- a/mail/tests/version.at
+++ b/libmailutils/tests/strtoc.at
@@ -1,5 +1,5 @@
 # This file is part of GNU Mailutils. -*- Autotest -*-
-# Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
+# Copyright (C) 2016 Free Software Foundation, Inc.
 #
 # GNU Mailutils is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -14,6 +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/>.
 
-dnl m4_include([testsuite.inc])
-
-MUT_VERSION(mail)
+AT_SETUP([mu_str_to_c])
+AT_CHECK([strtoc])
+AT_CLEANUP
diff --git a/libmailutils/tests/strtoc.c b/libmailutils/tests/strtoc.c
new file mode 100644
index 0000000..64c3cb4
--- /dev/null
+++ b/libmailutils/tests/strtoc.c
@@ -0,0 +1,354 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include <mailutils/mailutils.h>
+
+union value
+{
+  char *v_string;
+  signed short v_short;
+  unsigned short v_ushort;
+  int v_int;
+  unsigned v_uint;
+  long v_long;
+  unsigned long v_ulong;
+  size_t v_size;
+  time_t v_time;
+  struct mu_cidr v_cidr;
+};
+
+struct value_handler
+{
+  void (*format) (union value *, FILE *);
+  int (*compare) (union value *, union value *);
+};
+
+static void
+v_string_format (union value *val, FILE *fp)
+{
+  char *p;
+	
+  fputc ('"', fp);
+  for (p = val->v_string; *p; p++)
+    {
+      if (*p == '\\' || *p == '"')
+	fputc ('\\', fp);
+      fputc (*p, fp);
+    }
+  fputc ('"', fp);
+}
+  
+static int
+v_string_compare (union value *a, union value *b)
+{
+  return strcmp (a->v_string, b->v_string);
+}
+
+static void
+v_short_format (union value *val, FILE *fp)
+{
+  fprintf (fp, "%hd", val->v_short); 
+}
+
+static int
+v_short_compare (union value *a, union value *b)
+{
+  return a->v_short != b->v_short;
+}
+
+static void
+v_ushort_format (union value *val, FILE *fp)
+{
+  fprintf (fp, "%hu", val->v_short);
+}
+
+static int
+v_ushort_compare (union value *a, union value *b)
+{
+  return a->v_ushort != b->v_ushort;
+}
+
+static void
+v_int_format (union value *val, FILE *fp)
+{
+  fprintf (fp, "%d", val->v_int);  
+}
+
+static int
+v_int_compare (union value *a, union value *b)
+{
+  return a->v_int != b->v_int;
+}
+
+static void
+v_uint_format (union value *val, FILE *fp)
+{
+  fprintf (fp, "%u", val->v_uint);
+}
+
+static int
+v_uint_compare (union value *a, union value *b)
+{
+  return a->v_uint != b->v_uint;
+}
+
+static void
+v_long_format (union value *val, FILE *fp)
+{
+  fprintf (fp, "%ld", val->v_long);  
+}
+
+static int
+v_long_compare (union value *a, union value *b)
+{
+  return a->v_long != b->v_long;
+}
+
+static void
+v_ulong_format (union value *val, FILE *fp)
+{
+  fprintf (fp, "%lu", val->v_long);  
+}
+
+static int
+v_ulong_compare (union value *a, union value *b)
+{
+  return a->v_ulong != b->v_ulong;
+}
+
+static void
+v_size_format (union value *val, FILE *fp)
+{
+  size_t v = val->v_size;
+  char buf[80];
+  size_t buflen = 80;
+  char *p = buf + buflen;
+  *--p = 0;
+  do
+    {
+      int n = v % 10;
+      *--p = n + '0';
+      v /= 10;
+    }
+  while (v && p > buf);
+
+  if (v)
+    fputs ("[overflow]", fp);
+  else
+    fputs (p, fp);
+}
+
+static int
+v_size_compare (union value *a, union value *b)
+{
+  return a->v_size != b->v_size;
+}
+
+static void
+v_cidr_format (union value *val, FILE *fp)
+{  
+  char *buf;
+
+  mu_cidr_format (&val->v_cidr, 0, &buf);
+  fprintf (fp, "%s", buf);
+  free (buf);
+}
+
+static int
+v_cidr_compare (union value *a, union value *b)
+{
+  if (a->v_cidr.family != b->v_cidr.family)
+    return 1;
+  if (a->v_cidr.len != b->v_cidr.len)
+    return 1;
+  if (memcmp (a->v_cidr.address, b->v_cidr.address, a->v_cidr.len))
+    return 1;
+  if (memcmp (a->v_cidr.netmask, b->v_cidr.netmask, a->v_cidr.len))
+    return 1;
+  return 0;
+}
+
+struct value_handler value_handler[] = {
+  [mu_c_string] = { v_string_format, v_string_compare },
+  [mu_c_short]  = { v_short_format, v_short_compare },
+  [mu_c_ushort] = { v_ushort_format, v_ushort_compare },
+  [mu_c_int]    = { v_int_format, v_int_compare },
+  [mu_c_uint]   = { v_uint_format, v_uint_compare },
+  [mu_c_long]   = { v_long_format, v_long_compare },
+  [mu_c_ulong]  = { v_ulong_format, v_ulong_compare },
+  [mu_c_size]   = { v_size_format, v_size_compare },
+#if 0
+    mu_c_time,
+#endif
+  [mu_c_bool]   = { v_int_format, v_int_compare },
+  [mu_c_cidr]   = { v_cidr_format, v_cidr_compare },
+  [mu_c_incr]   = { v_int_format, v_int_compare },
+};
+
+int
+valcmp (mu_c_type_t type, union value *a, union value *b)
+{
+  if ((size_t)type < sizeof (value_handler) / sizeof (value_handler[0])
+      && value_handler[type].compare)
+    return value_handler[type].compare (a, b);
+  else
+    {
+      fprintf (stderr, "unsupported value type: %d\n", type);
+      abort ();
+    }
+}
+
+void
+valprint (FILE *fp, mu_c_type_t type, union value *val)
+{
+  if ((size_t)type < sizeof (value_handler) / sizeof (value_handler[0])
+      && value_handler[type].format)
+    value_handler[type].format (val, fp);
+  else
+    {
+      fprintf (stderr, "unsupported value type: %d\n", type);
+      abort ();
+    }
+}
+
+struct testdata
+{
+  mu_c_type_t type;
+  char const *input;
+  int err;
+  union value val;
+};
+
+struct testdata tests[] = {
+  { mu_c_string, "now is the time", 0, { .v_string = "now is the time" } },
+  { mu_c_short,  "115",             0, { .v_short = 115 } },
+  { mu_c_short,  "-400",            0, { .v_short = -400 } },
+  { mu_c_short,  "1a",              EINVAL,  },
+
+  { mu_c_ushort, "110",             0, { .v_ushort = 110 } },
+  { mu_c_ushort, "-110",            ERANGE  },
+
+  { mu_c_int,    "10568",           0, { .v_int = 10568 } },
+  { mu_c_int,    "-10568",          0, { .v_int = -10568 } },
+
+  { mu_c_uint,   "10568",           0, { .v_uint = 10568 } },
+
+  { mu_c_long,   "10568",           0, { .v_long = 10568 } },
+  { mu_c_long,   "-10568",          0, { .v_long = -10568 } },
+
+  { mu_c_ulong,  "10568",           0, { .v_ulong = 10568 } },
+  
+  { mu_c_bool,   "true",            0, { .v_int = 1 } },
+  { mu_c_bool,   "false",           0, { .v_int = 0 } },
+
+  { mu_c_cidr,   "127.0.0.0/8",     0, { .v_cidr = {
+	.family = 2,
+	.len = 4,
+	.address = { 127, 0, 0, 0 },
+	.netmask = { 255 } } } },
+  { mu_c_cidr,   "fe80::4a5b:39ff:fe09:97f0/64", 0,  { .v_cidr = {
+	.family = 10,
+	.len = 16,
+	.address = { 0xfe, 0x80, 0x0,  0x0,  0x0,  0x0, 0x0,  0x0,
+		     0x4a, 0x5b, 0x39, 0xff, 0xfe, 0x9, 0x97, 0xf0 },
+	.netmask = { 255, 255, 255, 255, 255, 255, 255, 255,
+		     0,   0,   0,   0,   0,   0,   0,   0 } } } },
+  
+  { mu_c_incr,   NULL,              0, { .v_int = 1 } },
+  { mu_c_void }
+};
+
+void
+print_test_id (int i, FILE *fp)
+{
+  fprintf (fp, "%d: %s:%s: ", i, mu_c_type_str[tests[i].type],
+	   tests[i].input ? tests[i].input : "NULL");
+}	   
+
+void
+usage (int code, FILE *fp, char const *argv0)
+{
+  fprintf (fp, "usage: %s [-v]", argv0);
+  exit (code);
+}
+
+int
+main (int argc, char **argv)
+{
+  union value val;
+  char *errmsg;
+  int i;
+  unsigned failures = 0;
+  int verbose = 0;
+
+  for (i = 1; i < argc; i++) {
+    if (strcmp (argv[i], "-v") == 0)
+      verbose = 1;
+    else if (strcmp (argv[i], "-h") == 0)
+      usage (0, stdout, argv[0]);
+    else
+      usage (1, stderr, argv[0]);
+  }
+
+  if (i != argc)
+    usage (1, stderr, argv[0]);
+  
+  for (i = 0; tests[i].type != mu_c_void; i++)
+    {
+      int rc;
+
+      memset (&val, 0, sizeof (val));
+      rc = mu_str_to_c (tests[i].input, tests[i].type, &val, &errmsg);
+      if (rc)
+	{
+	  if (tests[i].err == rc)
+	    {
+	      if (verbose)
+		{
+		  print_test_id (i, stdout);
+		  fprintf (stdout, "XFAIL\n");
+		}
+	    }
+	  else
+	    {
+	      print_test_id (i, stderr);
+	      fprintf (stderr, "FAIL: error %s", mu_strerror (rc));
+	      if (errmsg)
+		fprintf (stderr, ": %s", errmsg);
+	      fputc ('\n', stderr);
+	      free (errmsg);
+	      ++failures;
+	    }
+	}
+      else if (valcmp (tests[i].type, &tests[i].val, &val))
+	{
+	  fprintf (stderr, "%d: FAIL: %s value differ: ",
+		   i, mu_c_type_str[tests[i].type]);
+	  fprintf (stderr, "expected: ");
+	  valprint (stderr, tests[i].type, &tests[i].val);
+	  fprintf (stderr, ", but got: ");
+	  valprint (stderr, tests[i].type, &val);
+	  fputc ('\n', stderr);
+	  ++failures;
+	}
+      else if (verbose)
+	{
+	  print_test_id (i, stdout);
+	  fprintf (stdout, "OK\n");
+	}
+    }
+  exit (!!failures);
+}
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index aa97088..be39fca 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -53,6 +53,34 @@ AT_CLEANUP
 
 AT_INIT
 
+AT_BANNER([Conversions])
+m4_include([strtoc.at])
+
+AT_BANNER([Command line parser])
+m4_include([parseopt00.at])
+m4_include([parseopt01.at])
+m4_include([parseopt02.at])
+m4_include([parseopt03.at])
+m4_include([parseopt04.at])
+m4_include([parseopt05.at])
+m4_include([parseopt06.at])
+m4_include([parseopt07.at])
+m4_include([parseopt08.at])
+m4_include([parseopt09.at])
+m4_include([parseopt10.at])
+m4_include([parseopt11.at])
+m4_include([parseopt12.at])
+m4_include([parseopt13.at])
+m4_include([parseopt14.at])
+m4_include([parseopt15.at])
+m4_include([parseopt16.at])
+m4_include([parseopt17.at])
+m4_include([parseopt18.at])
+m4_include([parseopt19.at])
+m4_include([parseopt20.at])
+m4_include([parseopt21.at])
+m4_include([parseopt22.at])
+
 AT_BANNER([Standard streams])
 m4_include([strin.at])
 m4_include([strout.at])
diff --git a/libmu_argp/muinit.c b/libmu_argp/muinit.c
index eb75fe3..50a4a9b 100644
--- a/libmu_argp/muinit.c
+++ b/libmu_argp/muinit.c
@@ -138,7 +138,7 @@ mu_app_init (struct argp *myargp, const char **capa,
       mu_stream_t stream;
       struct mu_cfg_cont *cont;
       static struct mu_cfg_param dummy_include_param[] = {
-	{ "include", mu_cfg_string, NULL, 0, NULL,
+	{ "include", mu_c_string, NULL, 0, NULL,
 	  N_("Include contents of the given file.  If a directory is given, "
 	     "include contents of the file <file>/<program>, where "
 	     "<program> is the name of the program.  This latter form is "
diff --git a/libmu_cfg/common.c b/libmu_cfg/common.c
index 6028c6e..1684b7f 100644
--- a/libmu_cfg/common.c
+++ b/libmu_cfg/common.c
@@ -49,14 +49,14 @@ _cb_folder (void *data, mu_config_value_t *val)
 }
 
 static struct mu_cfg_param mu_mailbox_param[] = {
-  { "mail-spool", mu_cfg_string, &mailbox_settings.mail_spool, 0, NULL,
+  { "mail-spool", mu_c_string, &mailbox_settings.mail_spool, 0, NULL,
     N_("Use specified URL as a mailspool directory."),
     N_("url") },
-  { "mailbox-pattern", mu_cfg_string, &mailbox_settings.mailbox_pattern,
+  { "mailbox-pattern", mu_c_string, &mailbox_settings.mailbox_pattern,
     0, NULL,
     N_("Create mailbox URL using <pattern>."),
     N_("pattern") },
-  { "mailbox-type", mu_cfg_string, &mailbox_settings.mailbox_type, 0, NULL,
+  { "mailbox-type", mu_c_string, &mailbox_settings.mailbox_type, 0, NULL,
     N_("Default mailbox type."), N_("protocol") },
   { "folder", mu_cfg_callback, NULL, 0, _cb_folder,
     N_("Default user mail folder"),
@@ -73,17 +73,17 @@ DCL_CFG_CAPA (mailbox);
 
 static struct mu_cfg_param mu_locking_param[] = {
   /* FIXME: Flags are superfluous. */
-  { "flags", mu_cfg_string, &locking_settings.lock_flags, 0, NULL,
+  { "flags", mu_c_string, &locking_settings.lock_flags, 0, NULL,
     N_("Default locker flags (E=external, R=retry, T=time, P=pid).") },
-  { "retry-timeout", mu_cfg_ulong, &locking_settings.lock_retry_timeout,
+  { "retry-timeout", mu_c_ulong, &locking_settings.lock_retry_timeout,
     0, NULL,
     N_("Set timeout for acquiring the lock.") },
-  { "retry-count", mu_cfg_ulong, &locking_settings.lock_retry_count, 0, NULL,
+  { "retry-count", mu_c_ulong, &locking_settings.lock_retry_count, 0, NULL,
     N_("Set the maximum number of times to retry acquiring the lock.") },
-  { "expire-timeout", mu_cfg_ulong, &locking_settings.lock_expire_timeout,
+  { "expire-timeout", mu_c_ulong, &locking_settings.lock_expire_timeout,
     0, NULL,
     N_("Expire locks older than this amount of time.") },
-  { "external-locker", mu_cfg_string, &locking_settings.external_locker, 
+  { "external-locker", mu_c_string, &locking_settings.external_locker, 
     0, NULL,
     N_("Use external locker program."),
     N_("prog") },
@@ -98,11 +98,11 @@ DCL_CFG_CAPA (locking);
 /* ************************************************************************* */
      
 static struct mu_cfg_param mu_address_param[] = {
-  { "email-addr", mu_cfg_string, &address_settings.address, 0, NULL,
+  { "email-addr", mu_c_string, &address_settings.address, 0, NULL,
     N_("Set the current user email address (default is "
        "loginname@defaultdomain)."),
     N_("email") },
-  { "email-domain", mu_cfg_string, &address_settings.domain, 0, NULL,
+  { "email-domain", mu_c_string, &address_settings.domain, 0, NULL,
     N_("Set e-mail domain for unqualified user names (default is this host)"),
     N_("domain") },
   { NULL }
@@ -116,7 +116,7 @@ DCL_CFG_CAPA (address);
 /* ************************************************************************* */
      
 static struct mu_cfg_param mu_mailer_param[] = {
-  { "url", mu_cfg_string, &mailer_settings.mailer, 0, NULL,
+  { "url", mu_c_string, &mailer_settings.mailer, 0, NULL,
     N_("Use this URL as the default mailer"),
     N_("url") },
   { NULL }
@@ -160,9 +160,9 @@ cb_severity (void *data, mu_config_value_t *val)
 }      
 
 static struct mu_cfg_param mu_logging_param[] = {
-  { "syslog", mu_cfg_bool, &mu_log_syslog, 0, NULL,
+  { "syslog", mu_c_bool, &mu_log_syslog, 0, NULL,
     N_("Send diagnostics to syslog.") },
-  { "print-severity", mu_cfg_bool, &mu_log_print_severity, 0, NULL,
+  { "print-severity", mu_c_bool, &mu_log_print_severity, 0, NULL,
     N_("Print message severity levels.") },
   { "severity", mu_cfg_callback, NULL, 0, cb_severity,
     N_("Output only messages with a severity equal to or greater than "
@@ -171,9 +171,9 @@ static struct mu_cfg_param mu_logging_param[] = {
     N_("Set syslog facility. Arg is one of the following: user, daemon, "
        "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
        "or a facility number.") },
-  { "session-id", mu_cfg_bool, &mu_log_session_id, 0, NULL,
+  { "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
     N_("Log session ID") },
-  { "tag", mu_cfg_string, &mu_log_tag, 0, NULL,
+  { "tag", mu_c_string, &mu_log_tag, 0, NULL,
     N_("Tag syslog messages with this string.") },
   { NULL }
 };
@@ -204,7 +204,7 @@ static struct mu_cfg_param mu_debug_param[] = {
     N_("Set Mailutils debugging level.  Argument is a colon-separated list "
        "of debugging specifications in the form:\n"
        "   <object: string>[[:]=<level: number>].") },
-  { "line-info", mu_cfg_bool, &debug_settings.line_info, 0, NULL,
+  { "line-info", mu_c_bool, &debug_settings.line_info, 0, NULL,
     N_("Prefix debug messages with Mailutils source locations.") },
   { NULL }
 };
diff --git a/libmu_cfg/gsasl.c b/libmu_cfg/gsasl.c
index f4d3fbb..539f8b9 100644
--- a/libmu_cfg/gsasl.c
+++ b/libmu_cfg/gsasl.c
@@ -26,21 +26,21 @@
 static struct mu_gsasl_module_data gsasl_settings;
 
 static struct mu_cfg_param mu_gsasl_param[] = {
-  { "enable", mu_cfg_bool, &gsasl_settings.enable, 0, NULL,
+  { "enable", mu_c_bool, &gsasl_settings.enable, 0, NULL,
     N_("Enable GSASL (default)") },
-  { "cram-passwd", mu_cfg_string, &gsasl_settings.cram_md5_pwd, 0, NULL,
+  { "cram-passwd", mu_c_string, &gsasl_settings.cram_md5_pwd, 0, NULL,
     N_("Name of GSASL password file."),
     N_("file") },
-  { "service", mu_cfg_string, &gsasl_settings.service, 0, NULL,
+  { "service", mu_c_string, &gsasl_settings.service, 0, NULL,
     N_("SASL service name."),
     N_("name") },
-  { "realm", mu_cfg_string, &gsasl_settings.realm, 0, NULL,
+  { "realm", mu_c_string, &gsasl_settings.realm, 0, NULL,
     N_("SASL realm name."),
     N_("name") },
-  { "hostname", mu_cfg_string, &gsasl_settings.hostname, 0, NULL,
+  { "hostname", mu_c_string, &gsasl_settings.hostname, 0, NULL,
     N_("SASL host name."),
     N_("name") },
-  { "anonymous-user", mu_cfg_string, &gsasl_settings.anon_user, 0, NULL,
+  { "anonymous-user", mu_c_string, &gsasl_settings.anon_user, 0, NULL,
     N_("Anonymous user name."),
     N_("name") },
 
diff --git a/libmu_cfg/ldap.c b/libmu_cfg/ldap.c
index 1da6734..ec47165 100644
--- a/libmu_cfg/ldap.c
+++ b/libmu_cfg/ldap.c
@@ -43,22 +43,22 @@ cb_field_map (void *data, mu_config_value_t *val)
 }
 
 static struct mu_cfg_param mu_ldap_param[] = {
-  { "enable", mu_cfg_bool, &ldap_settings.enable, 0, NULL,
+  { "enable", mu_c_bool, &ldap_settings.enable, 0, NULL,
     N_("Enable LDAP lookups.") },
-  { "url", mu_cfg_string, &ldap_settings.url, 0, NULL,
+  { "url", mu_c_string, &ldap_settings.url, 0, NULL,
     N_("Set URL of the LDAP server."),
     N_("url") },
-  { "base", mu_cfg_string, &ldap_settings.base, 0, NULL,
+  { "base", mu_c_string, &ldap_settings.base, 0, NULL,
     N_("Base DN for LDAP lookups."),
     N_("dn") },
-  { "binddn", mu_cfg_string, &ldap_settings.binddn, 0, NULL,
+  { "binddn", mu_c_string, &ldap_settings.binddn, 0, NULL,
     N_("DN for accessing LDAP database."),
     N_("dn") },
-  { "passwd", mu_cfg_string, &ldap_settings.passwd, 0, NULL,
+  { "passwd", mu_c_string, &ldap_settings.passwd, 0, NULL,
     N_("Password for use with binddn.") },
-  { "tls", mu_cfg_bool, &ldap_settings.tls, 0, NULL,
+  { "tls", mu_c_bool, &ldap_settings.tls, 0, NULL,
     N_("Use TLS encryption.") },
-  { "debug", mu_cfg_int, &ldap_settings.debug, 0, NULL,
+  { "debug", mu_c_int, &ldap_settings.debug, 0, NULL,
     N_("Set LDAP debugging level.") },
   { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
     N_("Set a field-map for parsing LDAP replies.  The map is a "
@@ -69,10 +69,10 @@ static struct mu_cfg_param mu_ldap_param[] = {
        "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
        "the corresponding LDAP attribute."),
     N_("map") },
-  { "getpwnam", mu_cfg_string, &ldap_settings.getpwnam_filter, 0, NULL,
+  { "getpwnam", mu_c_string, &ldap_settings.getpwnam_filter, 0, NULL,
     N_("LDAP filter to use for getpwnam requests."),
     N_("filter") },
-  { "getpwuid", mu_cfg_string, &ldap_settings.getpwuid_filter, 0, NULL,
+  { "getpwuid", mu_c_string, &ldap_settings.getpwuid_filter, 0, NULL,
     N_("LDAP filter to use for getpwuid requests."),
     N_("filter") },
   { NULL }
diff --git a/libmu_cfg/pam.c b/libmu_cfg/pam.c
index 33d50ab..ec8c9cc 100644
--- a/libmu_cfg/pam.c
+++ b/libmu_cfg/pam.c
@@ -25,7 +25,7 @@
 static char *pam_settings;
 
 static struct mu_cfg_param mu_pam_param[] = {
-  { "service", mu_cfg_string, &pam_settings, 0, NULL,
+  { "service", mu_c_string, &pam_settings, 0, NULL,
     N_("Set PAM service name."),
     N_("name") },
   { NULL }
diff --git a/libmu_cfg/radius.c b/libmu_cfg/radius.c
index cee0713..fb874a6 100644
--- a/libmu_cfg/radius.c
+++ b/libmu_cfg/radius.c
@@ -26,16 +26,16 @@
 static struct mu_radius_module_data radius_settings;
 
 static struct mu_cfg_param mu_radius_param[] = {
-  { "auth", mu_cfg_string, &radius_settings.auth_request, 0, NULL,
+  { "auth", mu_c_string, &radius_settings.auth_request, 0, NULL,
     N_("Radius request for authorization."),
     N_("request") },
-  { "getpwnam", mu_cfg_string, &radius_settings.getpwnam_request, 0, NULL,
+  { "getpwnam", mu_c_string, &radius_settings.getpwnam_request, 0, NULL,
     N_("Radius request for getpwnam."),
     N_("request") },
-  { "getpwuid", mu_cfg_string, &radius_settings.getpwuid_request, 0, NULL,
+  { "getpwuid", mu_c_string, &radius_settings.getpwuid_request, 0, NULL,
     N_("Radius request for getpwuid."),
     N_("request") },
-  { "directory", mu_cfg_string, &radius_settings.config_dir, 0, NULL,
+  { "directory", mu_c_string, &radius_settings.config_dir, 0, NULL,
     N_("Set radius configuration directory.") },
   { NULL }
 };
diff --git a/libmu_cfg/sieve.c b/libmu_cfg/sieve.c
index bd38f5d..fb4f106 100644
--- a/libmu_cfg/sieve.c
+++ b/libmu_cfg/sieve.c
@@ -32,7 +32,7 @@ cb_clear_library_path (void *data, mu_config_value_t *val)
 
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  if (mu_cfg_parse_boolean (val->v.string, &flag))
+  if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
     {
       mu_error (_("not a boolean"));
       return 1;
@@ -49,7 +49,7 @@ cb_clear_include_path (void *data, mu_config_value_t *val)
   
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  if (mu_cfg_parse_boolean (val->v.string, &flag))
+  if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
     {
       mu_error (_("not a boolean"));
       return 1;
diff --git a/libmu_cfg/sql.c b/libmu_cfg/sql.c
index fbacff0..af60300 100644
--- a/libmu_cfg/sql.c
+++ b/libmu_cfg/sql.c
@@ -57,31 +57,31 @@ cb_field_map (void *data, mu_config_value_t *val)
 }
 
 static struct mu_cfg_param mu_sql_param[] = {
-  { "interface", mu_cfg_string, &sql_settings.interface, 0, NULL,
+  { "interface", mu_c_string, &sql_settings.interface, 0, NULL,
     N_("Set SQL interface to use (one of: mysql, odbc, or postgres).") },
-  { "getpwnam", mu_cfg_string, &sql_settings.getpwnam_query, 0, NULL,
+  { "getpwnam", mu_c_string, &sql_settings.getpwnam_query, 0, NULL,
     N_("SQL query to use for getpwnam requests."),
     N_("query") },
-  { "getpwuid", mu_cfg_string, &sql_settings.getpwuid_query, 0, NULL,
+  { "getpwuid", mu_c_string, &sql_settings.getpwuid_query, 0, NULL,
     N_("SQL query to use for getpwuid requests."),
     N_("query") },
-  { "getpass", mu_cfg_string, &sql_settings.getpass_query, 0, NULL,
+  { "getpass", mu_c_string, &sql_settings.getpass_query, 0, NULL,
     N_("SQL query returning the user's password."),
     N_("query") },
-  { "host", mu_cfg_string, &sql_settings.host, 0, NULL,
+  { "host", mu_c_string, &sql_settings.host, 0, NULL,
     N_("SQL server host name.") },
-  { "user", mu_cfg_string, &sql_settings.user, 0, NULL,
+  { "user", mu_c_string, &sql_settings.user, 0, NULL,
     N_("SQL user name.") },
-  { "passwd", mu_cfg_string, &sql_settings.passwd, 0, NULL,
+  { "passwd", mu_c_string, &sql_settings.passwd, 0, NULL,
     N_("Password for the SQL user.") },
-  { "port", mu_cfg_int, &sql_settings.port, 0, NULL,
+  { "port", mu_c_int, &sql_settings.port, 0, NULL,
     N_("SQL server port.") },
-  { "db", mu_cfg_string, &sql_settings.db, 0, NULL,
+  { "db", mu_c_string, &sql_settings.db, 0, NULL,
     N_("Database name.") },
   { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
     N_("Type of password returned by getpass query (one of: plain, hash, "
        "scrambled).") },
-  { "positional", mu_cfg_bool, &sql_settings.positional, 0, NULL,
+  { "positional", mu_c_bool, &sql_settings.positional, 0, NULL,
     N_("Use positional (v1.0 compatible) field interface.") },
   { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
     N_("Set a field-map for parsing SQL replies.  The map is a "
diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
index 2004cbe..3d568ef 100644
--- a/libmu_cfg/tls.c
+++ b/libmu_cfg/tls.c
@@ -77,18 +77,18 @@ cb_safety_checks (void *data, mu_config_value_t *arg)
 }
 
 static struct mu_cfg_param mu_tls_param[] = {
-  { "enable", mu_cfg_bool, &tls_settings.enable, 0, NULL,
+  { "enable", mu_c_bool, &tls_settings.enable, 0, NULL,
     N_("Enable TLS encryption.") },
-  { "ssl-cert", mu_cfg_string, &tls_settings.ssl_cert, 0, NULL,
+  { "ssl-cert", mu_c_string, &tls_settings.ssl_cert, 0, NULL,
     N_("Specify SSL certificate file."),
     N_("file") },
-  { "ssl-key", mu_cfg_string, &tls_settings.ssl_key, 0, NULL,
+  { "ssl-key", mu_c_string, &tls_settings.ssl_key, 0, NULL,
     N_("Specify SSL certificate key file."),
     N_("file") },
-  { "ssl-cafile", mu_cfg_string, &tls_settings.ssl_cafile, 0, NULL,
+  { "ssl-cafile", mu_c_string, &tls_settings.ssl_cafile, 0, NULL,
     N_("Specify trusted CAs file."),
     N_("file") },
-  { "ssl-priorities", mu_cfg_string, &tls_settings.priorities, 0, NULL,
+  { "ssl-priorities", mu_c_string, &tls_settings.priorities, 0, NULL,
     N_("Set the priorities to use on the ciphers, key exchange methods, "
        "macs and compression methods."),
     NULL },
diff --git a/libmu_cfg/virtdomain.c b/libmu_cfg/virtdomain.c
index c2dc2cc..d4e2d1e 100644
--- a/libmu_cfg/virtdomain.c
+++ b/libmu_cfg/virtdomain.c
@@ -25,7 +25,7 @@
 static struct mu_gocs_virtual virtdomain_settings;
 
 static struct mu_cfg_param mu_virtdomain_param[] = {
-  { "passwd-dir", mu_cfg_string, &virtdomain_settings, 0, NULL,
+  { "passwd-dir", mu_c_string, &virtdomain_settings, 0, NULL,
     N_("Name of the directory where virtual domain password files are "
        "located."),
     N_("dir") },
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 0eac0c4..85d757b 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -284,7 +284,7 @@ cb_stderr (void *data, mu_config_value_t *val)
   
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  if (mu_cfg_parse_boolean (val->v.string, &res))
+  if (mu_str_to_c (val->v.string, mu_c_bool, &res, NULL))
     mu_error (_("not a boolean"));
   else
     mu_log_syslog = !res;
@@ -415,24 +415,24 @@ struct mu_cfg_param maidag_cfg_param[] = {
   { "delivery-mode", mu_cfg_callback, NULL, 0, cb_delivery_mode,
     N_("Set delivery mode"),
     N_("mode: {mda | url | lmtp}") },
-  { "exit-multiple-delivery-success", mu_cfg_bool, &multiple_delivery, 0, NULL,
+  { "exit-multiple-delivery-success", mu_c_bool, &multiple_delivery, 0, NULL,
     N_("In case of multiple delivery, exit with code 0 if at least one "
        "delivery succeeded.") },
-  { "exit-quota-tempfail", mu_cfg_bool, &ex_quota_tempfail, 0, NULL,
+  { "exit-quota-tempfail", mu_c_bool, &ex_quota_tempfail, 0, NULL,
     N_("Indicate temporary failure if the recipient is over his mail quota.")
   },
 #ifdef ENABLE_DBM
-  { "quota-db", mu_cfg_string, &quotadbname, 0, NULL,
+  { "quota-db", mu_c_string, &quotadbname, 0, NULL,
     N_("Name of DBM quota database file."),
     N_("file") },
 #endif
 #ifdef USE_SQL
-  { "quota-query", mu_cfg_string, &quota_query, 0, NULL,
+  { "quota-query", mu_c_string, &quota_query, 0, NULL,
     N_("SQL query to retrieve mailbox quota.  This is deprecated, use "
        "sql { ... } instead."),
     N_("query") },
 #endif
-  { "message-id-header", mu_cfg_string, &message_id_header, 0, NULL,
+  { "message-id-header", mu_c_string, &message_id_header, 0, NULL,
     N_("When logging Sieve actions, identify messages by the value of "
        "this header."),
     N_("name") },
@@ -445,12 +445,12 @@ struct mu_cfg_param maidag_cfg_param[] = {
        "  l - sieve action logs\n") },
   { "stderr", mu_cfg_callback, NULL, 0, cb_stderr,
     N_("Log to stderr instead of syslog.") },
-  { "forward-file", mu_cfg_string, &forward_file, 0, NULL,
+  { "forward-file", mu_c_string, &forward_file, 0, NULL,
     N_("Process forward file.") },
   { "forward-file-checks", mu_cfg_callback, NULL, 0, cb_forward_file_checks,
     N_("Configure safety checks for the forward file."),
     N_("arg: list") },
-  { "domain", mu_cfg_string, &default_domain, 0, NULL,
+  { "domain", mu_c_string, &default_domain, 0, NULL,
     N_("Default email domain") },
 /* LMTP support */
   { "group", mu_cfg_callback, &lmtp_groups, 0, cb_group,
@@ -463,7 +463,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
        "   file://<socket-file-name>\n"
        "or socket://<socket-file-name>"),
     N_("url") },
-  { "reuse-address", mu_cfg_bool, &reuse_lmtp_address, 0, NULL,
+  { "reuse-address", mu_c_bool, &reuse_lmtp_address, 0, NULL,
     N_("Reuse existing address (LMTP mode).  Default is \"yes\".") },
   { "filter", mu_cfg_section, NULL, 0, NULL,
     N_("Add a message filter") },
diff --git a/mail/unset.c b/mail/unset.c
index d829ef9..45526b1 100644
--- a/mail/unset.c
+++ b/mail/unset.c
@@ -26,7 +26,7 @@ mail_unset (int argc, char **argv)
 {
   if (argc < 2)
     {
-      mailvar_print (0);
+      mailvar_print (1);
       return 0;
     }
   else
diff --git a/mh/rmf.c b/mh/rmf.c
index 9cf652f..2e8c47f 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -92,7 +92,7 @@ opt_handler (int key, char *arg, struct argp_state *state)
 }
 
 static char *
-current_folder_path ()
+current_folder_path (void)
 {
   mu_mailbox_t mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
   mu_url_t url;
@@ -197,7 +197,7 @@ main (int argc, char **argv)
       name = cur_folder_path;
     }
   else
-    name = mh_expand_name (NULL, folder_name, NAME_ANY);
+    name = mh_expand_name (NULL, folder_name, NAME_FOLDER);
   if (recursive)
     status = recrmf (name);
   else
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 0bc7bf6..4a7810c 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -164,10 +164,10 @@ struct mu_cfg_param mimeview_cfg_param[] = {
   { "debug", mu_cfg_callback, NULL, 0, cb_debug,
     N_("Set debug verbosity level."),
     N_("flags") },
-  { "mimetypes", mu_cfg_string, &mimetypes_config, 0, NULL,
+  { "mimetypes", mu_c_string, &mimetypes_config, 0, NULL,
     N_("Use this mime.types file."),
     N_("file") },
-  { "metamail", mu_cfg_string, &metamail, 0, NULL,
+  { "metamail", mu_c_string, &metamail, 0, NULL,
     N_("Use this program to display files."),
     N_("prog") },
   { NULL }
diff --git a/movemail/movemail.c b/movemail/movemail.c
index 888a015..67b721f 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -371,17 +371,17 @@ cb_onerror (void *data, mu_config_value_t *val)
 }
   
 struct mu_cfg_param movemail_cfg_param[] = {
-  { "preserve", mu_cfg_bool, &preserve_mail, 0, NULL,
+  { "preserve", mu_c_bool, &preserve_mail, 0, NULL,
     N_("Do not remove messages from the source mailbox.") },
-  { "reverse",  mu_cfg_bool, &reverse_order, 0, NULL,
+  { "reverse",  mu_c_bool, &reverse_order, 0, NULL,
     N_("Reverse message sorting order.") },
-  { "emacs", mu_cfg_bool, &emacs_mode, 0, NULL,
+  { "emacs", mu_c_bool, &emacs_mode, 0, NULL,
     N_("Output information used by Emacs rmail interface.") },
-  { "uidl", mu_cfg_bool, &uidl_option, 0, NULL,
+  { "uidl", mu_c_bool, &uidl_option, 0, NULL,
     N_("Use UIDLs to avoid downloading the same message twice.") },
-  { "verbose", mu_cfg_int, &verbose_option, 0, NULL,
+  { "verbose", mu_c_int, &verbose_option, 0, NULL,
     N_("Set verbosity level.") },
-  { "program-id", mu_cfg_string, &program_id_option, 0, NULL,
+  { "program-id", mu_c_string, &program_id_option, 0, NULL,
     N_("Set program identifier string (default: program name)") },
   { "mailbox-ownership", mu_cfg_callback, NULL, 0,
     cb_mailbox_ownership,
@@ -392,10 +392,10 @@ struct mu_cfg_param movemail_cfg_param[] = {
        " set-id=UID[:GID] set supplied UID and GID\n"
        " set-name=USER    make destination mailbox owned by USER"),
     N_("methods: list") },
-  { "max-messages", mu_cfg_size, &max_messages_option, 0, NULL,
+  { "max-messages", mu_c_size, &max_messages_option, 0, NULL,
     N_("Copy at most <count> messages."),
     N_("count") },
-  { "ignore-errors", mu_cfg_bool, &ignore_errors, 0, NULL,
+  { "ignore-errors", mu_c_bool, &ignore_errors, 0, NULL,
     N_("Continue after an error.") },
   { "onerror", mu_cfg_callback, NULL, 0, cb_onerror,
     N_("What to do after an error. Argument is a comma-separated list of:\n"
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 90f04f9..ca1a1af 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -182,7 +182,7 @@ cb_tls_required (void *data, mu_config_value_t *val)
   
   if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
-  if (mu_cfg_parse_boolean (val->v.string, &bv))
+  if (mu_str_to_c (val->v.string, mu_c_bool, &bv, NULL))
     mu_error (_("Not a boolean value"));
   else if (bv)
     {
@@ -210,16 +210,16 @@ static struct mu_cfg_param pop3d_srv_param[] = {
 };
     
 static struct mu_cfg_param pop3d_cfg_param[] = {
-  { "undelete", mu_cfg_bool, &undelete_on_startup, 0, NULL,
+  { "undelete", mu_c_bool, &undelete_on_startup, 0, NULL,
     N_("On startup, clear deletion marks from all the messages.") },
-  { "expire", mu_cfg_uint, &expire, 0, NULL,
+  { "expire", mu_c_uint, &expire, 0, NULL,
     N_("Automatically expire read messages after the given number of days."),
     N_("days") },
-  { "delete-expired", mu_cfg_bool, &expire_on_exit, 0, NULL,
+  { "delete-expired", mu_c_bool, &expire_on_exit, 0, NULL,
     N_("Delete expired messages upon closing the mailbox.") },
-  { "scan-lines", mu_cfg_bool, &pop3d_xlines, 0, NULL,
+  { "scan-lines", mu_c_bool, &pop3d_xlines, 0, NULL,
     N_("Output the number of lines in the message in its scan listing.") },
-  { "apop-database-file", mu_cfg_string, &apop_database_name, 0, NULL,
+  { "apop-database-file", mu_c_string, &apop_database_name, 0, NULL,
     N_("set APOP database file name or URL") },
   { "apop-database-owner", mu_cfg_callback, NULL, 0, cb_apop_database_owner,
     N_("Name or UID of the APOP database owner") },
@@ -247,9 +247,9 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
        "Deprecated, use \"tls required\" instead.") },
 #endif
 #ifdef ENABLE_LOGIN_DELAY
-  { "login-delay", mu_cfg_time, &login_delay, 0, NULL,
+  { "login-delay", mu_c_time, &login_delay, 0, NULL,
     N_("Set the minimal allowed delay between two successive logins.") },
-  { "stat-file", mu_cfg_string, &login_stat_file, 0, NULL,
+  { "stat-file", mu_c_string, &login_stat_file, 0, NULL,
     N_("Set the name of login statistics file (for login-delay).") },
 #endif
   { "bulletin-source", mu_cfg_callback, NULL, 0, cb_bulletin_source,
@@ -260,12 +260,12 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
     N_("Set the bulletin database file name."),
     N_("file") },
 #endif
-  { "output-buffer-size", mu_cfg_size, &pop3d_output_bufsize, 0, NULL,
+  { "output-buffer-size", mu_c_size, &pop3d_output_bufsize, 0, NULL,
     N_("Size of the output buffer.") },
   { "mandatory-locking", mu_cfg_section },
   { ".server", mu_cfg_section, NULL, 0, NULL,
     N_("Server configuration.") },
-  { "transcript", mu_cfg_bool, &pop3d_transcript, 0, NULL,
+  { "transcript", mu_c_bool, &pop3d_transcript, 0, NULL,
     N_("Set global transcript mode.") },
   TCP_WRAPPERS_CONFIG
   { NULL }
diff --git a/readmsg/readmsg.c b/readmsg/readmsg.c
index 485f925..794c0f1 100644
--- a/readmsg/readmsg.c
+++ b/readmsg/readmsg.c
@@ -126,21 +126,21 @@ readmsg_parse_opt (int key, char *arg, struct argp_state *astate)
 
 
 struct mu_cfg_param readmsg_cfg_param[] = {
-  { "debug", mu_cfg_int, &dbug, 0, NULL,
+  { "debug", mu_c_int, &dbug, 0, NULL,
     N_("Set debug verbosity level.") },
-  { "header", mu_cfg_bool, &all_header, 0, NULL,
+  { "header", mu_c_bool, &all_header, 0, NULL,
     N_("Display entire headers.") },
-  { "weedlist", mu_cfg_string, &weedlist, 0, NULL,
+  { "weedlist", mu_c_string, &weedlist, 0, NULL,
     N_("Display only headers from this list.  Argument is a list of header "
        "names separated by whitespace or commas."),
     N_("list") },
-  { "folder", mu_cfg_string, &mailbox_name, 0, NULL,
+  { "folder", mu_c_string, &mailbox_name, 0, NULL,
     N_("Read messages from this folder.") },
-  { "no-header", mu_cfg_bool, &no_header, 0, NULL,
+  { "no-header", mu_c_bool, &no_header, 0, NULL,
     N_("Exclude all headers.") }, 
-  { "form-feeds", mu_cfg_bool, &form_feed, 0, NULL,
+  { "form-feeds", mu_c_bool, &form_feed, 0, NULL,
     N_("Output formfeed character between messages.") },
-  { "show-all-match", mu_cfg_bool, &show_all, 0, NULL,
+  { "show-all-match", mu_c_bool, &show_all, 0, NULL,
     N_("Print all messages matching pattern, not only the first.") },
   { NULL }
 };
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 182b291..32a8a0b 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -281,12 +281,12 @@ cb_email (void *data, mu_config_value_t *val)
 }
 
 static struct mu_cfg_param sieve_cfg_param[] = {
-  { "keep-going", mu_cfg_bool, &keep_going, 0, NULL,
+  { "keep-going", mu_c_bool, &keep_going, 0, NULL,
     N_("Do not abort if execution fails on a message.") },
-  { "mbox-url", mu_cfg_string, &mbox_url, 0, NULL,
+  { "mbox-url", mu_c_string, &mbox_url, 0, NULL,
     N_("Mailbox to sieve (defaults to user's mail spool)."),
     N_("url") },
-  { "ticket", mu_cfg_string, &mu_ticket_file, 0, NULL,
+  { "ticket", mu_c_string, &mu_ticket_file, 0, NULL,
     N_("Ticket file for user authentication."),
     N_("ticket") },
   { "debug", mu_cfg_callback, NULL, 0, cb_debug,
@@ -297,9 +297,9 @@ static struct mu_cfg_param sieve_cfg_param[] = {
        "   P - network protocols (sieve.prot)\n"
        "   t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n"
        "   i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR).") },
-  { "verbose", mu_cfg_bool, &verbose, 0, NULL,
+  { "verbose", mu_c_bool, &verbose, 0, NULL,
     N_("Log all executed actions.") },
-  { "line-info", mu_cfg_bool, &sieve_print_locus, 0, NULL,
+  { "line-info", mu_c_bool, &sieve_print_locus, 0, NULL,
     N_("Print source locations along with action logs (default).") },
   { "email", mu_cfg_callback, NULL, 0, cb_email,
     N_("Set user email address.") },


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 10 11:09:24 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1btcCi-00042a-PI
	for mharc-commit-mailutils@gnu.org; Mon, 10 Oct 2016 11:09:24 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:55992)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btcCY-000428-EM
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 11:09:23 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btcCR-00070S-E5
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 11:09:13 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:50262)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btcCR-00070I-7l
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 11:09:07 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 2B4D5220167; Mon, 10 Oct 2016 15:09:07 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-764-g2191823
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 8905bb4805cf4ebcff9ba3d99073b81c906399f6
X-Git-Newrev: 219182387a823ae8113a5a14cf29f9263d00171c
Message-Id: <20161010150907.2B4D5220167@vcs.savannah.gnu.org>
Date: Mon, 10 Oct 2016 15:09:06 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 10 Oct 2016 15:09:23 -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=219182387a823ae8113a5a14cf29f9263d00171c

The branch, master has been updated
       via  219182387a823ae8113a5a14cf29f9263d00171c (commit)
      from  8905bb4805cf4ebcff9ba3d99073b81c906399f6 (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 219182387a823ae8113a5a14cf29f9263d00171c
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 10 15:47:26 2016 +0300

    Fix help output.  Test it.
    
    * include/mailutils/opt.h (MU_PARSEOPT_EXTRA_INFO)
    (MU_PARSEOPT_EXIT_ERROR): New flags.
    (struct mu_parseopt) <po_extra_info>: New member.
    <po_exit_error>: New member.
    * libmailutils/opt/help.c: Fix help output formatting.
    Implement support for ARGP_HELP_FMT envvar.
    * libmailutils/opt/opt.c (add_option_cache): Honor
    MU_PARSEOPT_IMMEDIATE.
    (parseopt_init): Initialize each member separately.
    
    * libmailutils/tests/parseopt.c: Rewrite envvar handling.
    * libmailutils/tests/Makefile.am: Add new tests.
    * libmailutils/tests/testsuite.at (PARSEOPT_DEFAULT): New define.
    * libmailutils/tests/parseopt00.at: Use PARSEOPT_DEFAULT.
    * libmailutils/tests/parseopt01.at: Likewise.
    * libmailutils/tests/parseopt02.at: Likewise.
    * libmailutils/tests/parseopt03.at: Likewise.
    * libmailutils/tests/parseopt04.at: Likewise.
    * libmailutils/tests/parseopt05.at: Likewise.
    * libmailutils/tests/parseopt06.at: Likewise.
    * libmailutils/tests/parseopt07.at: Likewise.
    * libmailutils/tests/parseopt08.at: Likewise.
    * libmailutils/tests/parseopt09.at: Likewise.
    * libmailutils/tests/parseopt10.at: Likewise.
    * libmailutils/tests/parseopt11.at: Likewise.
    * libmailutils/tests/parseopt12.at: Likewise.
    * libmailutils/tests/parseopt13.at: Likewise.
    * libmailutils/tests/parseopt14.at: Likewise.
    * libmailutils/tests/parseopt15.at: Likewise.
    * libmailutils/tests/parseopt16.at: Likewise.
    * libmailutils/tests/parseopt17.at: Likewise.
    * libmailutils/tests/parseopt18.at: Likewise.
    * libmailutils/tests/parseopt19.at: Likewise.
    * libmailutils/tests/parseopt20.at: Likewise.
    * libmailutils/tests/parseopt21.at: Likewise.
    * libmailutils/tests/parseopt22.at: Likewise.
    * libmailutils/tests/parseopt23.at: New test.
    * libmailutils/tests/parseopt24.at: New test.
    * libmailutils/tests/parseopt25.at: New test.
    * libmailutils/tests/parseopt_help00.at: New test.
    * libmailutils/tests/parseopt_help01.at: New test.
    * libmailutils/tests/parseopt_help02.at: New test.
    * libmailutils/tests/parseopt_help03.at: New test.
    * libmailutils/tests/parseopt_help04.at: New test.
    * libmailutils/tests/parseopt_help05.at: New test.
    * libmailutils/tests/parseopt_help06.at: New test.
    * libmailutils/tests/parseopt_help07.at: New test.
    * libmailutils/tests/parseopt_help08.at: New test.
    * libmailutils/tests/parseopt_help09.at: New test.
    * libmailutils/tests/parseopt_help10.at: New test.
    * libmailutils/tests/parseopt_help11.at: New test.

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

Summary of changes:
 include/mailutils/opt.h                            |   17 +-
 libmailutils/opt/help.c                            |  286 +++++++++++++++++---
 libmailutils/opt/opt.c                             |   51 +++-
 libmailutils/tests/Makefile.am                     |   15 +
 libmailutils/tests/parseopt.c                      |   76 +++++-
 libmailutils/tests/parseopt00.at                   |    2 +-
 libmailutils/tests/parseopt01.at                   |    2 +-
 libmailutils/tests/parseopt02.at                   |    2 +-
 libmailutils/tests/parseopt03.at                   |    2 +-
 libmailutils/tests/parseopt04.at                   |    2 +-
 libmailutils/tests/parseopt05.at                   |    2 +-
 libmailutils/tests/parseopt06.at                   |    2 +-
 libmailutils/tests/parseopt07.at                   |    2 +-
 libmailutils/tests/parseopt08.at                   |    2 +-
 libmailutils/tests/parseopt09.at                   |    2 +-
 libmailutils/tests/parseopt10.at                   |    2 +-
 libmailutils/tests/parseopt11.at                   |    2 +-
 libmailutils/tests/parseopt12.at                   |    2 +-
 libmailutils/tests/parseopt13.at                   |    2 +-
 libmailutils/tests/parseopt14.at                   |    2 +-
 libmailutils/tests/parseopt15.at                   |    2 +-
 libmailutils/tests/parseopt16.at                   |    3 +-
 libmailutils/tests/parseopt17.at                   |    1 +
 libmailutils/tests/parseopt18.at                   |    1 +
 libmailutils/tests/parseopt19.at                   |    1 +
 libmailutils/tests/parseopt20.at                   |    3 +-
 libmailutils/tests/parseopt21.at                   |    3 +-
 libmailutils/tests/parseopt22.at                   |    3 +-
 .../tests/{parseopt09.at => parseopt23.at}         |   18 +-
 .../tests/{parseopt22.at => parseopt25.at}         |   14 +-
 .../tests/{parseopt18.at => parseopt_help00.at}    |   41 +--
 .../tests/{parseopt02.at => parseopt_help01.at}    |   25 +-
 .../tests/{parseopt18.at => parseopt_help02.at}    |   41 +--
 libmailutils/tests/parseopt_help03.at              |   47 ++++
 libmailutils/tests/parseopt_help04.at              |   46 ++++
 libmailutils/tests/parseopt_help05.at              |   47 ++++
 libmailutils/tests/parseopt_help06.at              |   47 ++++
 libmailutils/tests/parseopt_help07.at              |   56 ++++
 .../tests/{parseopt18.at => parseopt_help08.at}    |   39 +--
 .../tests/{parseopt01.at => parseopt_help09.at}    |   26 +-
 .../tests/{parseopt01.at => parseopt_help10.at}    |   25 +-
 libmailutils/tests/parseopt_help11.at              |   45 +++
 libmailutils/tests/testsuite.at                    |   35 +++
 43 files changed, 846 insertions(+), 198 deletions(-)
 copy libmailutils/tests/{parseopt09.at => parseopt23.at} (79%)
 copy libmailutils/tests/{parseopt22.at => parseopt25.at} (79%)
 copy libmailutils/tests/{parseopt18.at => parseopt_help00.at} (51%)
 copy libmailutils/tests/{parseopt02.at => parseopt_help01.at} (70%)
 copy libmailutils/tests/{parseopt18.at => parseopt_help02.at} (50%)
 create mode 100644 libmailutils/tests/parseopt_help03.at
 create mode 100644 libmailutils/tests/parseopt_help04.at
 create mode 100644 libmailutils/tests/parseopt_help05.at
 create mode 100644 libmailutils/tests/parseopt_help06.at
 create mode 100644 libmailutils/tests/parseopt_help07.at
 copy libmailutils/tests/{parseopt18.at => parseopt_help08.at} (50%)
 copy libmailutils/tests/{parseopt01.at => parseopt_help09.at} (67%)
 copy libmailutils/tests/{parseopt01.at => parseopt_help10.at} (66%)
 create mode 100644 libmailutils/tests/parseopt_help11.at

diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index de84d21..8e3b03b 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -61,7 +61,7 @@ struct mu_option
   (!MU_OPTION_IS_OPTION(opt) && (opt)->opt_doc)
 #define MU_OPTION_IS_VALID_SHORT_OPTION(opt) \
   ((opt)->opt_short > 0 && (opt)->opt_short < 127 && \
-   mu_isalnum ((opt)->opt_short))
+   (mu_isalnum ((opt)->opt_short) || ((opt)->opt_short == '?')))
 #define MU_OPTION_IS_VALID_LONG_OPTION(opt) \
   ((opt)->opt_long != NULL)
 
@@ -97,8 +97,11 @@ struct mu_option_cache
 #define MU_PARSEOPT_BUG_ADDRESS    0x00010000
 #define MU_PARSEOPT_PACKAGE_NAME   0x00020000
 #define MU_PARSEOPT_PACKAGE_URL    0x00040000
-#define MU_PARSEOPT_DATA           0x00080000
-#define MU_PARSEOPT_HELP_HOOK      0x00100000
+#define MU_PARSEOPT_EXTRA_INFO     0x00080000
+#define MU_PARSEOPT_EXIT_ERROR     0x00100000
+#define MU_PARSEOPT_HELP_HOOK      0x00200000
+#define MU_PARSEOPT_DATA           0x00400000
+#define MU_PARSEOPT_VERSION_HOOK   0x00800000
 
 /* Reuse mu_parseopt struct initialized previously */
 #define MU_PARSEOPT_REUSE          0x80000000
@@ -116,6 +119,8 @@ struct mu_parseopt
   int po_flags;                        
 
   char *po_data;                   /* Call-specific data */
+
+  int po_exit_error;               /* Exit on error with this code */
   
   /* Informational: */
   char const *po_prog_name;
@@ -124,8 +129,10 @@ struct mu_parseopt
   char const *po_bug_address;
   char const *po_package_name;
   char const *po_package_url;
-
-  void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_Stream_t ?*/
+  char const *po_extra_info;
+  
+  void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_stream_t ?*/
+  void (*po_version_hook) (FILE *stream);
   
   /* Output data */
   int po_ind;                      /* Index of the next option */
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index c3d9a6f..b106d9a 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -19,22 +19,161 @@
 #endif
 #include <stdlib.h>
 #include <string.h>
+#include <limits.h>
+#include <errno.h>
+#include <unistd.h>
 #include <mailutils/alloc.h>
 #include <mailutils/opt.h>
 #include <mailutils/cctype.h>
 #include <mailutils/nls.h>
+#include <mailutils/wordsplit.h>
+
+unsigned short_opt_col = 2;
+unsigned long_opt_col = 6;
+/*FIXME: doc_opt_col? */
+unsigned header_col = 1;
+unsigned opt_doc_col = 29;
+unsigned usage_indent = 12;
+unsigned rmargin = 79;
+
+unsigned dup_args = 0;
+unsigned dup_args_note = 1;
+
+enum usage_var_type
+  {
+    usage_var_column,
+    usage_var_bool
+  };
+
+static struct usage_var
+{
+  char *name;
+  unsigned *valptr;
+  enum usage_var_type type;
+} usage_var[] = {
+  { "short-opt-col", &short_opt_col, usage_var_column },
+  { "header-col",    &header_col,    usage_var_column },
+  { "opt-doc-col",   &opt_doc_col,   usage_var_column },
+  { "usage-indent",  &usage_indent,  usage_var_column },
+  { "rmargin",       &rmargin,       usage_var_column },
+  { "dup-args",      &dup_args,      usage_var_bool },
+  { "dup-args-note", &dup_args_note, usage_var_bool },
+  { "long-opt-col",  &long_opt_col,  usage_var_column },
+  { "doc_opt_col",   NULL,           usage_var_column },
+  { NULL }
+};
 
-#define LMARGIN 2
-#define DESCRCOLUMN 30
-#define RMARGIN 79
-#define GROUPCOLUMN 2
-#define USAGECOLUMN 13
+static void
+set_usage_var (struct mu_parseopt *po, char const *id)
+{
+  struct usage_var *p;
+  size_t len;
+  int boolval = 1;
+  
+  if (strlen (id) > 3 && memcmp (id, "no-", 3) == 0)
+    {
+      id += 3;
+      boolval = 0;
+    }
+  len = strcspn (id, "=");
+
+  for (p = usage_var; p->name; p++)
+    {
+      if (strlen (p->name) == len && memcmp (p->name, id, len) == 0)
+	{
+	  if (!p->valptr)
+	    return;
+
+	  if (p->type == usage_var_bool)
+	    {
+	      if (id[len])
+		{
+		  if (po->po_prog_name)
+		    fprintf (stderr, "%s: ", po->po_prog_name);
+		  fprintf (stderr,
+			   "error in ARGP_HELP_FMT: improper usage of [no-]%s\n",
+			   id);
+		  return;
+		}
+	      *p->valptr = boolval;
+	      return;
+	    }
+	  
+	  if (id[len])
+	    {
+	      char *endp;
+	      unsigned long val;
+	      
+	      errno = 0;
+	      val = strtoul (id + len + 1, &endp, 10);
+	      if (errno || *endp)
+		{
+		  if (po->po_prog_name)
+		    fprintf (stderr, "%s: ", po->po_prog_name);
+		  fprintf (stderr,
+			   "error in ARGP_HELP_FMT: bad value for %s\n",
+			   id);
+		}
+	      else if (val > UINT_MAX)
+		{
+		  if (po->po_prog_name)
+		    fprintf (stderr, "%s: ", po->po_prog_name);
+		  fprintf (stderr,
+			   "error in ARGP_HELP_FMT: %s value is out of range\n",
+			   id);
+		}
+	      else
+		*p->valptr = val;
+	    }
+	  else
+	    {
+	      if (po->po_prog_name)
+		fprintf (stderr, "%s: ", po->po_prog_name);
+	      fprintf (stderr,
+		       "%s: ARGP_HELP_FMT parameter requires a value\n",
+		       id);
+	      return;
+	    }
+	  return;
+	}
+    }
+
+  if (po->po_prog_name)
+    fprintf (stderr, "%s: ", po->po_prog_name);
+  fprintf (stderr,
+	   "%s: Unknown ARGP_HELP_FMT parameter\n",
+	   id);
+}
 
 static void
-indent (size_t start, size_t col)
+init_usage_vars (struct mu_parseopt *po)
+{
+  char *fmt;
+  struct mu_wordsplit ws;
+  size_t i;
+  
+  fmt = getenv ("ARGP_HELP_FMT");
+  if (!fmt)
+    return;
+  ws.ws_delim=",";
+  if (mu_wordsplit (fmt, &ws, 
+		    MU_WRDSF_DELIM | MU_WRDSF_NOVAR | MU_WRDSF_NOCMD
+		    | MU_WRDSF_WS | MU_WRDSF_SHOWERR))
+    return;
+  for (i = 0; i < ws.ws_wordc; i++)
+    {
+      set_usage_var (po, ws.ws_wordv[i]);
+    }
+
+  mu_wordsplit_free (&ws);
+}
+
+static int
+indent (int start, int col)
 {
   for (; start < col; start++)
     putchar (' ');
+  return start;
 }
 
 static void
@@ -70,6 +209,22 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
 
 
 static size_t
+print_opt_arg (struct mu_option *opt, int delim)
+{
+  int w = 0;
+  if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
+    {
+      if (delim == '=')
+	w = printf ("[=%s]", gettext (opt->opt_arg));
+      else
+	w = printf ("[%s]", gettext (opt->opt_arg));
+    }
+  else
+    w = printf ("%c%s", delim, gettext (opt->opt_arg));
+  return w;
+}
+
+static size_t
 print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
 	      int *argsused)
 {
@@ -82,9 +237,11 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
     {
       if (num)
 	putchar ('\n');
-      indent (0, GROUPCOLUMN);
-      print_option_descr (gettext (opt->opt_doc), GROUPCOLUMN, RMARGIN);
-      putchar ('\n');
+      if (opt->opt_doc[0])
+	{
+	  indent (0, header_col);
+	  print_option_descr (gettext (opt->opt_doc), header_col, rmargin);
+	}
       return num + 1;
     }
 
@@ -103,52 +260,51 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
 	{
 	  if (w == 0)
 	    {
-	      indent (0, LMARGIN);
-	      w = LMARGIN;
+	      indent (0, short_opt_col);
+	      w = short_opt_col;
 	    }
 	  else
 	    w += printf (", ");
 	  w += printf ("-%c", optbuf[i]->opt_short);
 	  delim = ' ';
+	  if (opt->opt_arg && dup_args)
+	    w += print_opt_arg (opt, delim);
 	}
     }
-  
+
   for (i = num; i < next; i++)
     {
       if (MU_OPTION_IS_VALID_LONG_OPTION (optbuf[i]))
 	{
 	  if (w == 0)
 	    {
-	      indent (0, LMARGIN);
-	      w = LMARGIN;
+	      indent (0, short_opt_col);
+	      w = short_opt_col;
 	    }
 	  else
 	    w += printf (", ");
-	  w += printf ("--%s", optbuf[i]->opt_long);
+	  if (i == num)
+	    w = indent (w, long_opt_col);
+  	  w += printf ("--%s", optbuf[i]->opt_long);
 	  delim = '=';
+	  if (opt->opt_arg && dup_args)
+	    w += print_opt_arg (opt, delim);
 	}
     }
   
   if (opt->opt_arg)
     {
       *argsused = 1;
-      if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
-	{
-	  if (delim == '=')
-	    w += printf ("[=%s]", gettext (opt->opt_arg));
-	  else
-	    w += printf ("[%s]", gettext (opt->opt_arg));
-	}
-      else
-	w += printf ("%c%s", delim, gettext (opt->opt_arg));
+      if (!dup_args)
+	w += print_opt_arg (opt, delim);
     }
-  if (w >= DESCRCOLUMN)
+  if (w >= opt_doc_col)
     {
       putchar ('\n');
       w = 0;
     }
-  indent (w, DESCRCOLUMN);
-  print_option_descr (gettext (opt->opt_doc), DESCRCOLUMN, RMARGIN);
+  indent (w, opt_doc_col);
+  print_option_descr (gettext (opt->opt_doc), opt_doc_col, rmargin);
 
   return next;
 }
@@ -163,9 +319,9 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
     i = print_option (optbuf, optcnt, i, &argsused);
   putchar ('\n');
 
-  if (argsused)
+  if (argsused && dup_args_note)
     {
-      print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN);
+      print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, rmargin);
       putchar ('\n');
     }
 }
@@ -173,6 +329,8 @@ mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
 void
 mu_program_help (struct mu_parseopt *po)
 {
+  init_usage_vars (po);
+
   printf ("%s", _("Usage:"));
   if (po->po_prog_name)
     printf (" %s", po->po_prog_name);
@@ -182,7 +340,7 @@ mu_program_help (struct mu_parseopt *po)
   putchar ('\n');
   
   if (po->po_prog_doc)
-    print_option_descr (gettext (po->po_prog_doc), 0, RMARGIN);
+    print_option_descr (gettext (po->po_prog_doc), 0, rmargin);
   putchar ('\n');
 
   mu_option_describe_options (po->po_optv, po->po_optc);
@@ -200,6 +358,8 @@ mu_program_help (struct mu_parseopt *po)
   if (po->po_package_name && po->po_package_url)
     printf (_("%s home page: <%s>\n"),
 	    po->po_package_name, po->po_package_url);
+  if (po->po_flags & MU_PARSEOPT_EXTRA_INFO)
+    print_option_descr (po->po_extra_info, 0, rmargin);
 }
 
 static struct mu_option **option_tab;
@@ -209,8 +369,22 @@ cmpidx_short (const void *a, const void *b)
 {
   unsigned const *ai = (unsigned const *)a;
   unsigned const *bi = (unsigned const *)b;
+  int ac = option_tab[*ai]->opt_short;
+  int bc = option_tab[*bi]->opt_short;
+  int d;
+  
+  if (mu_isalpha (ac))
+    {
+      if (!mu_isalpha (bc))
+	return -1;
+    }
+  else if (mu_isalpha (bc))
+    return 1;
 
-  return option_tab[*ai]->opt_short - option_tab[*bi]->opt_short;
+  d = mu_tolower (ac) - mu_tolower (bc);
+  if (d == 0)
+    d =  mu_isupper (ac) ? 1 : -1;
+  return d;
 }
   
 static int
@@ -228,7 +402,7 @@ mu_program_usage (struct mu_parseopt *po)
 {
   unsigned i;
   unsigned n;
-  char buf[RMARGIN+1];
+  char buf[rmargin+1];
   unsigned *idxbuf;
   unsigned nidx;
 
@@ -240,23 +414,25 @@ mu_program_usage (struct mu_parseopt *po)
     {									\
       buf[n] = 0;							\
       printf ("%s\n", buf);						\
-      n = USAGECOLUMN;							\
-      memset (buf, ' ', n);						\
+      n = usage_indent;						\
+      if (n) memset (buf, ' ', n);					\
     }									\
   while (0)
 #define ADDC(c)							        \
   do									\
     {									\
-      if (n == RMARGIN) FLUSH;						\
+      if (n == rmargin) FLUSH;						\
       buf[n++] = c;							\
     }									\
   while (0)
 
+  init_usage_vars (po);
+
   option_tab = optbuf;
   
   idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
 
-  n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"),	mu_progname);
+  n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"),	po->po_prog_name);
   
   /* Print a list of short options without arguments. */
   for (i = nidx = 0; i < optcnt; i++)
@@ -293,8 +469,10 @@ mu_program_usage (struct mu_parseopt *po)
 	  const char *arg = gettext (opt->opt_arg);
 	  size_t len = 5 + strlen (arg) + 1;
 	  
-	  if (n + len > RMARGIN) FLUSH;
-	  buf[n++] = ' ';
+	  if (n + len >= rmargin)
+	    FLUSH;
+	  else
+	    buf[n++] = ' ';
 	  buf[n++] = '[';
 	  buf[n++] = '-';
 	  buf[n++] = opt->opt_short;
@@ -320,10 +498,12 @@ mu_program_usage (struct mu_parseopt *po)
 	{
 	  struct mu_option *opt = optbuf[idxbuf[i]];
 	  const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL;
-	  size_t len = 3 + strlen (opt->opt_long)
+	  size_t len = 5 + strlen (opt->opt_long)
 	                 + (arg ? 1 + strlen (arg) : 0);
-	  if (n + len > RMARGIN) FLUSH;
-	  buf[n++] = ' ';
+	  if (n + len >= rmargin)
+	    FLUSH;
+	  else
+	    buf[n++] = ' ';
 	  buf[n++] = '[';
 	  buf[n++] = '-';
 	  buf[n++] = '-';
@@ -339,6 +519,30 @@ mu_program_usage (struct mu_parseopt *po)
 	}
     }
 
+  if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
+    {
+      char const *p = po->po_prog_args;
+
+      if (n + 1 >= rmargin)
+	FLUSH;
+      buf[n++] = ' ';
+      
+      while (*p)
+	{
+	  size_t len = strcspn (p, "  \t\n");
+	  if (len == 0)
+	    len = 1;
+	  if (n + len >= rmargin)
+	    FLUSH;
+	  else
+	    {
+	      memcpy (buf + n, p, len);
+	      p += len;
+	      n += len;
+	    }
+	}
+    }
+
   FLUSH;
   free (idxbuf);
 }
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index ba54f75..61bd00f 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -82,19 +82,30 @@ fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
   exit (EXIT_SUCCESS);
 }
 
+static void
+fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
+{
+  po->po_version_hook (stdout);
+  exit (EXIT_SUCCESS);
+}
+
 /* Default options */
 struct mu_option mu_default_options[] = {
   MU_OPTION_GROUP(""),
-  { "help",    'h', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"),
+  { "help",    '?', NULL, MU_OPTION_IMMEDIATE, N_("give this help list"),
     mu_c_string, NULL, fn_help },
-  { "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
-    mu_c_string, NULL, /* FIXME: fn_version */ },
   { "usage",   0,   NULL, MU_OPTION_IMMEDIATE, N_("give a short usage message"),
     mu_c_string, NULL, fn_usage
   },
   MU_OPTION_END
 };
 
+struct mu_option mu_version_options[] = {
+  { "version", 'V', NULL, MU_OPTION_IMMEDIATE, N_("print program version"),
+    mu_c_string, NULL, fn_version },
+  MU_OPTION_END
+};
+
 /* Output error message */
 static void
 parse_error (struct mu_parseopt *po, char const *fmt, ...)
@@ -132,7 +143,8 @@ add_option_cache (struct mu_parseopt *po, struct mu_option *opt,
   cache->cache_opt = opt;
   cache->cache_arg = arg ? mu_strdup (arg) : NULL;
 
-  if (opt->opt_flags & MU_OPTION_IMMEDIATE)
+  if ((po->po_flags & MU_PARSEOPT_IMMEDIATE)
+       || (opt->opt_flags & MU_OPTION_IMMEDIATE))
     {
       parseopt_apply (cache, po);
       mu_option_cache_destroy (cache);
@@ -407,7 +419,7 @@ parse (struct mu_parseopt *po)
 			po->po_arg_count++;
 		      continue;
 		    }
-		  exit (EXIT_ERROR);
+		  exit (po->po_exit_error);
 		}	
 	    }
 	  else
@@ -426,7 +438,7 @@ parse (struct mu_parseopt *po)
 			po->po_arg_count++;
 		      continue;
 		    }
-		  exit (EXIT_ERROR);
+		  exit (po->po_exit_error);
 		}
 	      arg = NULL;
 	    }
@@ -442,7 +454,7 @@ parse (struct mu_parseopt *po)
 		po->po_arg_count++;
 	      continue;
 	    }
-	  exit (EXIT_ERROR);
+	  exit (po->po_exit_error);
 	}
     }
 
@@ -459,7 +471,6 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
   struct mu_option *opt;
   size_t i, j;
 
-  memset (po, 0, sizeof *po);
   po->po_argc = 0;
   po->po_argv = NULL;
   po->po_optc = 0;
@@ -481,8 +492,14 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
     po->po_package_url = NULL;
   if (!(flags & MU_PARSEOPT_PACKAGE_URL))
     po->po_data = NULL;
+  if (!(flags & MU_PARSEOPT_EXTRA_INFO))
+    po->po_extra_info = NULL;
   if (!(flags & MU_PARSEOPT_HELP_HOOK))
     po->po_help_hook = NULL;
+  if (!(flags & MU_PARSEOPT_EXIT_ERROR))
+    po->po_exit_error = EXIT_ERROR;
+  if (!(flags & MU_PARSEOPT_VERSION_HOOK))
+    po->po_version_hook = NULL;
   
   /* Count the options */
   po->po_optc = 0;
@@ -493,6 +510,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
   if (!(flags & MU_PARSEOPT_NO_STDOPT))
     for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++)
       ++po->po_optc;
+
+  if (flags & MU_PARSEOPT_VERSION_HOOK)
+    for (i = 0; !MU_OPTION_IS_END (&mu_version_options[i]); i++)
+      ++po->po_optc;
   
   /* Allocate the working buffer of option pointers */
   po->po_optv = mu_calloc (po->po_optc + 1, sizeof (*po->po_optv));
@@ -512,6 +533,10 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
   if (!(flags & MU_PARSEOPT_NO_STDOPT))
     for (i = 0; !MU_OPTION_IS_END (&mu_default_options[i]); i++, j++)
       po->po_optv[j] = &mu_default_options[i];
+
+  if (flags & MU_PARSEOPT_VERSION_HOOK)
+    for (i = 0; !MU_OPTION_IS_END (&mu_version_options[i]); i++, j++)
+      po->po_optv[j] = &mu_version_options[i];
   
   po->po_optv[j] = NULL;
 
@@ -532,6 +557,16 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
 	    start = sort_group (po->po_optv, start);
 	}
     }
+
+  po->po_ind = 0;
+  po->po_opterr = 0;
+  po->po_optlist = NULL;
+  po->po_cur = NULL;
+  po->po_chr = 0;
+  po->po_arg_start = 0;
+  po->po_arg_count = 0;
+  po->po_permuted = 0;
+  
   return 0;
 }
 
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 5655d80..349eb24 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -127,6 +127,21 @@ TESTSUITE_AT = \
  parseopt20.at\
  parseopt21.at\
  parseopt22.at\
+ parseopt23.at\
+ parseopt24.at\
+ parseopt25.at\
+ parseopt_help00.at\
+ parseopt_help01.at\
+ parseopt_help02.at\
+ parseopt_help03.at\
+ parseopt_help04.at\
+ parseopt_help05.at\
+ parseopt_help06.at\
+ parseopt_help07.at\
+ parseopt_help08.at\
+ parseopt_help09.at\
+ parseopt_help10.at\
+ parseopt_help11.at\
  prop.at\
  scantime.at\
  strftime.at\
diff --git a/libmailutils/tests/parseopt.c b/libmailutils/tests/parseopt.c
index d3caf65..bef57ee 100644
--- a/libmailutils/tests/parseopt.c
+++ b/libmailutils/tests/parseopt.c
@@ -63,8 +63,51 @@ struct mu_option group_b[] = {
 
 struct mu_option *optv[] = { group_a, group_b, NULL };
 
+static void
+version_func (FILE *fp)
+{
+  fputs ("version hook called\n", fp);
+}
+
 #define S(s) ((s)?(s):"(null)")
 
+struct parseopt_param
+{
+  char *name;
+  int flag;
+  mu_c_type_t type;
+  size_t off;
+};
+
+static struct parseopt_param parseopt_param[] = {
+  { "MU_PARSEOPT_ARGV0", MU_PARSEOPT_ARGV0, mu_c_void },
+  { "MU_PARSEOPT_IGNORE_ERRORS", MU_PARSEOPT_IGNORE_ERRORS, mu_c_void },
+  { "MU_PARSEOPT_IN_ORDER", MU_PARSEOPT_IN_ORDER, mu_c_void },
+  { "MU_PARSEOPT_NO_STDOPT", MU_PARSEOPT_NO_STDOPT, mu_c_void },
+  { "MU_PARSEOPT_NO_ERREXIT", MU_PARSEOPT_NO_ERREXIT, mu_c_void },
+  { "MU_PARSEOPT_IMMEDIATE", MU_PARSEOPT_IMMEDIATE, mu_c_void },
+  { "MU_PARSEOPT_NO_SORT", MU_PARSEOPT_NO_SORT, mu_c_void },
+
+  { "MU_PARSEOPT_PROG_NAME", MU_PARSEOPT_PROG_NAME,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_name) },
+  { "MU_PARSEOPT_PROG_DOC", MU_PARSEOPT_PROG_DOC,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_doc) },
+  { "MU_PARSEOPT_PROG_ARGS", MU_PARSEOPT_PROG_ARGS,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_args) },
+  { "MU_PARSEOPT_BUG_ADDRESS", MU_PARSEOPT_BUG_ADDRESS,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_bug_address) },
+  { "MU_PARSEOPT_PACKAGE_NAME", MU_PARSEOPT_PACKAGE_NAME,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_package_name) },
+  { "MU_PARSEOPT_PACKAGE_URL", MU_PARSEOPT_PACKAGE_URL,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_package_url) },
+  { "MU_PARSEOPT_EXTRA_INFO", MU_PARSEOPT_EXTRA_INFO,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_extra_info) },
+  { "MU_PARSEOPT_EXIT_ERROR", MU_PARSEOPT_EXIT_ERROR,
+    mu_c_int, mu_offsetof(struct mu_parseopt, po_exit_error) },
+  { "MU_PARSEOPT_VERSION_HOOK", MU_PARSEOPT_VERSION_HOOK, mu_c_void },
+  { NULL }
+};
+
 int
 main (int argc, char *argv[])
 {
@@ -79,16 +122,29 @@ main (int argc, char *argv[])
     flags = MU_PARSEOPT_DEFAULT;
   else
     {
-      if (getenv ("MU_PARSEOPT_IN_ORDER"))
-	flags |= MU_PARSEOPT_IN_ORDER;
-      if (getenv ("MU_PARSEOPT_IGNORE_ERRORS"))
-	flags |= MU_PARSEOPT_IGNORE_ERRORS;
-      if (getenv ("MU_PARSEOPT_IN_ORDER"))
-	flags |= MU_PARSEOPT_IN_ORDER;
-      if (getenv ("MU_PARSEOPT_NO_ERREXIT"))
-	flags |= MU_PARSEOPT_NO_ERREXIT;
-      if (getenv ("MU_PARSEOPT_NO_STDOPT"))
-	flags |= MU_PARSEOPT_NO_STDOPT;
+      struct parseopt_param *param;
+      for (param = parseopt_param; param->name; param++)
+	{
+	  char *val = getenv (param->name);
+	  if (val)
+	    {
+	      flags |= param->flag;
+	      if (param->type != mu_c_void)
+		{
+		  char *errmsg;
+		  int rc = mu_str_to_c (val, param->type,
+					((char*)&po + param->off),
+					&errmsg);
+		  if (rc)
+		    {
+		      fprintf (stderr, "envvar %s: %s\n",
+			       param->name, errmsg ? errmsg : mu_strerror (rc));
+		    }
+		}
+	    }
+	}
+      if (flags & MU_PARSEOPT_VERSION_HOOK)
+	po.po_version_hook = version_func;
     }
   
   rc = mu_parseopt (&po, argc, argv, optv, flags);
diff --git a/libmailutils/tests/parseopt00.at b/libmailutils/tests/parseopt00.at
index 245b637..d3b68f1 100644
--- a/libmailutils/tests/parseopt00.at
+++ b/libmailutils/tests/parseopt00.at
@@ -17,7 +17,7 @@
 AT_SETUP([empty command line])
 AT_KEYWORDS([parseopt parseopt00])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt
 ],
 [0],
diff --git a/libmailutils/tests/parseopt01.at b/libmailutils/tests/parseopt01.at
index ca9517d..351d002 100644
--- a/libmailutils/tests/parseopt01.at
+++ b/libmailutils/tests/parseopt01.at
@@ -17,7 +17,7 @@
 AT_SETUP([command line without options])
 AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt02.at b/libmailutils/tests/parseopt02.at
index fb91d53..7963a48 100644
--- a/libmailutils/tests/parseopt02.at
+++ b/libmailutils/tests/parseopt02.at
@@ -17,7 +17,7 @@
 AT_SETUP([short options])
 AT_KEYWORDS([parseopt parseopt_short parseopt02])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt -f file -x -a -d command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt03.at b/libmailutils/tests/parseopt03.at
index 08d2cfc..ac9c97e 100644
--- a/libmailutils/tests/parseopt03.at
+++ b/libmailutils/tests/parseopt03.at
@@ -17,7 +17,7 @@
 AT_SETUP([short option with argument])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_arg parseopt03])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt -ffile -x -a -d command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt04.at b/libmailutils/tests/parseopt04.at
index 319b196..a8f9ab8 100644
--- a/libmailutils/tests/parseopt04.at
+++ b/libmailutils/tests/parseopt04.at
@@ -17,7 +17,7 @@
 AT_SETUP([short option with optional argument])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_arg parseopt04])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt -ofile command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt05.at b/libmailutils/tests/parseopt05.at
index 830ddbb..b801289 100644
--- a/libmailutils/tests/parseopt05.at
+++ b/libmailutils/tests/parseopt05.at
@@ -17,7 +17,7 @@
 AT_SETUP([short option without optional argument])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_opt_noarg parseopt05])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt -o command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt06.at b/libmailutils/tests/parseopt06.at
index 87bdfbe..55d6789 100644
--- a/libmailutils/tests/parseopt06.at
+++ b/libmailutils/tests/parseopt06.at
@@ -17,7 +17,7 @@
 AT_SETUP([incremental short option])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_incr parseopt06])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt -d -d command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt07.at b/libmailutils/tests/parseopt07.at
index ae0fbb3..51df00d 100644
--- a/libmailutils/tests/parseopt07.at
+++ b/libmailutils/tests/parseopt07.at
@@ -17,7 +17,7 @@
 AT_SETUP([short option clustering])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_cluster parseopt07])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt -xffile -dado10 command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt08.at b/libmailutils/tests/parseopt08.at
index 0b020f1..cab69de 100644
--- a/libmailutils/tests/parseopt08.at
+++ b/libmailutils/tests/parseopt08.at
@@ -17,7 +17,7 @@
 AT_SETUP([long options])
 AT_KEYWORDS([parseopt parseopt_long parseopt08])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --file=file --all command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt09.at b/libmailutils/tests/parseopt09.at
index 7f6ca10..ade889c 100644
--- a/libmailutils/tests/parseopt09.at
+++ b/libmailutils/tests/parseopt09.at
@@ -17,7 +17,7 @@
 AT_SETUP([long option with argument])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --file file command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt10.at b/libmailutils/tests/parseopt10.at
index dbd0d42..6278c2d 100644
--- a/libmailutils/tests/parseopt10.at
+++ b/libmailutils/tests/parseopt10.at
@@ -17,7 +17,7 @@
 AT_SETUP([long option with optional argument])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_arg parseopt10])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --optional=file command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt11.at b/libmailutils/tests/parseopt11.at
index 5284e52..a0cafa7 100644
--- a/libmailutils/tests/parseopt11.at
+++ b/libmailutils/tests/parseopt11.at
@@ -17,7 +17,7 @@
 AT_SETUP([long option without optional argument])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_opt_noarg parseopt11])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --optional command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt12.at b/libmailutils/tests/parseopt12.at
index a8d56ca..6ec591c 100644
--- a/libmailutils/tests/parseopt12.at
+++ b/libmailutils/tests/parseopt12.at
@@ -17,7 +17,7 @@
 AT_SETUP([incremental long option])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_incr parseopt12])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --debug --debug command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt13.at b/libmailutils/tests/parseopt13.at
index d67865f..e458f6a 100644
--- a/libmailutils/tests/parseopt13.at
+++ b/libmailutils/tests/parseopt13.at
@@ -17,7 +17,7 @@
 AT_SETUP([abbreviated long options])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt13])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --fil=file --fin=Word command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt14.at b/libmailutils/tests/parseopt14.at
index a06e425..de9a538 100644
--- a/libmailutils/tests/parseopt14.at
+++ b/libmailutils/tests/parseopt14.at
@@ -17,7 +17,7 @@
 AT_SETUP([ambiguous abbreviated long options])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_abbr parseopt_long_ambig parseopt14])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --fi=file --fi=Word command line arguments
 ],
 [1],
diff --git a/libmailutils/tests/parseopt15.at b/libmailutils/tests/parseopt15.at
index 5c51090..1a9045e 100644
--- a/libmailutils/tests/parseopt15.at
+++ b/libmailutils/tests/parseopt15.at
@@ -17,7 +17,7 @@
 AT_SETUP([mixed long and short options])
 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt15.at])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
+PARSEOPT_DEFAULT
 parseopt --file=filename -o -xa --find word -j10 command line arguments
 ],
 [0],
diff --git a/libmailutils/tests/parseopt16.at b/libmailutils/tests/parseopt16.at
index af13145..0d2dfaf 100644
--- a/libmailutils/tests/parseopt16.at
+++ b/libmailutils/tests/parseopt16.at
@@ -15,8 +15,9 @@
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AT_SETUP([option aliases])
-AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt16.at])
+AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_alias parseopt16.at])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt -vvv
 ],
 [0],
diff --git a/libmailutils/tests/parseopt17.at b/libmailutils/tests/parseopt17.at
index b82df13..2823e0a 100644
--- a/libmailutils/tests/parseopt17.at
+++ b/libmailutils/tests/parseopt17.at
@@ -17,6 +17,7 @@
 AT_SETUP([argument permutation])
 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt17.at])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt more --file=file arguments follow -x -o options
 ],
 [0],
diff --git a/libmailutils/tests/parseopt18.at b/libmailutils/tests/parseopt18.at
index e9f753a..0b1a3e3 100644
--- a/libmailutils/tests/parseopt18.at
+++ b/libmailutils/tests/parseopt18.at
@@ -17,6 +17,7 @@
 AT_SETUP([double-dash])
 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt -x --file=foobar -- -a --optional arg
 ],
 [0],
diff --git a/libmailutils/tests/parseopt19.at b/libmailutils/tests/parseopt19.at
index 94a59f7..e680ecf 100644
--- a/libmailutils/tests/parseopt19.at
+++ b/libmailutils/tests/parseopt19.at
@@ -17,6 +17,7 @@
 AT_SETUP([double-dash with permutation])
 AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt19.at])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt -x more --file=foobar -- -a --optional arg
 ],
 [0],
diff --git a/libmailutils/tests/parseopt20.at b/libmailutils/tests/parseopt20.at
index 092a8db..64e8548 100644
--- a/libmailutils/tests/parseopt20.at
+++ b/libmailutils/tests/parseopt20.at
@@ -17,10 +17,11 @@
 AT_SETUP([short option without required argument])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_noarg parseopt20])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt -f
 ],
 [1],
 [],
 [parseopt: option '-f' requires an argument
 ])
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
diff --git a/libmailutils/tests/parseopt21.at b/libmailutils/tests/parseopt21.at
index 5982013..4f04c31 100644
--- a/libmailutils/tests/parseopt21.at
+++ b/libmailutils/tests/parseopt21.at
@@ -17,10 +17,11 @@
 AT_SETUP([long option without required argument])
 AT_KEYWORDS([parseopt parseopt_long parseopt_long_noarg parseopt21])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt --file
 ],
 [1],
 [],
 [parseopt: option '--file' requires an argument
 ])
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
diff --git a/libmailutils/tests/parseopt22.at b/libmailutils/tests/parseopt22.at
index d07f1d5..e755026 100644
--- a/libmailutils/tests/parseopt22.at
+++ b/libmailutils/tests/parseopt22.at
@@ -17,10 +17,11 @@
 AT_SETUP([unrecognized option])
 AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
 AT_CHECK([
+PARSEOPT_DEFAULT
 parseopt -X
 ],
 [1],
 [],
 [parseopt: unrecognized option '-X'
 ])
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
diff --git a/libmailutils/tests/parseopt09.at b/libmailutils/tests/parseopt23.at
similarity index 79%
copy from libmailutils/tests/parseopt09.at
copy to libmailutils/tests/parseopt23.at
index 7f6ca10..aaf75fc 100644
--- a/libmailutils/tests/parseopt09.at
+++ b/libmailutils/tests/parseopt23.at
@@ -14,15 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([long option with argument])
-AT_KEYWORDS([parseopt parseopt_long parseopt_long_arg parseopt09])
+AT_SETUP([in order parsing])
+AT_KEYWORDS([parseopt parseopt_in_order parseopt23])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
-parseopt --file file command line arguments
+PARSEOPT_DEFAULT
+MU_PARSEOPT_IN_ORDER=1 parseopt --file=filename more -a -x arguments
 ],
 [0],
 [rc=0
-file_name=file
+file_name=filename
 opt_value=initial
 x_option=0
 a_option=0
@@ -30,8 +30,10 @@ find_value=(null)
 d_option=0
 jobs=0
 argv:
-0: command
-1: line
-2: arguments
+0: more
+1: -a
+2: -x
+3: arguments
 ])
 AT_CLEANUP
+
diff --git a/libmailutils/tests/parseopt22.at b/libmailutils/tests/parseopt25.at
similarity index 79%
copy from libmailutils/tests/parseopt22.at
copy to libmailutils/tests/parseopt25.at
index d07f1d5..2cbbe3f 100644
--- a/libmailutils/tests/parseopt22.at
+++ b/libmailutils/tests/parseopt25.at
@@ -14,13 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([unrecognized option])
-AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
+AT_SETUP([MU_PARSEOPT_VERSION_HOOK])
+AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt25])
 AT_CHECK([
-parseopt -X
+PARSEOPT_DEFAULT
+MU_PARSEOPT_VERSION_HOOK=1 parseopt -V
 ],
-[1],
-[],
-[parseopt: unrecognized option '-X'
+[0],
+[version hook called
 ])
-AT_CLEANUP
\ No newline at end of file
+AT_CLEANUP
diff --git a/libmailutils/tests/parseopt18.at b/libmailutils/tests/parseopt_help00.at
similarity index 51%
copy from libmailutils/tests/parseopt18.at
copy to libmailutils/tests/parseopt_help00.at
index e9f753a..c3751ac 100644
--- a/libmailutils/tests/parseopt18.at
+++ b/libmailutils/tests/parseopt_help00.at
@@ -14,24 +14,33 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([double-dash])
-AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
+AT_SETUP([standard help output])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help00])
 AT_CHECK([
-parseopt -x --file=foobar -- -a --optional arg
+PARSEOPT_DEFAULT
+parseopt --help
 ],
 [0],
-[rc=0
-file_name=foobar
-opt_value=initial
-x_option=1
-a_option=0
-find_value=(null)
-d_option=0
-jobs=0
-argv:
-0: -a
-1: --optional
-2: arg
-])
+[[Usage: parseopt [OPTION]...
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[=FILE]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+]])
 AT_CLEANUP
 
+
diff --git a/libmailutils/tests/parseopt02.at b/libmailutils/tests/parseopt_help01.at
similarity index 70%
copy from libmailutils/tests/parseopt02.at
copy to libmailutils/tests/parseopt_help01.at
index fb91d53..63ecf56 100644
--- a/libmailutils/tests/parseopt02.at
+++ b/libmailutils/tests/parseopt_help01.at
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([short options])
-AT_KEYWORDS([parseopt parseopt_short parseopt02])
+AT_SETUP([standard usage output])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help00])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
-parseopt -f file -x -a -d command line arguments
+PARSEOPT_DEFAULT
+parseopt --usage
 ],
 [0],
-[rc=0
-file_name=file
-opt_value=initial
-x_option=1
-a_option=1
-find_value=(null)
-d_option=1
-jobs=0
-argv:
-0: command
-1: line
-2: arguments
-])
+[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
+            [--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
+            [--optional=FILE] [--usage] [--verbose]
+]])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt18.at b/libmailutils/tests/parseopt_help02.at
similarity index 50%
copy from libmailutils/tests/parseopt18.at
copy to libmailutils/tests/parseopt_help02.at
index e9f753a..79aef4d 100644
--- a/libmailutils/tests/parseopt18.at
+++ b/libmailutils/tests/parseopt_help02.at
@@ -14,24 +14,33 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([double-dash])
-AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
+AT_SETUP([MU_PARSEOPT_PROG_NAME])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help02])
 AT_CHECK([
-parseopt -x --file=foobar -- -a --optional arg
+PARSEOPT_DEFAULT
+MU_PARSEOPT_PROG_NAME=newname parseopt --help
 ],
 [0],
-[rc=0
-file_name=foobar
-opt_value=initial
-x_option=1
-a_option=0
-find_value=(null)
-d_option=0
-jobs=0
-argv:
-0: -a
-1: --optional
-2: arg
-])
+[[Usage: newname [OPTION]...
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[=FILE]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+]])
 AT_CLEANUP
 
+
diff --git a/libmailutils/tests/parseopt_help03.at b/libmailutils/tests/parseopt_help03.at
new file mode 100644
index 0000000..f004bcf
--- /dev/null
+++ b/libmailutils/tests/parseopt_help03.at
@@ -0,0 +1,47 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([MU_PARSEOPT_PROG_DOC])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help03])
+AT_CHECK([
+unset ARGP_HELP_FMT
+MU_PARSEOPT_PROG_DOC="Tests option parsing" parseopt --help
+],
+[0],
+[[Usage: parseopt [OPTION]...
+Tests option parsing
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[=FILE]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+]])
+AT_CLEANUP
+
+
diff --git a/libmailutils/tests/parseopt_help04.at b/libmailutils/tests/parseopt_help04.at
new file mode 100644
index 0000000..1c6de2e
--- /dev/null
+++ b/libmailutils/tests/parseopt_help04.at
@@ -0,0 +1,46 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([MU_PARSEOPT_PROG_ARGS])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help04])
+AT_CHECK([
+PARSEOPT_DEFAULT
+MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
+],
+[0],
+[Usage: parseopt [[OPTION]]... SOME MORE ARGS
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[[=FILE]]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+])
+AT_CLEANUP
+
+
diff --git a/libmailutils/tests/parseopt_help05.at b/libmailutils/tests/parseopt_help05.at
new file mode 100644
index 0000000..9a0c1ed
--- /dev/null
+++ b/libmailutils/tests/parseopt_help05.at
@@ -0,0 +1,47 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([MU_PARSEOPT_BUG_ADDRESS])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help05])
+AT_CHECK([
+PARSEOPT_DEFAULT
+MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>' parseopt --help
+],
+[0],
+[Usage: parseopt [[OPTION]]...
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[[=FILE]]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+Report bugs to <gray@gnu.org>.
+])
+AT_CLEANUP
+
+
diff --git a/libmailutils/tests/parseopt_help06.at b/libmailutils/tests/parseopt_help06.at
new file mode 100644
index 0000000..5ba784f
--- /dev/null
+++ b/libmailutils/tests/parseopt_help06.at
@@ -0,0 +1,47 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([MU_PARSEOPT_PACKAGE_NAME and MU_PARSEOPT_PACKAGE_URL])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help06])
+AT_CHECK([
+PARSEOPT_DEFAULT
+MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailutils.org' parseopt --help
+],
+[0],
+[[Usage: parseopt [OPTION]...
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[=FILE]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+GNU Mailutils home page: <http://mailutils.org>
+]])
+AT_CLEANUP
+
+
diff --git a/libmailutils/tests/parseopt_help07.at b/libmailutils/tests/parseopt_help07.at
new file mode 100644
index 0000000..265acb4
--- /dev/null
+++ b/libmailutils/tests/parseopt_help07.at
@@ -0,0 +1,56 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([all data])
+AT_KEYWORDS([parseopt parseopt_help parseopt_help07])
+AT_CHECK([
+PARSEOPT_DEFAULT
+MU_PARSEOPT_PROG_DOC="Tests option parsing"\
+ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS"\ 
+ MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>'\
+ MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils'\
+ MU_PARSEOPT_PACKAGE_URL='http://mailutils.org'\
+ MU_PARSEOPT_EXTRA_INFO='General help using GNU software: <http://www.gnu.org/gethelp/>'\
+ parseopt --help
+],
+[0],
+[[Usage: parseopt [OPTION]... SOME MORE ARGS
+Tests option parsing
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[=FILE]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+Report bugs to <gray@gnu.org>.
+GNU Mailutils home page: <http://mailutils.org>
+General help using GNU software: <http://www.gnu.org/gethelp/>
+]])
+AT_CLEANUP
+
+
diff --git a/libmailutils/tests/parseopt18.at b/libmailutils/tests/parseopt_help08.at
similarity index 50%
copy from libmailutils/tests/parseopt18.at
copy to libmailutils/tests/parseopt_help08.at
index e9f753a..c9f1029 100644
--- a/libmailutils/tests/parseopt18.at
+++ b/libmailutils/tests/parseopt_help08.at
@@ -14,24 +14,31 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([double-dash])
-AT_KEYWORDS([parseopt parseopt_long parseopt_short parseopt_double_dash parseopt18.at])
+AT_SETUP([ARGP_HELP_FMT compatibility])
+AT_KEYWORDS([parseopt parseopt_help ARGP_HELP_FMT parseopt_help08])
 AT_CHECK([
-parseopt -x --file=foobar -- -a --optional arg
+PARSEOPT_DEFAULT
+ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-col=10\
+ parseopt --help
 ],
 [0],
-[rc=0
-file_name=foobar
-opt_value=initial
-x_option=1
-a_option=0
-find_value=(null)
-d_option=0
-jobs=0
-argv:
-0: -a
-1: --optional
-2: arg
-])
+[[Usage: parseopt [OPTION]...
+
+          Group A
+ -a,  --all                     no arguments to this one
+ -f FILE, --file=FILE           set file name
+ -o[FILE], --optional[=FILE]    optional argument
+ -x                             short-only option
+
+          Group B
+ -F VALUE, --find=VALUE         find VALUE
+ -d, -v, --debug, --verbose     another option
+ -j N, --jobs=N                 sets numeric value
+
+ -?,  --help                    give this help list
+      --usage                   give a short usage message
+
+]])
 AT_CLEANUP
 
+
diff --git a/libmailutils/tests/parseopt01.at b/libmailutils/tests/parseopt_help09.at
similarity index 67%
copy from libmailutils/tests/parseopt01.at
copy to libmailutils/tests/parseopt_help09.at
index ca9517d..d727bdf 100644
--- a/libmailutils/tests/parseopt01.at
+++ b/libmailutils/tests/parseopt_help09.at
@@ -14,24 +14,16 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([command line without options])
-AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
+AT_SETUP([ARGP_HELP_FMT usage compatibility])
+AT_KEYWORDS([parseopt parseopt_help ARGP_HELP_FMT parseopt_help09])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
-parseopt command line arguments
+PARSEOPT_DEFAULT
+ARGP_HELP_FMT=rmargin=62,usage-indent=1\
+ parseopt --usage
 ],
 [0],
-[rc=0
-file_name=(null)
-opt_value=initial
-x_option=0
-a_option=0
-find_value=(null)
-d_option=0
-jobs=0
-argv:
-0: command
-1: line
-2: arguments
-])
+[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N]
+ [-o FILE] [--all] [--debug] [--file=FILE] [--find=VALUE]
+ [--help] [--jobs=N] [--optional=FILE] [--usage] [--verbose]
+]])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt01.at b/libmailutils/tests/parseopt_help10.at
similarity index 66%
copy from libmailutils/tests/parseopt01.at
copy to libmailutils/tests/parseopt_help10.at
index ca9517d..3f70616 100644
--- a/libmailutils/tests/parseopt01.at
+++ b/libmailutils/tests/parseopt_help10.at
@@ -14,24 +14,15 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([command line without options])
-AT_KEYWORDS([parseopt parseopt_noopt parseopt01])
+AT_SETUP([MU_PARSEOPT_VERSION_HOOK usage output])
+AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt26])
 AT_CHECK([
-MU_PARSEOPT_DEFAULT=1
-parseopt command line arguments
+PARSEOPT_DEFAULT
+MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage
 ],
 [0],
-[rc=0
-file_name=(null)
-opt_value=initial
-x_option=0
-a_option=0
-find_value=(null)
-d_option=0
-jobs=0
-argv:
-0: command
-1: line
-2: arguments
-])
+[[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
+            [--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
+            [--optional=FILE] [--usage] [--verbose] [--version]
+]])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt_help11.at b/libmailutils/tests/parseopt_help11.at
new file mode 100644
index 0000000..a8bda93
--- /dev/null
+++ b/libmailutils/tests/parseopt_help11.at
@@ -0,0 +1,45 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([MU_PARSEOPT_VERSION_HOOK help output])
+AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK help])
+AT_CHECK([
+PARSEOPT_DEFAULT
+MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
+],
+[0],
+[[Usage: parseopt [OPTION]...
+
+ Group A
+  -a, --all                  no arguments to this one
+  -f, --file=FILE            set file name
+  -o, --optional[=FILE]      optional argument
+  -x                         short-only option
+
+ Group B
+  -F, --find=VALUE           find VALUE
+  -d, -v, --debug, --verbose another option
+  -j, --jobs=N               sets numeric value
+
+  -?, --help                 give this help list
+      --usage                give a short usage message
+  -V, --version              print program version
+
+Mandatory or optional arguments to long options are also mandatory or optional
+for any corresponding short options.
+
+]])
+AT_CLEANUP
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index be39fca..12043f9 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -57,6 +57,24 @@ AT_BANNER([Conversions])
 m4_include([strtoc.at])
 
 AT_BANNER([Command line parser])
+m4_define([PARSEOPT_DEFAULT],[
+unset ARGP_HELP_FMT
+unset MU_PARSEOPT_ARGV0
+unset MU_PARSEOPT_IGNORE_ERRORS
+unset MU_PARSEOPT_IN_ORDER
+unset MU_PARSEOPT_NO_STDOPT
+unset MU_PARSEOPT_NO_ERREXIT
+unset MU_PARSEOPT_IMMEDIATE
+unset MU_PARSEOPT_NO_SORT
+
+unset MU_PARSEOPT_PROG_NAME
+unset MU_PARSEOPT_PROG_DOC
+unset MU_PARSEOPT_PROG_ARGS
+unset MU_PARSEOPT_BUG_ADDRESS
+unset MU_PARSEOPT_PACKAGE_NAME
+unset MU_PARSEOPT_PACKAGE_URL
+])
+
 m4_include([parseopt00.at])
 m4_include([parseopt01.at])
 m4_include([parseopt02.at])
@@ -80,6 +98,23 @@ m4_include([parseopt19.at])
 m4_include([parseopt20.at])
 m4_include([parseopt21.at])
 m4_include([parseopt22.at])
+m4_include([parseopt23.at])
+m4_include([parseopt24.at])
+m4_include([parseopt25.at])
+
+AT_BANNER([Command line help output])
+m4_include([parseopt_help00.at])
+m4_include([parseopt_help01.at])
+m4_include([parseopt_help02.at])
+m4_include([parseopt_help03.at])
+m4_include([parseopt_help04.at])
+m4_include([parseopt_help05.at])
+m4_include([parseopt_help06.at])
+m4_include([parseopt_help07.at])
+m4_include([parseopt_help08.at])
+m4_include([parseopt_help09.at])
+m4_include([parseopt_help10.at])
+m4_include([parseopt_help11.at])
 
 AT_BANNER([Standard streams])
 m4_include([strin.at])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 10 14:08:01 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1btezZ-0001BD-Ps
	for mharc-commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:08:01 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:48080)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btezW-0001A5-QG
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:08:00 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btezU-0002Mq-Eg
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:07:57 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:53161)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btezU-0002Mm-Ai
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:07:56 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 14D20220167; Mon, 10 Oct 2016 18:07:56 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-765-g045898f
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 219182387a823ae8113a5a14cf29f9263d00171c
X-Git-Newrev: 045898ffd13dd8938dc3855a6275006175cc4823
Message-Id: <20161010180756.14D20220167@vcs.savannah.gnu.org>
Date: Mon, 10 Oct 2016 18:07:55 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 10 Oct 2016 18:08:00 -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=045898ffd13dd8938dc3855a6275006175cc4823

The branch, master has been updated
       via  045898ffd13dd8938dc3855a6275006175cc4823 (commit)
      from  219182387a823ae8113a5a14cf29f9263d00171c (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 045898ffd13dd8938dc3855a6275006175cc4823
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 10 21:06:18 2016 +0300

    Add missing test

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

Summary of changes:
 libmailutils/tests/{parseopt22.at => parseopt24.at} |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
 copy libmailutils/tests/{parseopt22.at => parseopt24.at} (85%)

diff --git a/libmailutils/tests/parseopt22.at b/libmailutils/tests/parseopt24.at
similarity index 85%
copy from libmailutils/tests/parseopt22.at
copy to libmailutils/tests/parseopt24.at
index e755026..50053c1 100644
--- a/libmailutils/tests/parseopt22.at
+++ b/libmailutils/tests/parseopt24.at
@@ -14,13 +14,13 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([unrecognized option])
-AT_KEYWORDS([parseopt parseopt_short parseopt_short_unrecognized parseopt22])
+AT_SETUP([MU_PARSEOPT_EXIT_ERROR])
+AT_KEYWORDS([parseopt MU_PARSEOPT_EXIT_ERROR parseopt24])
 AT_CHECK([
 PARSEOPT_DEFAULT
-parseopt -X
+MU_PARSEOPT_EXIT_ERROR=64 parseopt -X
 ],
-[1],
+[64],
 [],
 [parseopt: unrecognized option '-X'
 ])


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 10 14:50:23 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1btfeZ-00022Z-EW
	for mharc-commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:50:23 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:37351)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btfeX-00022O-OS
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:50:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btfeV-0000Lb-FV
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:50:20 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:53772)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1btfeV-0000LM-Ab
	for commit-mailutils@gnu.org; Mon, 10 Oct 2016 14:50:19 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id D5C1F220167; Mon, 10 Oct 2016 18:50:18 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-766-g6e81473
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 045898ffd13dd8938dc3855a6275006175cc4823
X-Git-Newrev: 6e8147334cf9ffe36367760c06002a1e5b7ae0d5
Message-Id: <20161010185018.D5C1F220167@vcs.savannah.gnu.org>
Date: Mon, 10 Oct 2016 18:50:18 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 10 Oct 2016 18:50:23 -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=6e8147334cf9ffe36367760c06002a1e5b7ae0d5

The branch, master has been updated
       via  6e8147334cf9ffe36367760c06002a1e5b7ae0d5 (commit)
      from  045898ffd13dd8938dc3855a6275006175cc4823 (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 6e8147334cf9ffe36367760c06002a1e5b7ae0d5
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Mon Oct 10 21:47:41 2016 +0300

    Raise shared library version number
    
    * configure.ac (VI_CURRENT): Set to 5
    Don't link intprops.h
    * gnulib: Upgrade.
    * gnulib.modules (intprops) Remove.
    * libmailutils/cfg/parser.y: Don't incluse intprops.h
    * po/POTFILES.in: Add new files.

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

Summary of changes:
 configure.ac              |   11 ++++-------
 gnulib                    |    2 +-
 gnulib.modules            |    1 -
 libmailutils/cfg/parser.y |    1 -
 po/POTFILES.in            |    4 ++++
 5 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 7bd3641..dc244de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,7 +31,7 @@ dnl Autobuild stuff
 AB_INIT
 
 dnl Library versioning
-AC_SUBST(VI_CURRENT,  4)
+AC_SUBST(VI_CURRENT,  5)
 AC_SUBST(VI_REVISION, 0)
 AC_SUBST(VI_AGE,      0)
 
@@ -111,15 +111,12 @@ AC_CHECK_TYPE(iconv_t,:,
 ])
 
 # NOTE: Generally speaking, Mailutils libraries are not allowed to include
-# gnulib headers.  The only exceptions are: gettext.h, which is needed for
-# proper i18n, and intprops.h, which is used in libmailutils/cfg_parser.y.
-# This latter will probably be rewritten to remove the need for intprops.h.
+# gnulib headers.  The only exception is gettext.h, which is needed for
+# proper i18n.
 #
-# To make these two headers accessible for the libraries, they are linked
-# to include/.
+# To make it accessible for the libraries, it is linked to include/.
 #
 AC_CONFIG_LINKS(include/gettext.h:lib/gnu/gettext.h)
-AC_CONFIG_LINKS(include/intprops.h:lib/gnu/intprops.h)
 
 AH_BOTTOM([
 #define DEFAULT_TEXT_DOMAIN PACKAGE
diff --git a/gnulib b/gnulib
index a6aa0b6..2692e23 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit a6aa0b6f74864a94e940b310f6200e18f7d9dcc9
+Subproject commit 2692e23a48e21f6daa029e8af9f1a143b7532f47
diff --git a/gnulib.modules b/gnulib.modules
index afea682..a552282 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -8,7 +8,6 @@ argp
 crypto/des
 gettext
 gitlog-to-changelog
-intprops
 inttostr
 mbchar
 mbiter
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index 6877063..e36b513 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -25,7 +25,6 @@
 #include <stdarg.h>
 #include <string.h>
 #include <netdb.h>
-#include "intprops.h"
 #include <mailutils/argcv.h>
 #include <mailutils/wordsplit.h>
 #include <mailutils/nls.h>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 433c3c9..135171c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -123,6 +123,9 @@ libmailutils/diag/debug.c
 libmailutils/diag/diag.c
 libmailutils/diag/errors
 
+libmailutils/opt/opt.c
+libmailutils/opt/help.c
+
 libmailutils/server/acl.c
 
 libmailutils/stream/file_stream.c
@@ -147,6 +150,7 @@ libmailutils/base/version.c
 libmailutils/base/tempfile.c
 
 libmailutils/string/trueans.c
+libmailutils/string/str_to_c.c
 
 libmailutils/stdstream/basestr.c
 libmailutils/stdstream/strerr.c


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Oct 12 02:23:28 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1buCwq-0002oI-O7
	for mharc-commit-mailutils@gnu.org; Wed, 12 Oct 2016 02:23:28 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:56979)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1buCwf-0002o6-7n
	for commit-mailutils@gnu.org; Wed, 12 Oct 2016 02:23:28 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1buCwS-00019l-Sq
	for commit-mailutils@gnu.org; Wed, 12 Oct 2016 02:23:17 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:32883)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1buCwS-00019d-JO
	for commit-mailutils@gnu.org; Wed, 12 Oct 2016 02:23:04 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 45599220167; Wed, 12 Oct 2016 06:23:04 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-769-gd56b824
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 6e8147334cf9ffe36367760c06002a1e5b7ae0d5
X-Git-Newrev: d56b82437f909ff323d9cd87f2ed9f04322f9966
Message-Id: <20161012062304.45599220167@vcs.savannah.gnu.org>
Date: Wed, 12 Oct 2016 06:23:03 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 12 Oct 2016 06:23: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=d56b82437f909ff323d9cd87f2ed9f04322f9966

The branch, master has been updated
       via  d56b82437f909ff323d9cd87f2ed9f04322f9966 (commit)
       via  260b113a1e75989b4e460712f16af10d93fe19e8 (commit)
       via  bc73fc65600b6021dfe7a9fa1fba7e9b823993e2 (commit)
      from  6e8147334cf9ffe36367760c06002a1e5b7ae0d5 (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 d56b82437f909ff323d9cd87f2ed9f04322f9966
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Wed Oct 12 09:15:47 2016 +0300

    Convert to mu_cli: frm, from, messages, mimeview, movemail, readmsg, sieve
    
    * configure.ac (MU_APP_NEW_LIBRARIES): New temp variable.
    
    * include/mailutils/sieve.h (mu_cli_capa_sieve): New extern.
    * include/mailutils/tls.h (mu_cli_capa_tls): New extern.
    
    * libmailutils/cli/cli.c: Minor change.
    * libmailutils/cli/stdcapa.c: Add "auth" capability.
    
    * libmu_auth/tls.c: provide mu_cli_capa_tls
    
    * dotlock/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * dotlock/dotlock.c
    
    * frm/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * frm/frm.h: Fix includes.
    * frm/frm.c: Use mu_cli for optionr&config parsing.
    * frm/from.c: Likewise.
    
    * messages/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * messages/messages.c: Use mu_cli for optionr&config parsing.
    
    * mimeview/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * mimeview/mimeview.c: Use mu_cli for optionr&config parsing.
    
    * movemail/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * movemail/movemail.c: Use mu_cli for optionr&config parsing.
    
    * readmsg/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * readmsg/readmsg.c: Use mu_cli for optionr&config parsing.
    
    * sieve/Makefile.am: Link with MU_APP_NEW_LIBRARIES
    * sieve/sieve.c: Use mu_cli for optionr&config parsing.

commit 260b113a1e75989b4e460712f16af10d93fe19e8
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Tue Oct 11 18:02:33 2016 +0300

    Bugfix
    
    * libmailutils/opt/opt.c (find_long_option): Don't mark ambiguity
    if the matching option unaliases to the same option as the found one.

commit bc73fc65600b6021dfe7a9fa1fba7e9b823993e2
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Tue Oct 11 17:20:38 2016 +0300

    Introduce new CLI/configuration code for mailutils applications.
    
    The new API is to replace libmu_cfg and libmu_argp.  A smooth transition
    is scheduled, during which the two APIs will coexist,
    
    * configure.ac: Build libmailutils/cli/Makefile
    * include/mailutils/cli.h: New file.
    * include/mailutils/Makefile.am: Add cli.h
    * libmailutils/cli/Makefile.am: New file.
    * libmailutils/cli/capa.c: New file.
    * libmailutils/cli/cli.c: New file.
    * libmailutils/cli/stdcapa.c: New file.
    * libmailutils/Makefile.am (SUBDIRS): Add cli.
    
    * include/mailutils/cfg.h (mu_cfg_parse_hints): New members: append_tree
    and data.
    (MU_PARSE_CONFIG_LINT): New flag.
    * include/mailutils/diag.h (mu_program_name)
    (mu_full_program_name): Remove const qualifier.
    * include/mailutils/locker.h (mu_locker_set_default_external_program):
    Argument is const.
    * libmailutils/base/locker.c: Likewise.
    
    * include/mailutils/opt.h (mu_progname, mu_absprogname): Replace
    with mu_program_name and mu_full_program_name.
    (mu_set_progname): Rename to mu_set_program_name.
    (mu_parseopt) <po_data>: Change type to void *.
    (po_help_hook, po_version_hook): Change signatures.
    (mu_parseopt_error): New function.
    * libmailutils/opt/progname.c (mu_progname, mu_absprogname): Replace
    with mu_program_name and mu_full_program_name.
    (mu_set_progname): Rename to mu_set_program_name.
    * libmailutils/opt/help.c: Minor changes
    * libmailutils/opt/opt.c (parse_error): Rename to mu_parse_error (extern).
    (next_opt): Fix permutations.
    * libmailutils/tests/parseopt.c: Reflect changes.
    * libmailutils/tests/parseopt17.at: Improve test case
    * libmailutils/tests/parseopt_help05.at: Reflect changes.
    * libmailutils/tests/parseopt_help07.at: Reflect changes.
    
    * include/mailutils/stdstream.h (mu_program_name): Remove qualifier.
    
    * libmailutils/cfg/driver.c (mu_cfg_tree_reduce): Remove useless condition
    
    * libmailutils/cfg/lexer.l (mu_cfg_parse_file): Additional info messages.
    * libmailutils/cfg/parser.y (mu_cfg_parse_config): Join in
    the append_tree.
    * libmailutils/diag/diag.c (mu_program_name, mu_full_program_name)
    (mu_set_program_name): Remove. Declared elsewhere.
    * libmu_sieve/conf.c: Add new configuration code. Mark old text for
    removal.
    * libmailutils/tests/tcli.c: New program.
    * libmailutils/tests/Makefile.am: Add tcli.c

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

Summary of changes:
 configure.ac                          |    2 +
 dotlock/Makefile.am                   |    2 +-
 dotlock/dotlock.c                     |  146 +++------
 frm/Makefile.am                       |    2 +-
 frm/frm.c                             |  190 +++++------
 frm/frm.h                             |    2 +-
 frm/from.c                            |   83 ++---
 include/mailutils/Makefile.am         |    1 +
 include/mailutils/cfg.h               |    5 +-
 include/mailutils/cli.h               |   55 ++++
 include/mailutils/diag.h              |    4 +-
 include/mailutils/locker.h            |    2 +-
 include/mailutils/opt.h               |   16 +-
 include/mailutils/sieve.h             |    3 +
 include/mailutils/stdstream.h         |    2 +-
 include/mailutils/tls.h               |    3 +
 libmailutils/Makefile.am              |    3 +-
 libmailutils/base/locker.c            |    2 +-
 libmailutils/cfg/driver.c             |   12 +-
 libmailutils/cfg/lexer.l              |    6 +
 libmailutils/cfg/parser.y             |    5 +-
 libmailutils/{opt => cli}/Makefile.am |   10 +-
 libmailutils/cli/capa.c               |   96 ++++++
 libmailutils/cli/cli.c                |  420 ++++++++++++++++++++++++
 libmailutils/cli/stdcapa.c            |  568 +++++++++++++++++++++++++++++++++
 libmailutils/diag/diag.c              |   26 --
 libmailutils/opt/help.c               |    8 +-
 libmailutils/opt/opt.c                |   26 +-
 libmailutils/opt/progname.c           |   14 +-
 libmailutils/tests/.gitignore         |    1 +
 libmailutils/tests/Makefile.am        |    1 +
 libmailutils/tests/parseopt.c         |    4 +-
 libmailutils/tests/parseopt17.at      |   20 ++
 libmailutils/tests/parseopt_help05.at |    2 +-
 libmailutils/tests/parseopt_help07.at |    2 +-
 libmailutils/tests/tcli.c             |   75 +++++
 libmu_auth/tls.c                      |  111 ++++++-
 libmu_sieve/conf.c                    |  171 +++++++++-
 messages/Makefile.am                  |    2 +-
 messages/messages.c                   |   89 ++----
 mimeview/Makefile.am                  |    2 +-
 mimeview/mimeview.c                   |  169 +++++-----
 movemail/Makefile.am                  |    2 +-
 movemail/movemail.c                   |  294 ++++++++---------
 readmsg/Makefile.am                   |    2 +-
 readmsg/readmsg.c                     |  140 +++-----
 sieve/Makefile.am                     |    2 +-
 sieve/sieve.c                         |  265 ++++++---------
 48 files changed, 2123 insertions(+), 945 deletions(-)
 create mode 100644 include/mailutils/cli.h
 copy libmailutils/{opt => cli}/Makefile.am (91%)
 create mode 100644 libmailutils/cli/capa.c
 create mode 100644 libmailutils/cli/cli.c
 create mode 100644 libmailutils/cli/stdcapa.c
 create mode 100644 libmailutils/tests/tcli.c

diff --git a/configure.ac b/configure.ac
index dc244de..d9f1b58 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,7 @@ AC_SUBST(MU_SIEVE_MODDIR,'$(libdir)/$(PACKAGE)')
 
 AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)')
 AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/libmu_argp/libmu_argp.la ${top_builddir}/libmu_cfg/libmu_cfg.la ${top_builddir}/lib/libmuaux.la')
+AC_SUBST(MU_APP_NEW_LIBRARIES,'${top_builddir}/lib/libmuaux.la')
 
 # There are two sets of include directories: MU_LIB_COMMON_INCLUDES, used
 # by the libraries, and MU_APP_COMMON_INCLUDES, which is used by applications.
@@ -1506,6 +1507,7 @@ AC_CONFIG_FILES([
  libmailutils/address/Makefile
  libmailutils/sockaddr/Makefile
  libmailutils/cidr/Makefile
+ libmailutils/cli/Makefile
  libmailutils/cfg/Makefile
  libmailutils/datetime/Makefile
  libmailutils/diag/Makefile
diff --git a/dotlock/Makefile.am b/dotlock/Makefile.am
index 3425b0f..0ab3f34 100644
--- a/dotlock/Makefile.am
+++ b/dotlock/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
 bin_PROGRAMS = dotlock
 
 dotlock_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MAILUTILS}\
  @MU_COMMON_LIBRARIES@
 
diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index c6a96c5..0a8cfec 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -20,49 +20,12 @@
 #endif
 
 #include <stdlib.h>
-#ifdef __EXT_QNX
-# undef __EXT_QNX
-#endif
 #include <unistd.h>
 
 #include <mailutils/errno.h>
 #include <mailutils/locker.h>
 #include <mailutils/nls.h>
-
-#include "mailutils/libargp.h"
-
-static char doc[] =
-N_("GNU dotlock -- lock mail spool files.")
-"\v"
-N_("Returns 0 on success, 3 if locking the file fails because\
- it's already locked, and 1 if some other kind of error occurred.");
-
-static char args_doc[] = N_("FILE");
-
-static struct argp_option options[] = {
-  {"unlock", 'u', NULL, 0,
-   N_("unlock"), 0},
-
-  {"force", 'f', N_("MINUTES"), OPTION_ARG_OPTIONAL,
-   N_("forcibly break an existing lock older than a certain time"), 0},
-
-  {"retry", 'r', N_("RETRIES"), OPTION_ARG_OPTIONAL,
-   N_("retry the lock a few times"), 0},
-
-  {"debug", 'd', NULL, 0,
-   N_("print details of failure reasons to stderr"), 0},
-
-  {NULL, 0, NULL, 0, NULL, 0}
-};
-
-static error_t parse_opt (int key, char *arg, struct argp_state *state);
-
-static struct argp argp = {
-  options,
-  parse_opt,
-  args_doc,
-  doc,
-};
+#include "mailutils/cli.h"
 
 static const char *file;
 static int unlock;
@@ -71,55 +34,25 @@ static int retries;
 static time_t force;
 static int debug;
 
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case 'd':
-      mu_argp_node_list_new (lst, "debug", "yes");
-      break;
-
-    case 'u':
-      unlock = 1;
-      break;
-
-    case 'r':
-      if (arg)
-	mu_argp_node_list_new (lst, "retry", arg);
-      break;
-
-    case 'f':
-      mu_argp_node_list_new (lst, "force", arg ? arg : "0");
-      break;
-
-    case ARGP_KEY_ARG:
-      if (file)
-	argp_error (state, _("only one FILE can be specified"));
-      file = arg;
-      break;
-
-    case ARGP_KEY_NO_ARGS:
-      if (!mu_help_config_mode)
-	argp_error (state, _("FILE must be specified"));
-      return ARGP_ERR_UNKNOWN;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+static struct mu_option dotlock_options[] = {
+  { "unlock", 'u', NULL, MU_OPTION_DEFAULT,
+    N_("unlock"),
+    mu_c_bool, &unlock },
+
+  { "force",  'f', N_("MINUTES"), MU_OPTION_ARG_OPTIONAL,
+    N_("forcibly break an existing lock older than a certain time"),
+    mu_c_time, &force },//FIXME: Default value
+ 
+  { "retry",  'r', N_("RETRIES"), MU_OPTION_ARG_OPTIONAL,
+    N_("retry the lock a few times"),
+    mu_c_int, &retries },
+
+  { "debug",  'd', NULL, MU_OPTION_DEFAULT,
+    N_("print details of failure reasons to stderr"), 
+    mu_c_bool, &debug },
+
+  MU_OPTION_END
+}, *options[] = { dotlock_options, NULL };
 
 struct mu_cfg_param dotlock_cfg_param[] = {
   { "force", mu_c_time, &force, 0, NULL,
@@ -130,12 +63,22 @@ struct mu_cfg_param dotlock_cfg_param[] = {
     N_("Print details of failure reasons to stderr.") },
   { NULL }
 };
+
+static struct mu_cli_setup cli = {
+  options,
+  dotlock_cfg_param,
+  N_("GNU dotlock -- lock mail spool files."),
+  //FIXME:
+  /*
+  N_("Returns 0 on success, 3 if locking the file fails because\
+ it's already locked, and 1 if some other kind of error occurred.");
+  */
+  N_("FILE")
+};
 
 
 
-const char *dotlock_capa[] = {
-  "mailutils",
-  "common",
+char *capa[] = {
   "debug",
   NULL
 };
@@ -156,13 +99,24 @@ main (int argc, char *argv[])
   if (setegid (usergid) < 0)
     return MU_DL_EX_ERROR;
 
-  argp_err_exit_status = MU_DL_EX_ERROR;
-  
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, dotlock_capa, dotlock_cfg_param, 
-		   argc, argv, 0, NULL, NULL))
-    exit (1);
+  /* FIXME: Force mu_cli to exit with MU_DL_EX_ERROR on errors? */
+
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
+
+  switch (argc)
+    {
+    case 0:
+      mu_error (_("FILE must be specified"));
+      exit (MU_DL_EX_ERROR);
+
+    case 1:
+      file = argv[0];
+      break;
 
+    default:
+      mu_error (_("only one FILE can be specified"));
+    }
+  
   if (force)
     {
       force *= 60;
diff --git a/frm/Makefile.am b/frm/Makefile.am
index 7861b51..8678e2f 100644
--- a/frm/Makefile.am
+++ b/frm/Makefile.am
@@ -27,7 +27,7 @@ frm_LDADD =  $(common_ldadd)
 from_LDADD = $(common_ldadd)
 
 common_ldadd = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/frm/frm.c b/frm/frm.c
index 4df0d87..99db191 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -29,8 +29,6 @@ static int align = 0;      /* Tidy mode. -t option. */
 #define IS_NEW  0x100
 static int select_attribute;
 
-static char doc[] = N_("GNU frm -- display From: lines.");
-
 static struct attr_tab {
   char *name;      /* Attribute name */
   int code;        /* Corresponding IS_.* flag */
@@ -84,7 +82,7 @@ prepare_attrs (void)
 /* Translates the textual status representation to the corresponding
    IS_.* flag */
 static int
-decode_attr (char *arg)
+decode_attr (char const *arg)
 {
   struct attr_tab *p;
   int len = strlen (arg);
@@ -111,105 +109,82 @@ decode_attr (char *arg)
 }
 
 
+static void
+cli_show_field (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  show_field = mu_strdup (arg);
+  align = 0;
+}
 
-static struct argp_option options[] = {
-  {"debug",  'd', NULL,   0, N_("enable debugging output"), 0},
-  {"field",  'f', N_("NAME"), 0, N_("header field to display"), 0},
-  {"to",     'l', NULL,   0, N_("include the To: information"), 0},
-  {"number", 'n', NULL,   0, N_("display message numbers"), 0},
-  {"Quiet",  'Q', NULL,   0, N_("do not display headers"), 0},
-  {"query",  'q', NULL,   0, N_("print a message if the mailbox contains some unread mail"), 0},
-  {"summary",'S', NULL,   0, N_("print a summary of messages"), 0},
-  {"status", 's', N_("STATUS"), 0,
-   /* TRANSLATORS: Please do *not* translate the words "new", "unread",
-      "old" and "read". They are keywords. */
-   N_("select messages with the specific attribute:"
-      " new, unread, old (same as unread) or read (or any unambiguous"
-      " abbreviation of these)"),
-   0},
-  {"align",  't', NULL,   0, N_("tidy mode: align subject lines"), 0},
-  {0, 0, 0, 0}
-};
+static void
+cli_Quiet (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  be_quiet += 2;
+}
 
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+static void
+cli_query (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case 'd':
-      frm_debug++;
-      break;
-
-    case 'f':
-      show_field = arg;
-      align = 0;
-      break;
-
-    case 'l':
-      show_to = 1;
-      break;
-
-    case 'n':
-      show_number = 1;
-      break;
-
-    case 'Q':
-      /* Very silent.  */
-      be_quiet += 2;
-      break;
-
-    case 'q':
-      be_quiet++;
-      show_query = 1;
-      break;
-
-    case 'S':
-      show_summary = 1;
-      break;
-
-    case 's':
-      select_attribute = decode_attr (arg);
-      break;
-      
-    case 't':
-      align = 1;
-      break;
-
-    case ARGP_KEY_FINI:
-      {
-	size_t s;
-	if (align && (s = util_getcols ()))
-	  init_output (s);
-	else
-	  init_output (0);
-      }
-      break;
-      
-    default: 
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+  be_quiet++;
+  show_query = 1;
+}
+
+static void
+cli_status (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  select_attribute = decode_attr (arg);
 }
 
-static struct argp argp = {
+static struct mu_option frm_options[] = {
+  { "debug",  'd', NULL,   MU_OPTION_DEFAULT,
+    N_("enable debugging output"),
+    mu_c_incr, &frm_debug },
+  { "field",  'f', N_("NAME"), MU_OPTION_DEFAULT,
+    N_("header field to display"),
+    mu_c_string, &show_field, cli_show_field },
+  { "to",     'l', NULL,   MU_OPTION_DEFAULT,
+    N_("include the To: information"),
+    mu_c_bool, &show_to },
+  { "number", 'n', NULL,   MU_OPTION_DEFAULT,
+    N_("display message numbers"),
+    mu_c_bool, &show_number },
+  { "Quiet",  'Q', NULL,   MU_OPTION_DEFAULT,
+    N_("do not display headers"),
+    mu_c_int, &be_quiet, cli_Quiet },
+  { "query",  'q', NULL,   MU_OPTION_DEFAULT,
+    N_("print a message if the mailbox contains some unread mail"),
+    mu_c_int, &be_quiet, cli_query },
+  { "summary",'S', NULL,   MU_OPTION_DEFAULT,
+    N_("print a summary of messages"), 
+    mu_c_bool, &show_summary },
+  { "status", 's', N_("STATUS"), 0,
+    /* TRANSLATORS: Please do *not* translate the words "new", "unread",
+       "old" and "read". They are keywords. */
+    N_("select messages with the specific attribute:"
+       " new, unread, old (same as unread) or read (or any unambiguous"
+       " abbreviation of these)"),
+    mu_c_string, NULL, cli_status},
+  { "align",  't', NULL,   MU_OPTION_DEFAULT,
+    N_("tidy mode: align subject lines"),
+    mu_c_bool, &align },
+  MU_OPTION_END
+}, *options[] = { frm_options, NULL };
+
+static struct mu_cli_setup cli = {
   options,
-  parse_opt,
-  N_("[URL ...]"),
-  doc,
   NULL,
-  NULL, NULL
+  N_("GNU frm -- display From: lines."),
+  N_("[URL ...]"),
 };
 
-static const char *frm_argp_capa[] = {
-  "mailutils",
-  "common",
+static char *frm_argp_capa[] = {
   "debug",
   "mailbox",
   "locking",
+  "tls",
   NULL
 };
-
-
+
 static struct
 {
   size_t new;
@@ -342,8 +317,8 @@ frm (char *mailbox_name)
 int
 main (int argc, char **argv)
 {
-  int c;
   int status = 0;
+  size_t s;
 
   /* Native Language Support */
   MU_APP_INIT_NLS ();
@@ -352,25 +327,30 @@ main (int argc, char **argv)
   
   /* register the formats.  */
   mu_register_all_mbox_formats ();
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, frm_argp_capa, NULL, argc, argv, 0, &c, NULL))
-    exit (1);
 
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
+
+  if (align && (s = util_getcols ()))
+    init_output (s);
+  else
+    init_output (0);
+  
   /* have an argument */
-  if (c == argc)
+  if (argc == 0)
     status = frm (NULL);
-  else if (c + 1 == argc)
-    status = frm (argv[c]);
+  else if (argc == 1)
+    status = frm (argv[0]);
   else
-    for (; c < argc; c++)
-      {
-	mu_printf ("%s:\n", argv[c]);
-	status = frm (argv[c]);
-      }
-
+    {
+      int i;
+      
+      for (i = 0; i < argc; i++)
+	{
+	  mu_printf ("%s:\n", argv[i]);
+	  status = frm (argv[i]);
+	}
+    }
+  
   return status;
 }
diff --git a/frm/frm.h b/frm/frm.h
index 44e2652..60b10a0 100644
--- a/frm/frm.h
+++ b/frm/frm.h
@@ -64,7 +64,7 @@
 #include <mailutils/util.h>
 #include <mailutils/mime.h>
 
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 
 typedef int (*frm_select_t) (size_t index, mu_message_t msg);
 
diff --git a/frm/from.c b/frm/from.c
index 270221f..7995bb4 100644
--- a/frm/from.c
+++ b/frm/from.c
@@ -21,58 +21,34 @@ int count_only;
 char *sender_option;
 char *mailbox_name;
 
-static char doc[] = N_("GNU from -- display from and subject.");
-
-static struct argp_option options[] = {
-  {"count",  'c', NULL,   0, N_("just print a count of messages and exit")},
-  {"sender", 's', N_("ADDRESS"), 0,
-   N_("print only mail from addresses containing the supplied string") },
-  {"file",   'f', N_("FILE"), 0,
-   N_("read mail from FILE") },
-  {"debug",  'd', NULL,   0, N_("enable debugging output"), 0},
-  {0, 0, 0, 0}
-};
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case 'c':
-      count_only = 1;
-      break;
-      
-    case 's':
-      sender_option = arg;
-      break;
-      
-    case 'f':
-      mailbox_name = arg;
-      break;
-      
-    case 'd':
-      frm_debug++;
-      break;
-
-    default: 
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp argp = {
+static struct mu_option from_options[] = {
+  { "count",  'c', NULL,   MU_OPTION_DEFAULT,
+    N_("just print a count of messages and exit"),
+    mu_c_bool, &count_only },
+  { "sender", 's', N_("ADDRESS"), MU_OPTION_DEFAULT,
+    N_("print only mail from addresses containing the supplied string"),
+    mu_c_string, &sender_option },
+  { "file",   'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read mail from FILE"), 
+    mu_c_string, &mailbox_name },
+  { "debug",  'd', NULL,   MU_OPTION_DEFAULT,
+    N_("enable debugging output"),
+    mu_c_incr, &frm_debug },
+  MU_OPTION_END
+}, *options[] = { from_options, NULL };
+
+static struct mu_cli_setup cli = {
   options,
-  parse_opt,
+  NULL,
+  N_("GNU from -- display from and subject."),
   N_("[OPTIONS] [USER]"),
-  doc,
 };
 
-static const char *capa[] = {
-  "mailutils",
-  "common",
+static char *capa[] = {
   "debug",
   "mailbox",
   "locking",
+  "tls",
   NULL
 };
 
@@ -105,7 +81,6 @@ from_select (size_t index, mu_message_t msg)
 int
 main (int argc, char **argv)
 {
-  int c;
   size_t total;
   
   /* Native Language Support */
@@ -113,20 +88,16 @@ main (int argc, char **argv)
 
   /* register the formats.  */
   mu_register_all_mbox_formats ();
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
 
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &c, NULL))
-    exit (1);
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
-  if (argc - c > 1)
+  if (argc > 1)
     {
       mu_error (_("too many arguments"));
       exit (1);
     }
-  else if (argc - c > 0)
+  else if (argc > 0)
     {
       if (mailbox_name)
 	{
@@ -134,9 +105,9 @@ main (int argc, char **argv)
 	  exit (1);
 	}
 
-      mailbox_name = mu_alloc (strlen (argv[c]) + 2);
+      mailbox_name = mu_alloc (strlen (argv[0]) + 2);
       mailbox_name[0] = '%';
-      strcpy (mailbox_name + 1, argv[c]);
+      strcpy (mailbox_name + 1, argv[0]);
     }
 
   init_output (0);
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index ba87486..9ae3929 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -36,6 +36,7 @@ pkginclude_HEADERS = \
  cctype.h\
  cfg.h\
  cidr.h\
+ cli.h\
  cstr.h\
  datetime.h\
  daemon.h\
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index 7ea8e08..e9f3587 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -79,6 +79,8 @@ struct mu_cfg_parse_hints
   char *site_rcfile;
   char *custom_rcfile;
   char *program;
+  struct mu_cfg_tree *append_tree;
+  void *data;
 };
 
 struct mu_cfg_tree
@@ -238,7 +240,8 @@ int mu_config_register_plain_section (const char *parent_path,
 #define MU_CFG_FMT_LOCUS           0x080
 #define MU_CFG_FMT_VALUE_ONLY      0x100
 #define MU_CFG_FMT_PARAM_PATH      0x200
-
+#define MU_PARSE_CONFIG_LINT       0x400
+  
 #ifdef MU_CFG_COMPATIBILITY
 # define MU_CFG_DEPRECATED
 #else
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
new file mode 100644
index 0000000..2943bc4
--- /dev/null
+++ b/include/mailutils/cli.h
@@ -0,0 +1,55 @@
+/* opt.h -- general-purpose command line option parser 
+   Copyright (C) 2016 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/>.
+*/
+
+#ifndef _MAILUTILS_CLI_H
+#define _MAILUTILS_CLI_H
+#include <stdio.h>
+#include <mailutils/types.h>
+#include <mailutils/cfg.h>
+#include <mailutils/opt.h>
+
+typedef void (*mu_cli_capa_commit_fp) (void *);
+
+struct mu_cli_capa
+{
+  char *name;
+  struct mu_option *opt;
+  struct mu_cfg_param *cfg;
+  mu_cfg_section_fp parser;
+  mu_cli_capa_commit_fp commit;
+};
+
+void mu_cli_capa_init (void);
+void mu_cli_capa_register (struct mu_cli_capa *capa);
+void mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits);
+
+struct mu_cli_setup
+{
+  struct mu_option **optv;
+  struct mu_cfg_param *cfg;
+  char *prog_doc;
+  char *prog_args;
+};
+
+void mu_version_func (struct mu_parseopt *po, FILE *stream);
+void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
+	     char **capa, void *data,
+	     int *ret_argc, char ***ret_argv);
+
+char *mu_site_config_file (void);
+
+#endif
diff --git a/include/mailutils/diag.h b/include/mailutils/diag.h
index 3e2bc51..0a5ebd2 100644
--- a/include/mailutils/diag.h
+++ b/include/mailutils/diag.h
@@ -29,8 +29,8 @@
 extern "C" {
 #endif
 
-extern const char *mu_program_name;
-extern const char *mu_full_program_name;
+extern char *mu_program_name;
+extern char *mu_full_program_name;
 
 #define MU_DIAG_EMERG    MU_LOG_EMERG
 #define MU_DIAG_ALERT    MU_LOG_ALERT
diff --git a/include/mailutils/locker.h b/include/mailutils/locker.h
index b8c4a93..718338f 100644
--- a/include/mailutils/locker.h
+++ b/include/mailutils/locker.h
@@ -103,7 +103,7 @@ extern int mu_locker_set_default_flags (int flags, enum mu_locker_set_mode mode)
 extern void mu_locker_set_default_retry_timeout (time_t to);
 extern void mu_locker_set_default_retry_count (size_t n);
 extern void mu_locker_set_default_expire_timeout (time_t t);
-extern int mu_locker_set_default_external_program (char *path);
+extern int mu_locker_set_default_external_program (char const *path);
 
 /* A flags of 0 means that the default will be used. */
 extern int mu_locker_create (mu_locker_t *, const char *filename, int flags);
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 8e3b03b..cc56342 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -23,10 +23,10 @@
 #include <mailutils/util.h>
 #include <mailutils/cctype.h>
 
-extern char *mu_progname;
-extern char *mu_absprogname;
+extern char *mu_program_name;
+extern char *mu_full_program_name;
 
-void mu_set_progname (char const *arg);
+void mu_set_program_name (char const *arg);
 
 #define MU_OPTION_DEFAULT        0
 #define MU_OPTION_ARG_OPTIONAL   0x01
@@ -118,7 +118,7 @@ struct mu_parseopt
   struct mu_option **po_optv;      /* Array of ptrs to option structures */ 
   int po_flags;                        
 
-  char *po_data;                   /* Call-specific data */
+  void *po_data;                   /* Call-specific data */
 
   int po_exit_error;               /* Exit on error with this code */
   
@@ -130,9 +130,10 @@ struct mu_parseopt
   char const *po_package_name;
   char const *po_package_url;
   char const *po_extra_info;
-  
-  void (*po_help_hook) (FILE *stream); /* FIXME: should take mu_stream_t ?*/
-  void (*po_version_hook) (FILE *stream);
+
+  /* FIXME: should these take mu_stream_t ?*/
+  void (*po_help_hook) (struct mu_parseopt *po, FILE *stream); 
+  void (*po_version_hook) (struct mu_parseopt *po, FILE *stream);
   
   /* Output data */
   int po_ind;                      /* Index of the next option */
@@ -162,6 +163,7 @@ struct mu_parseopt
 int mu_parseopt (struct mu_parseopt *p,
 		 int argc, char **argv, struct mu_option **optv,
 		 int flags);
+void mu_parseopt_error (struct mu_parseopt *po, char const *fmt, ...);
 
 int mu_parseopt_apply (struct mu_parseopt *p);
 void mu_parseopt_free (struct mu_parseopt *p);
diff --git a/include/mailutils/sieve.h b/include/mailutils/sieve.h
index 7123095..1ba1a72 100644
--- a/include/mailutils/sieve.h
+++ b/include/mailutils/sieve.h
@@ -22,6 +22,7 @@
 #include <sys/types.h>
 #include <stdarg.h>
 #include <mailutils/mailutils.h>
+#include <mailutils/cli.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -282,6 +283,8 @@ struct mu_gocs_sieve
 
 int mu_sieve_module_init (enum mu_gocs_op, void *);
 
+extern struct mu_cli_capa mu_cli_capa_sieve;
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/stdstream.h b/include/mailutils/stdstream.h
index ac35ff7..9771881 100644
--- a/include/mailutils/stdstream.h
+++ b/include/mailutils/stdstream.h
@@ -28,7 +28,7 @@ extern mu_stream_t mu_strin;
 extern mu_stream_t mu_strout;
 extern mu_stream_t mu_strerr;
 
-extern const char *mu_program_name;
+extern char *mu_program_name;
   
 #define MU_STRERR_STDERR  0
 #define MU_STRERR_SYSLOG  1
diff --git a/include/mailutils/tls.h b/include/mailutils/tls.h
index 08e00e9..db6e420 100644
--- a/include/mailutils/tls.h
+++ b/include/mailutils/tls.h
@@ -20,6 +20,7 @@
 #define _MAILUTILS_TLS_H
 
 #include <mailutils/types.h>
+#include <mailutils/cli.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -55,6 +56,8 @@ extern int mu_init_tls_libs (int x509);
 extern void mu_deinit_tls_libs (void);
 
 extern int mu_tls_enable;
+
+extern struct mu_cli_capa mu_cli_capa_tls;
   
 #ifdef __cplusplus
 }
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index 7a5270c..82550c2 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -17,7 +17,7 @@
 # <http://www.gnu.org/licenses/>.
 
 SUBDIRS = \
- auth base address list sockaddr cidr cfg diag\
+ auth base address list sockaddr cidr cfg cli diag\
  filter mailbox mailer mime msgset opt server string stream stdstream\
  property url imapio datetime . tests 
 
@@ -33,6 +33,7 @@ libmailutils_la_LIBADD = \
  sockaddr/libsockaddr.la\
  cidr/libcidr.la\
  cfg/libcfg.la\
+ cli/libcli.la\
  datetime/libdatetime.la\
  diag/libdiag.la\
  filter/libfilter.la\
diff --git a/libmailutils/base/locker.c b/libmailutils/base/locker.c
index b4663b9..c4fe993 100644
--- a/libmailutils/base/locker.c
+++ b/libmailutils/base/locker.c
@@ -242,7 +242,7 @@ mu_locker_set_default_expire_timeout (time_t t)
 }
 
 int
-mu_locker_set_default_external_program (char *path)
+mu_locker_set_default_external_program (char const *path)
 {
   char *p = strdup (path);
   if (!p)
diff --git a/libmailutils/cfg/driver.c b/libmailutils/cfg/driver.c
index c0cd2d5..f2a43a3 100644
--- a/libmailutils/cfg/driver.c
+++ b/libmailutils/cfg/driver.c
@@ -463,7 +463,7 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree,
 		    void *target_ptr)
 {
   int rc = 0;
-
+  struct mu_cfg_cont *cont;
   if (!parse_tree)
     return 0;
   if (hints && (hints->flags & MU_PARSE_CONFIG_DUMP))
@@ -477,13 +477,9 @@ mu_cfg_tree_reduce (mu_cfg_tree_t *parse_tree,
       mu_stream_destroy (&stream);
     }
 
-  if (root_container)
-    {
-      struct mu_cfg_cont *cont = mu_build_container (progparam);
-      rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr,
-			     NULL);
-      mu_config_destroy_container (&cont);
-    }
+  cont = mu_build_container (progparam);
+  rc = mu_cfg_scan_tree (parse_tree, &cont->v.section, target_ptr, NULL);
+  mu_config_destroy_container (&cont);
 
   return rc;
 }
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
index 40598a1..b6c49ec 100644
--- a/libmailutils/cfg/lexer.l
+++ b/libmailutils/cfg/lexer.l
@@ -330,10 +330,16 @@ mu_cfg_parse_file (mu_cfg_tree_t **return_tree, const char *file, int flags)
   int rc;
   char *full_name = mu_tilde_expansion (file, MU_HIERARCHY_DELIMITER, NULL);
 
+  if (flags & MU_PARSE_CONFIG_VERBOSE)
+    mu_diag_output (MU_DIAG_INFO, _("opening configuration file %s"),
+		    full_name);
   if (stat (full_name, &st))
     {
       if (errno != ENOENT)
 	mu_error (_("cannot stat `%s': %s"), full_name, mu_strerror (errno));
+      else if (flags & MU_PARSE_CONFIG_VERBOSE)
+	mu_diag_output (MU_DIAG_INFO, _("configuration file %s doesn't exist"),
+			full_name);
       free (full_name);
       return ENOENT;
     }
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index e36b513..043f7e0 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -1589,7 +1589,10 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
 	  mu_cfg_tree_union (&tree, &tmp);
 	}
     }
-  
+
+  if (hints->append_tree)
+    mu_cfg_tree_union (&tree, &hints->append_tree);
+
   *ptree = tree;
   return rc;
 }
diff --git a/libmailutils/opt/Makefile.am b/libmailutils/cli/Makefile.am
similarity index 91%
copy from libmailutils/opt/Makefile.am
copy to libmailutils/cli/Makefile.am
index d229c45..48770e8 100644
--- a/libmailutils/opt/Makefile.am
+++ b/libmailutils/cli/Makefile.am
@@ -15,12 +15,12 @@
 # Public License along with this library.  If not, see
 # <http://www.gnu.org/licenses/>.
 
-noinst_LTLIBRARIES = libopt.la
+noinst_LTLIBRARIES = libcli.la
 
-libopt_la_SOURCES = \
- opt.c\
- help.c\
- progname.c
+libcli_la_SOURCES = \
+ capa.c\
+ cli.c\
+ stdcapa.c
 
 AM_CPPFLAGS = \
   @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/cli/capa.c b/libmailutils/cli/capa.c
new file mode 100644
index 0000000..bd5c557
--- /dev/null
+++ b/libmailutils/cli/capa.c
@@ -0,0 +1,96 @@
+/* capa.c -- CLI capabilities for GNU Mailutils
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/cli.h>
+#include <mailutils/list.h>
+#include <mailutils/alloc.h>
+#include <mailutils/nls.h>
+
+static mu_list_t capa_list;
+
+static void
+capa_free (void *ptr)
+{
+  struct mu_cli_capa *cp = ptr;
+  free (cp->name);
+  free (cp);
+}   
+
+void
+mu_cli_capa_register (struct mu_cli_capa *capa)
+{
+  struct mu_cli_capa *cp = mu_alloc (sizeof (*cp));
+  cp->name = mu_strdup (capa->name);
+  cp->opt = capa->opt;
+  cp->cfg = capa->cfg;
+  cp->parser = capa->parser;
+  cp->commit = capa->commit;
+  if (!capa_list)
+    {
+      mu_list_create (&capa_list);
+      mu_list_set_destroy_item (capa_list, capa_free);
+    }
+  mu_list_append (capa_list, cp);
+}
+
+struct capa_apply
+{
+  char const *name;
+  mu_list_t opts;
+  mu_list_t commits;
+  int found;
+};
+
+static int
+capa_apply (void *item, void *data)
+{
+  struct mu_cli_capa *cp = item;
+  struct capa_apply *ap = data;
+
+  if (strcmp (cp->name, ap->name) == 0)
+    {
+      ap->found = 1;
+      if (cp->opt)
+        mu_list_append (ap->opts, cp->opt);
+      if (cp->commit)
+        mu_list_append (ap->commits, cp->commit);
+      if (cp->parser || cp->cfg)
+        mu_config_root_register_section (NULL, cp->name, NULL,
+				         cp->parser, cp->cfg);
+    }
+  return 0;
+}
+
+void
+mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits)
+{
+  struct capa_apply app;
+  app.name = name;
+  app.opts = opts;
+  app.commits = commits;
+  app.found = 0;
+  mu_list_foreach (capa_list, capa_apply, &app);
+  if (!app.found)
+    mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
+	      __FILE__, __LINE__, name);
+}
+
+    
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
new file mode 100644
index 0000000..597ac91
--- /dev/null
+++ b/libmailutils/cli/cli.c
@@ -0,0 +1,420 @@
+/* cli.c -- Command line interface for GNU Mailutils
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <sysexits.h>
+#include <mailutils/cfg.h>
+#include <mailutils/opt.h>
+#include <mailutils/cli.h>
+#include <mailutils/list.h>
+#include <mailutils/alloc.h>
+#include <mailutils/nls.h>
+#include <mailutils/errno.h>
+#include <mailutils/version.h>
+#include <mailutils/stream.h>
+#include <mailutils/stdstream.h>
+#include <mailutils/io.h>
+#include <mailutils/syslog.h>
+
+#ifndef MU_SITE_CONFIG_FILE
+# define MU_SITE_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
+#endif
+
+char *
+mu_site_config_file (void)
+{
+  char *p = getenv ("MU_SITE_CONFIG_FILE");
+  if (p)
+    return p;
+  return MU_SITE_CONFIG_FILE;
+}
+
+
+const char mu_version_copyright[] =
+  /* Do *not* mark this string for translation.  %s is a copyright
+     symbol suitable for this locale, and %d is the copyright
+     year.  */
+  "Copyright %s 2007-2016 Free Software Foundation, inc.";
+
+void
+mu_version_func (struct mu_parseopt *po, FILE *stream)
+{
+#ifdef GIT_DESCRIBE
+  fprintf (stream, "%s (%s) %s [%s]\n",
+	   mu_program_name, PACKAGE_NAME, PACKAGE_VERSION, GIT_DESCRIBE);
+#else
+  fprintf (stream, "%s (%s) %s\n", mu_program_name,
+	   PACKAGE_NAME, PACKAGE_VERSION);
+#endif
+  /* TRANSLATORS: Translate "(C)" to the copyright symbol
+     (C-in-a-circle), if this symbol is available in the user's
+     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
+  fprintf (stream, mu_version_copyright, _("(C)"));
+  fputs (_("\
+\n\
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\n\
+\n\
+"),
+	 stream);
+}
+
+static char gnu_general_help_url[] =
+  N_("General help using GNU software: <http://www.gnu.org/gethelp/>");
+
+
+static void
+change_progname (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  po->po_prog_name = mu_strdup (arg);
+}
+
+static void
+no_user_config (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  hints->flags &= ~MU_CFG_PARSE_PROGRAM;
+}
+
+static void
+no_site_config (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  hints->flags &= ~MU_CFG_PARSE_SITE_RCFILE;
+}
+
+static void
+config_file (struct mu_parseopt *po, struct mu_option *opt,
+	     char const *arg)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  hints->flags |= MU_CFG_PARSE_CUSTOM_RCFILE;
+  hints->custom_rcfile = mu_strdup (arg);
+}
+
+static void
+config_verbose (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  if (hints->flags & MU_PARSE_CONFIG_VERBOSE)
+    hints->flags |= MU_PARSE_CONFIG_DUMP;
+  else
+    hints->flags |= MU_PARSE_CONFIG_VERBOSE;
+}
+
+static void
+config_lint (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  hints->flags |= MU_PARSE_CONFIG_VERBOSE|MU_PARSE_CONFIG_LINT;
+}
+
+static void
+param_set (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  mu_cfg_node_t *node;
+  int rc = mu_cfg_create_subtree (arg, &node);
+  if (rc)
+    mu_parseopt_error (po, "%s: cannot create node: %s",
+		       arg, mu_strerror (rc));
+  if (!hints->append_tree)
+    mu_cfg_tree_create (&hints->append_tree);
+  mu_cfg_tree_add_node (hints->append_tree, node);
+}
+
+struct mu_option mu_common_options[] = {
+  MU_OPTION_GROUP(N_("Common options")),
+  { "program-name",   0,  N_("NAME"),  MU_OPTION_IMMEDIATE|MU_OPTION_HIDDEN,
+    N_("set program name"),
+    mu_c_string, NULL, change_progname },
+
+  { "no-user-config", 0,  NULL,        MU_OPTION_IMMEDIATE,
+    N_("do not load user configuration file"),
+    mu_c_string, NULL, no_user_config },
+  { "no-user-rcfile", 0,  NULL,        MU_OPTION_ALIAS },
+  
+  { "no-site-config", 0,  NULL,        MU_OPTION_IMMEDIATE,
+    N_("do not load user configuration file"),
+    mu_c_string, NULL, no_site_config },
+  { "no-site-rcfile", 0,  NULL,        MU_OPTION_ALIAS },
+  
+  { "config-file",    0,  N_("FILE"),  MU_OPTION_IMMEDIATE,
+    N_("load this configuration file"),
+    mu_c_string, NULL, config_file },
+  { "rcfile",         0,  NULL,        MU_OPTION_ALIAS },
+  
+  { "config-verbose", 0,  NULL,        MU_OPTION_IMMEDIATE,
+    N_("verbosely log parsing of the configuration files"),
+    mu_c_string, NULL, config_verbose },
+  { "rcfile-verbose", 0,  NULL,        MU_OPTION_ALIAS },
+  
+  { "config-lint",    0,  NULL,        MU_OPTION_IMMEDIATE,
+    N_("check configuration file syntax and exit"),
+    mu_c_string, NULL, config_lint },
+  { "rcfile-lint",    0,  NULL,        MU_OPTION_ALIAS },
+
+  { "set",            0,  N_("PARAM=VALUE"), MU_OPTION_IMMEDIATE,
+    N_("set configuration parameter"),
+    mu_c_string, NULL, param_set },
+  
+  MU_OPTION_END
+};
+
+static void
+show_comp_defaults (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *unused)
+{
+  mu_print_options ();
+  exit (0);
+}
+
+static void
+show_config_help (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *unused)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+
+  char *comment;
+  mu_stream_t stream;
+  struct mu_cfg_cont *cont;
+  static struct mu_cfg_param dummy_include_param[] = {
+    { "include", mu_c_string, NULL, 0, NULL,
+      N_("Include contents of the given file.  If a directory is given, "
+	 "include contents of the file <file>/<program>, where "
+	 "<program> is the name of the program.  This latter form is "
+	 "allowed only in the site-wide configuration file."),
+      N_("file-or-directory") },
+    { NULL }
+  };
+
+  mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0);
+
+  mu_asprintf (&comment,
+	       "Configuration file structure for %s utility.",
+	       po->po_prog_name);
+  mu_cfg_format_docstring (stream, comment, 0);
+  free (comment);
+  
+  mu_asprintf (&comment,
+	       "For use in global configuration file (%s), enclose it "
+	       "in `program %s { ... };",
+	       mu_site_config_file (),
+	       po->po_prog_name);		   
+  mu_cfg_format_docstring (stream, comment, 0);
+  free (comment);
+
+  /* FIXME: %s should be replaced by the canonical utility name */
+  mu_asprintf (&comment, "For more information, use `info %s'.",
+	       po->po_prog_name);
+  mu_cfg_format_docstring (stream, comment, 0);
+  free (comment);
+
+  cont = mu_config_clone_root_container ();
+  mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
+					dummy_include_param, NULL);
+  if (hints->data)
+    mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
+					  hints->data, NULL);
+  mu_cfg_format_container (stream, cont);
+  mu_config_destroy_container (&cont);
+      
+  mu_stream_destroy (&stream);
+  exit (0);
+}  
+
+struct mu_option mu_extra_help_options[] = {
+  MU_OPTION_GROUP (N_("Informational options")),
+  { "show-config-options",   0,  NULL,  MU_OPTION_IMMEDIATE,
+    N_("show compilation options"),
+    mu_c_string, NULL, show_comp_defaults },
+  { "config-help",           0,  NULL,  MU_OPTION_IMMEDIATE,
+    N_("show configuration file summary"),
+    mu_c_string, NULL, show_config_help },
+  MU_OPTION_END
+};
+
+
+static int
+add_opt_group (void *item, void *data)
+{
+  struct mu_parseopt *po = data;
+  struct mu_option *opt = item;
+  po->po_optv[po->po_optc++] = opt;
+  return 0;
+}
+
+/* Build the list of option groups and configuration sections */
+static struct mu_option **
+init_options (char **capa, struct mu_cli_setup *setup,
+	      mu_list_t *ret_comlist)
+{
+  size_t i, s;
+  mu_list_t oplist;
+  struct mu_parseopt po;
+  
+  mu_list_create (&oplist);
+  if (setup->optv)
+    {
+      for (i = 0; setup->optv[i]; i++)
+	mu_list_append (oplist, setup->optv[i]);
+    }
+  if (capa)
+    {
+      mu_list_t comlist;
+      mu_list_create (&comlist);
+      for (i = 0; capa[i]; i++)
+	mu_cli_capa_apply (capa[i], oplist, comlist);
+      *ret_comlist = comlist;
+    }
+  else
+    *ret_comlist = NULL;
+  
+  mu_list_append (oplist, mu_common_options);
+  mu_list_append (oplist, mu_extra_help_options);
+  
+  mu_list_count (oplist, &s);
+
+  po.po_optv = mu_calloc (s + 1, sizeof (po.po_optv[0]));
+  po.po_optc = 0;
+  mu_list_foreach (oplist, add_opt_group, &po);
+  if (po.po_optc != s)
+    abort ();
+  po.po_optv[po.po_optc] = NULL;
+  mu_list_destroy (&oplist);
+  return po.po_optv;
+}
+
+static int
+run_commit (void *item, void *data)
+{
+  mu_cli_capa_commit_fp commit = item;
+  commit (data);
+  return 0;
+}
+  
+void
+mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
+	void *data,
+	int *ret_argc, char ***ret_argv)
+{
+  struct mu_parseopt po;
+  int flags = 0;
+  struct mu_cfg_tree *parse_tree = NULL;
+  struct mu_cfg_parse_hints hints;
+  struct mu_option **optv;
+  mu_list_t com_list;
+  
+  /* Set program name */
+  mu_set_program_name (argv[0]);
+
+  if (!mu_log_tag)
+    mu_log_tag = (char*)mu_program_name;
+
+  /* Initialize standard streams */
+  mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
+
+  /* Initialize standard capabilities */
+  mu_cli_capa_init ();
+  
+  /* Initialize hints */
+  memset (&hints, 0, sizeof (hints));
+  hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
+  hints.site_rcfile = mu_site_config_file ();
+
+  hints.flags |= MU_CFG_PARSE_PROGRAM;
+  hints.program = (char*) mu_program_name;
+
+  hints.data = setup->cfg;
+  
+  /* Initialize po */
+  if (setup->prog_doc)
+    {
+      po.po_prog_doc = setup->prog_doc;
+      flags |= MU_PARSEOPT_PROG_DOC;
+    }
+
+  if (setup->prog_args)
+    {
+      po.po_prog_args = setup->prog_args;
+      flags |= MU_PARSEOPT_PROG_ARGS;
+    }
+  
+  po.po_package_name = PACKAGE_NAME;
+  flags |= MU_PARSEOPT_PACKAGE_NAME;
+
+  po.po_package_url = PACKAGE_URL;
+  flags |= MU_PARSEOPT_PACKAGE_URL;
+
+  po.po_bug_address = PACKAGE_BUGREPORT;
+  flags |= MU_PARSEOPT_BUG_ADDRESS;
+
+  po.po_extra_info = gnu_general_help_url;
+  flags |= MU_PARSEOPT_EXTRA_INFO;
+
+  po.po_version_hook = mu_version_func;
+  flags |= MU_PARSEOPT_VERSION_HOOK;
+
+  po.po_data = &hints;
+  flags |= MU_PARSEOPT_DATA;
+
+  po.po_exit_error = EX_USAGE;
+
+  optv = init_options (capa, setup, &com_list);
+
+  if (mu_parseopt (&po, argc, argv, optv, flags))
+    exit (po.po_exit_error);
+
+  argc -= po.po_arg_start;
+  argv += po.po_arg_start;
+  
+  if (ret_argc)
+    {
+      *ret_argc = argc;
+      *ret_argv = argv;
+    }
+  else if (argc)
+    mu_parseopt_error (&po, "%s", _("unexpected arguments"));
+
+  if (mu_cfg_parse_config (&parse_tree, &hints))
+    exit (EX_CONFIG);
+
+  if (mu_cfg_tree_reduce (parse_tree, &hints, setup->cfg, data))
+    exit (EX_CONFIG);
+
+  if (mu_cfg_error_count) //FIXME
+    exit (EX_CONFIG);
+  
+  mu_parseopt_apply (&po);
+
+  mu_list_foreach (com_list, run_commit, NULL);
+  mu_list_destroy (&com_list);
+  
+  if (hints.flags & MU_PARSE_CONFIG_LINT)
+    exit (0);
+
+  mu_cfg_destroy_tree (&parse_tree);
+  free (optv);
+  mu_parseopt_free (&po);  
+}
diff --git a/libmailutils/cli/stdcapa.c b/libmailutils/cli/stdcapa.c
new file mode 100644
index 0000000..05a761f
--- /dev/null
+++ b/libmailutils/cli/stdcapa.c
@@ -0,0 +1,568 @@
+/* stdcapa.c -- Standard CLI capabilities for GNU Mailutils
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 3, or (at
+   your option) any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <mailutils/cli.h>
+#include <mailutils/cfg.h>
+#include <mailutils/nls.h>
+#include <mailutils/syslog.h>
+#include <mailutils/stdstream.h>
+#include <mailutils/mailer.h>
+#include <mailutils/errno.h>
+#include <mailutils/mailbox.h>
+#include <mailutils/registrar.h>
+#include <mailutils/locker.h>
+#include <mailutils/mu_auth.h>
+
+/* ************************************************************************* 
+ * Logging section
+ * ************************************************************************* */
+static void
+cli_log_facility (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  if (mu_string_to_syslog_facility (arg, &mu_log_facility))
+    mu_parseopt_error (po, _("unknown syslog facility `%s'"), arg);
+}
+  
+static int
+cb_facility (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  
+  if (mu_string_to_syslog_facility (val->v.string, &mu_log_facility))
+    {
+      mu_error (_("unknown syslog facility `%s'"), val->v.string);
+      return 1;
+    }
+   return 0;
+}
+
+static int
+cb_severity (void *data, mu_config_value_t *val)
+{
+  unsigned n;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  if (mu_severity_from_string (val->v.string, &n))
+    {
+      mu_error (_("unknown severity `%s'"), val->v.string);
+      return 1;
+    }
+  mu_log_severity_threshold = n;
+  return 0;
+}      
+
+static struct mu_cfg_param logging_cfg[] = {
+  { "syslog", mu_c_bool, &mu_log_syslog, 0, NULL,
+    N_("Send diagnostics to syslog.") },
+  { "print-severity", mu_c_bool, &mu_log_print_severity, 0, NULL,
+    N_("Print message severity levels.") },
+  { "severity", mu_cfg_callback, NULL, 0, cb_severity,
+    N_("Output only messages with a severity equal to or greater than "
+       "this one."),
+    N_("arg: string")},
+  { "facility", mu_cfg_callback, NULL, 0, cb_facility,
+    N_("Set syslog facility. Arg is one of the following: user, daemon, "
+       "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
+       "or a facility number."), 
+    N_("arg: string") },
+  { "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
+    N_("Log session ID") },
+  { "tag", mu_c_string, &mu_log_tag, 0, NULL,
+    N_("Tag syslog messages with this string.") },
+  { NULL }
+};
+
+static struct mu_option logging_option[] = {
+  { "log-facility", 0, N_("FACILITY"), MU_OPTION_DEFAULT,
+    N_("output logs to syslog FACILITY"),
+    mu_c_int, &mu_log_facility, cli_log_facility },
+  MU_OPTION_END
+};
+
+static void
+logging_commit (void *unused)
+{
+  if (mu_log_syslog >= 0)
+    mu_stdstream_strerr_setup (mu_log_syslog ?
+			       MU_STRERR_SYSLOG : MU_STRERR_STDERR);
+}
+
+/* ************************************************************************* 
+ * Mailer                                                                    
+ * ************************************************************************* */
+static void
+cli_mailer (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  int rc = mu_mailer_set_url_default (arg);
+  if (rc != 0)
+    mu_parseopt_error (po, _("invalid mailer URL `%s': %s"),
+		       arg, mu_strerror (rc));
+}
+
+static struct mu_option mailer_option[] = {
+  { "mailer", 'M', N_("MAILER"), MU_OPTION_DEFAULT,
+    N_("use specified URL as the default mailer"),
+    mu_c_string, NULL, cli_mailer },
+  MU_OPTION_END
+};
+
+static int
+cb_mailer (void *data, mu_config_value_t *val)
+{
+  int rc;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  rc = mu_mailer_set_url_default (val->v.string);
+  if (rc != 0)
+    mu_error (_("%s: invalid mailer URL: %s"),
+		val->v.string, mu_strerror (rc));
+  return rc;
+}
+
+static struct mu_cfg_param mailer_cfg[] = {
+  { "url", mu_cfg_callback, NULL, 0, cb_mailer,
+    N_("Use this URL as the default mailer"),
+    N_("url: string") },
+  { NULL }
+};
+
+/* ************************************************************************* 
+ * Debugging
+ * ************************************************************************* */
+static void
+cli_debug_level (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  mu_debug_clear_all ();
+  mu_debug_parse_spec (arg);
+  /* FIXME: Error handling */
+}
+
+static struct mu_option debug_option[] = {
+  MU_OPTION_GROUP (N_("Global debugging settings")),
+  { "debug-level", 0, N_("LEVEL"), MU_OPTION_DEFAULT,
+    N_("set Mailutils debugging level"),
+    mu_c_string, NULL, cli_debug_level },
+  { "debug-line-info", 0, NULL,    MU_OPTION_DEFAULT,
+    N_("show source info with debugging messages"),
+    mu_c_bool, &mu_debug_line_info },
+  MU_OPTION_END
+};
+
+static int
+cb_debug_level (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  mu_debug_parse_spec (val->v.string);
+  return 0;
+}
+
+static struct mu_cfg_param debug_cfg[] = {
+  { "level", mu_cfg_callback, NULL, 0, &cb_debug_level,
+    N_("Set Mailutils debugging level.  Argument is a colon-separated list "
+       "of debugging specifications in the form:\n"
+       "   <object: string>[[:]=<level: number>]."),
+    N_("arg: string") },
+  { "line-info", mu_c_bool, &mu_debug_line_info, 0, NULL,
+    N_("Prefix debug messages with Mailutils source locations.") },
+  { NULL }
+};
+
+/* ************************************************************************* *
+ * Mailbox                                                                   *
+ * ************************************************************************* */
+
+static int
+cb_mail_spool (void *data, mu_config_value_t *val)
+{
+  int rc;
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  rc = mu_set_mail_directory (val->v.string);
+  if (rc)
+    mu_error (_("cannot set mail directory name to `%s': %s"),
+	      val->v.string, mu_strerror (rc));
+  return rc;
+}
+
+static int
+cb_mailbox_pattern (void *data, mu_config_value_t *val)
+{
+  int rc;
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+
+  rc = mu_set_mailbox_pattern (val->v.string);
+  if (rc)
+    mu_error (_("cannot set mailbox pattern to `%s': %s"),
+	      val->v.string, mu_strerror (rc));
+  return rc;
+}
+
+static int
+cb_mailbox_type (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  if (mu_registrar_set_default_scheme (val->v.string))
+    mu_error (_("invalid mailbox type: %s"), val->v.string);
+  return 0;
+}
+  
+static int
+cb_folder (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  mu_set_folder_directory (val->v.string);
+  return 0;
+}
+
+static struct mu_cfg_param mailbox_cfg[] = {
+  { "mail-spool", mu_cfg_callback, NULL, 0, cb_mail_spool,
+    N_("Use specified URL as a mailspool directory."),
+    N_("url: string") },
+  { "mailbox-pattern", mu_cfg_callback, NULL, 0, cb_mailbox_pattern,
+    N_("Create mailbox URL using <pattern>."),
+    N_("pattern: string") },
+  { "mailbox-type", mu_cfg_callback, NULL, 0, cb_mailbox_type,
+    N_("Default mailbox type."),
+    N_("protocol: string") },
+  { "folder", mu_cfg_callback, NULL, 0, cb_folder,
+    N_("Default user mail folder"),
+    N_("dir: string") },
+  { NULL }
+};
+
+/* ************************************************************************* *
+ * Locking                                                                   *
+ * ************************************************************************* */
+static int
+cb_locker_flags (void *data, mu_config_value_t *val)
+{
+  int flags = 0;
+  char const *s;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+
+  for (s = val->v.string; *s; s++)
+    {
+      switch (*s)
+	{
+	case 'E':
+	  flags |= MU_LOCKER_EXTERNAL;
+	  break;
+	      
+	case 'R':
+	  flags |= MU_LOCKER_RETRY;
+	  break;
+	      
+	case 'T':
+	  flags |= MU_LOCKER_TIME;
+	  break;
+	      
+	case 'P':
+	  flags |= MU_LOCKER_PID;
+	  break;
+	      
+	default:
+	  mu_error (_("invalid lock flag `%c'"), *s);
+	}
+    }
+  mu_locker_set_default_flags (flags, mu_locker_assign);
+  return 0;
+}
+
+static int
+cb_locker_retry_timeout (void *data, mu_config_value_t *val)
+{
+  int rc;
+  time_t t;
+  char *errmsg;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  rc = mu_str_to_c (val->v.string, mu_c_time, &t, &errmsg);
+  if (rc)
+    {
+      mu_error (_("conversion failed: %s"), errmsg ? errmsg :
+		mu_strerror (rc));
+      free (errmsg);
+    }
+  else
+    {
+      mu_locker_set_default_retry_timeout (t);
+      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
+    }
+  return 0;
+}
+
+static int
+cb_locker_retry_count (void *data, mu_config_value_t *val)
+{
+  int rc;
+  size_t n;
+  char *errmsg;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  rc = mu_str_to_c (val->v.string, mu_c_size, &n, &errmsg);
+  if (rc)
+    {
+      mu_error (_("conversion failed: %s"), errmsg ? errmsg :
+		mu_strerror (rc));
+      free (errmsg);
+    }
+  else
+    {
+      mu_locker_set_default_retry_count (n);
+      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
+    }
+  return 0;
+}
+
+static int
+cb_locker_expire_timeout (void *data, mu_config_value_t *val)
+{
+  int rc;
+  time_t t;
+  char *errmsg;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  rc = mu_str_to_c (val->v.string, mu_c_time, &t, &errmsg);
+  if (rc)
+    {
+      mu_error (_("conversion failed: %s"), errmsg ? errmsg :
+		mu_strerror (rc));
+      free (errmsg);
+    }
+  else
+    {
+      mu_locker_set_default_expire_timeout (t);
+      mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
+    }
+  return 0;
+}
+
+static int
+cb_locker_external (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  mu_locker_set_default_external_program (val->v.string);
+  mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
+  return 0;
+}
+  
+static struct mu_cfg_param locking_cfg[] = {
+  /* FIXME: Flags are superfluous. */
+  { "flags", mu_cfg_callback, NULL, 0, cb_locker_flags,
+    N_("Default locker flags (E=external, R=retry, T=time, P=pid)."),
+    N_("arg: string") },
+  { "retry-timeout", mu_cfg_callback, NULL, 0, cb_locker_retry_timeout,
+    N_("Set timeout for acquiring the lock."),
+    N_("arg: interval")},
+  { "retry-count", mu_cfg_callback, NULL, 0, cb_locker_retry_count,
+    N_("Set the maximum number of times to retry acquiring the lock."),
+    N_("arg: integer") },
+  { "expire-timeout", mu_cfg_callback, NULL, 0, cb_locker_expire_timeout,
+    N_("Expire locks older than this amount of time."),
+    N_("arg: interval")},
+  { "external-locker", mu_cfg_callback, NULL, 0, cb_locker_external,
+    N_("Use external locker program."),
+    N_("prog: string") },
+  { NULL, }
+};
+
+/* ************************************************************************* *
+ * Address                                                                   *
+ * ************************************************************************* */
+static int
+cb_email_addr (void *data, mu_config_value_t *val)
+{
+  int rc;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+
+  rc = mu_set_user_email (val->v.string);
+  if (rc)
+    mu_error (_("invalid email address `%s': %s"),
+	      val->v.string, mu_strerror (rc));
+  return 0;
+}
+
+static int
+cb_email_domain (void *data, mu_config_value_t *val)
+{
+  int rc;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+
+  rc = mu_set_user_email_domain (val->v.string);
+  if (rc)
+    mu_error (_("invalid email domain `%s': %s"),
+	      val->v.string, mu_strerror (rc));
+  return 0;
+}
+
+static struct mu_cfg_param address_cfg[] = {
+  { "email-addr", mu_cfg_callback, NULL, 0, cb_email_addr,
+    N_("Set the current user email address (default is "
+       "loginname@defaultdomain)."),
+    N_("email: address") },
+  { "email-domain", mu_cfg_callback, NULL, 0, cb_email_domain,
+    N_("Set e-mail domain for unqualified user names (default is this host)"),
+    N_("domain: string") },
+  { NULL }
+};
+
+/* ************************************************************************* *
+ * Authentication & Authorization                                            *
+ * ************************************************************************* */
+static int
+cb_authentication (void *data, mu_config_value_t *val)
+{
+  if (val->type == MU_CFG_STRING)
+    {
+      if (strcmp (val->v.string, "clear") == 0)
+	mu_authentication_clear_list ();
+      else
+	/*FIXME: use err for error reporting*/
+	mu_authentication_add_module_list (val->v.string);
+    }
+  else if (val->type == MU_CFG_LIST)
+    {
+      int i;
+      for (i = 0; i < val->v.arg.c; i++)
+	{
+	  if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
+	    return 1;
+	  if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
+	    mu_authentication_clear_list ();
+	  else
+	    mu_authentication_add_module (val->v.arg.v[i].v.string);
+	}
+    }
+  else
+    {
+      mu_error (_("expected string value"));
+      return 1;
+    }
+  return 0;
+}
+
+static int
+cb_authorization (void *data, mu_config_value_t *val)
+{
+  if (val->type == MU_CFG_STRING)
+    {
+      if (strcmp (val->v.string, "clear") == 0)
+	mu_authorization_clear_list ();
+      else
+	/*FIXME: use err for error reporting*/
+	mu_authorization_add_module_list (val->v.string);
+    }
+  else if (val->type == MU_CFG_LIST)
+    {
+      int i;
+      for (i = 0; i < val->v.arg.c; i++)
+	{
+	  if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
+	    return 1;
+	  if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
+	    mu_authorization_clear_list ();
+	  else
+	    mu_authorization_add_module (val->v.arg.v[i].v.string);
+	}
+    }
+  else
+    {
+      mu_error (_("expected string value"));
+      return 1;
+    }
+  return 0;
+}
+
+static struct mu_cfg_param mu_auth_param[] = {
+  { "authentication", mu_cfg_callback, NULL, 0, cb_authentication,
+    /* FIXME: The description is incomplete. MU-list is also allowed as
+       argument */
+    N_("Set a list of modules for authentication. Modlist is a "
+       "colon-separated list of module names or a word `clear' to "
+       "clear the previously set up values."),
+    N_("modlist") },
+  { "authorization", mu_cfg_callback, NULL, 0, cb_authorization,
+    N_("Set a list of modules for authorization. Modlist is a "
+       "colon-separated list of module names or a word `clear' to "
+       "clear the previously set up values."),
+    N_("modlist") },
+  { NULL }
+};
+
+int
+mu_auth_section_parser
+   (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
+    const char *section_label, void **section_data, void *call_data,
+    mu_cfg_tree_t *tree)
+{
+  switch (stage)
+    {
+    case mu_cfg_section_start:
+      break;
+
+    case mu_cfg_section_end:
+      mu_auth_finish_setup ();
+    }
+  return 0;
+}
+
+/* ************************************************************************* *
+ * Registry of standard mailutils' capabilities                              *
+ * ************************************************************************* */
+struct mu_cli_capa mu_cli_std_capa[] = {
+  { "mailutils" }, /* Dummy */
+  { "logging", logging_option, logging_cfg, NULL, logging_commit },
+  { "mailer",  mailer_option, mailer_cfg, NULL, NULL },
+  { "debug", debug_option, debug_cfg, NULL, NULL },
+  { "mailbox", NULL, mailbox_cfg, NULL, NULL },
+  { "locking", NULL, locking_cfg, NULL, NULL },
+  { "address", NULL, address_cfg, NULL, NULL },
+  { "auth",    NULL, mu_auth_param, mu_auth_section_parser },
+
+  { NULL }
+};
+
+void
+mu_cli_capa_init (void)
+{
+  size_t i;
+
+  for (i = 0; mu_cli_std_capa[i].name; i++)
+    mu_cli_capa_register (&mu_cli_std_capa[i]);
+}
diff --git a/libmailutils/diag/diag.c b/libmailutils/diag/diag.c
index ba055b2..3f10356 100644
--- a/libmailutils/diag/diag.c
+++ b/libmailutils/diag/diag.c
@@ -30,32 +30,6 @@
 #include <mailutils/stdstream.h>
 #include <mailutils/stream.h>
 
-const char *mu_program_name;
-const char *mu_full_program_name;
-
-void
-mu_set_program_name (const char *name)
-{
-  const char *progname;
-
-  mu_full_program_name = name;
-  if (!name)
-    progname = name;
-  else
-    {
-      progname = strrchr (name, '/');
-      if (progname)
-	progname++;
-      else
-	progname = name;
-      
-      if (strlen (progname) > 3 && memcmp (progname, "lt-", 3) == 0)
-	progname += 3;
-    }
-  
-  mu_program_name = progname;
-}
-
 void
 mu_diag_init ()
 {
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index b106d9a..f91c126 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -155,7 +155,7 @@ init_usage_vars (struct mu_parseopt *po)
   fmt = getenv ("ARGP_HELP_FMT");
   if (!fmt)
     return;
-  ws.ws_delim=",";
+  ws.ws_delim = ",";
   if (mu_wordsplit (fmt, &ws, 
 		    MU_WRDSF_DELIM | MU_WRDSF_NOVAR | MU_WRDSF_NOCMD
 		    | MU_WRDSF_WS | MU_WRDSF_SHOWERR))
@@ -346,20 +346,20 @@ mu_program_help (struct mu_parseopt *po)
   mu_option_describe_options (po->po_optv, po->po_optc);
 
   if (po->po_help_hook)
-    po->po_help_hook (stdout);
+    po->po_help_hook (po, stdout);
 
   if (po->po_bug_address)
     /* TRANSLATORS: The placeholder indicates the bug-reporting address
        for this package.  Please add _another line_ saying
        "Report translation bugs to <...>\n" with the address for translation
        bugs (typically your translation team's web or email address).  */
-    printf (_("Report bugs to %s.\n"), po->po_bug_address);
+    printf (_("Report bugs to <%s>.\n"), po->po_bug_address);
 
   if (po->po_package_name && po->po_package_url)
     printf (_("%s home page: <%s>\n"),
 	    po->po_package_name, po->po_package_url);
   if (po->po_flags & MU_PARSEOPT_EXTRA_INFO)
-    print_option_descr (po->po_extra_info, 0, rmargin);
+    print_option_descr (_(po->po_extra_info), 0, rmargin);
 }
 
 static struct mu_option **option_tab;
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 61bd00f..37c22ab 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -85,7 +85,7 @@ fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 static void
 fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
-  po->po_version_hook (stdout);
+  po->po_version_hook (po, stdout);
   exit (EXIT_SUCCESS);
 }
 
@@ -107,8 +107,8 @@ struct mu_option mu_version_options[] = {
 };
 
 /* Output error message */
-static void
-parse_error (struct mu_parseopt *po, char const *fmt, ...)
+void
+mu_parseopt_error (struct mu_parseopt *po, char const *fmt, ...)
 {
   va_list ap;
 
@@ -176,7 +176,7 @@ find_short_option (struct mu_parseopt *po, int chr)
 	  && po->po_optv[i]->opt_short == chr)
 	return option_unalias (po, i);
     }
-  parse_error (po, _("unrecognized option '-%c'"), chr);
+  mu_parseopt_error (po, _("unrecognized option '-%c'"), chr);
   return NULL;
 }
 
@@ -207,9 +207,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
 	      break;
 
 	    case 1:
+	      if (option_unalias (po, i) == option_unalias (po, ind))
+		continue;
 	      if (po->po_flags & MU_PARSEOPT_IGNORE_ERRORS)
 		return NULL;
-	      parse_error (po,
+	      mu_parseopt_error (po,
 			   _("option '--%*.*s' is ambiguous; possibilities:"),
 			   optlen, optlen, optstr);
 	      fprintf (stderr, "--%s\n", po->po_optv[ind]->opt_long);
@@ -224,7 +226,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
   switch (found)
     {
     case 0:
-      parse_error (po, _("unrecognized option '--%s'"), optstr);
+      mu_parseopt_error (po, _("unrecognized option '--%s'"), optstr);
       break;
       
     case 1:
@@ -303,7 +305,7 @@ next_opt (struct mu_parseopt *po)
 	    break;
 	  if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
 	    {
-	      if (!po->po_permuted)
+	      if (!po->po_permuted && po->po_arg_count == 0)
 		po->po_arg_start = po->po_ind - 1;
 	      po->po_arg_count++;
 	      continue;
@@ -405,11 +407,11 @@ parse (struct mu_parseopt *po)
 	      else
 		{
 		  if (long_opt)
-		    parse_error (po,
+		    mu_parseopt_error (po,
 				 _("option '--%s' requires an argument"),
 				 long_opt);
 		  else
-		    parse_error (po,
+		    mu_parseopt_error (po,
 				 _("option '-%c' requires an argument"),
 				 po->po_chr);
 		  po->po_opterr = po->po_ind;
@@ -428,7 +430,7 @@ parse (struct mu_parseopt *po)
 		  && po->po_cur[0]
 		  && !(po->po_flags & MU_OPTION_ARG_OPTIONAL))
 		{
-		  parse_error (po,
+		  mu_parseopt_error (po,
 			       _("option '--%s' doesn't allow an argument"),
 			       long_opt);
 		  po->po_opterr = po->po_ind;
@@ -661,9 +663,9 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
 	    errtext = mu_strerror (rc);
 
 	  if (opt->opt_long)
-	    parse_error (po, "--%s: %s", opt->opt_long, errtext);
+	    mu_parseopt_error (po, "--%s: %s", opt->opt_long, errtext);
 	  else
-	    parse_error (po, "-%c: %s", opt->opt_short, errtext);
+	    mu_parseopt_error (po, "-%c: %s", opt->opt_short, errtext);
 	  free (errmsg);
 
 	  if (!(po->po_flags & MU_PARSEOPT_NO_ERREXIT))
diff --git a/libmailutils/opt/progname.c b/libmailutils/opt/progname.c
index 19d430e..0d19773 100644
--- a/libmailutils/opt/progname.c
+++ b/libmailutils/opt/progname.c
@@ -22,16 +22,16 @@
 #include <mailutils/alloc.h>
 #include <mailutils/opt.h>
 
-char *mu_progname;
-char *mu_absprogname;
+char *mu_program_name;
+char *mu_full_program_name;
 
 void
-mu_set_progname (char const *arg)
+mu_set_program_name (const char *arg)
 {
   char *p;
 
-  free (mu_absprogname);
-  mu_absprogname = mu_strdup (arg);
+  free (mu_full_program_name);
+  mu_full_program_name = mu_strdup (arg);
   
   p = strrchr (arg, '/');
   if (p)
@@ -40,6 +40,6 @@ mu_set_progname (char const *arg)
     p = (char*) arg;
   if (strlen (p) > 3 && memcmp (p, "lt-", 3) == 0)
     p += 3;
-  free (mu_progname);
-  mu_progname = mu_strdup (p);
+  free (mu_program_name);
+  mu_program_name = mu_strdup (p);
 }
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index 51e4e68..62b06b4 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -27,6 +27,7 @@ strftime
 strin
 strout
 strtoc
+tcli
 tempfile
 url-comp
 url-parse
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 349eb24..728eaec 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -64,6 +64,7 @@ noinst_PROGRAMS = \
  strout\
  strtoc\
  tempfile\
+ tcli\
  url-comp\
  url-parse\
  wicket\
diff --git a/libmailutils/tests/parseopt.c b/libmailutils/tests/parseopt.c
index bef57ee..f25aabf 100644
--- a/libmailutils/tests/parseopt.c
+++ b/libmailutils/tests/parseopt.c
@@ -64,7 +64,7 @@ struct mu_option group_b[] = {
 struct mu_option *optv[] = { group_a, group_b, NULL };
 
 static void
-version_func (FILE *fp)
+version_hook (struct mu_parseopt *po, FILE *fp)
 {
   fputs ("version hook called\n", fp);
 }
@@ -144,7 +144,7 @@ main (int argc, char *argv[])
 	    }
 	}
       if (flags & MU_PARSEOPT_VERSION_HOOK)
-	po.po_version_hook = version_func;
+	po.po_version_hook = version_hook;
     }
   
   rc = mu_parseopt (&po, argc, argv, optv, flags);
diff --git a/libmailutils/tests/parseopt17.at b/libmailutils/tests/parseopt17.at
index 2823e0a..b57a070 100644
--- a/libmailutils/tests/parseopt17.at
+++ b/libmailutils/tests/parseopt17.at
@@ -35,4 +35,24 @@ argv:
 2: follow
 3: options
 ])
+
+AT_CHECK([
+PARSEOPT_DEFAULT
+parseopt --file=file more arguments follow -x -o options
+],
+[0],
+[rc=0
+file_name=file
+opt_value=(null)
+x_option=1
+a_option=0
+find_value=(null)
+d_option=0
+jobs=0
+argv:
+0: more
+1: arguments
+2: follow
+3: options
+])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt_help05.at b/libmailutils/tests/parseopt_help05.at
index 9a0c1ed..4fe6960 100644
--- a/libmailutils/tests/parseopt_help05.at
+++ b/libmailutils/tests/parseopt_help05.at
@@ -18,7 +18,7 @@ AT_SETUP([MU_PARSEOPT_BUG_ADDRESS])
 AT_KEYWORDS([parseopt parseopt_help parseopt_help05])
 AT_CHECK([
 PARSEOPT_DEFAULT
-MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>' parseopt --help
+MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org' parseopt --help
 ],
 [0],
 [Usage: parseopt [[OPTION]]...
diff --git a/libmailutils/tests/parseopt_help07.at b/libmailutils/tests/parseopt_help07.at
index 265acb4..91c3c19 100644
--- a/libmailutils/tests/parseopt_help07.at
+++ b/libmailutils/tests/parseopt_help07.at
@@ -20,7 +20,7 @@ AT_CHECK([
 PARSEOPT_DEFAULT
 MU_PARSEOPT_PROG_DOC="Tests option parsing"\
  MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS"\ 
- MU_PARSEOPT_BUG_ADDRESS='<gray@gnu.org>'\
+ MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org'\
  MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils'\
  MU_PARSEOPT_PACKAGE_URL='http://mailutils.org'\
  MU_PARSEOPT_EXTRA_INFO='General help using GNU software: <http://www.gnu.org/gethelp/>'\
diff --git a/libmailutils/tests/tcli.c b/libmailutils/tests/tcli.c
new file mode 100644
index 0000000..9a640d5
--- /dev/null
+++ b/libmailutils/tests/tcli.c
@@ -0,0 +1,75 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/mailutils.h>
+#include <mailutils/cli.h>
+
+int dtrt_option;
+
+struct mu_option group_a[] = {
+  { "dtrt", 'd', "VALUE", MU_OPTION_DEFAULT,
+    "do the right thing",
+    mu_c_int, &dtrt_option },
+  MU_OPTION_END
+};
+
+struct mu_option *options[] = { group_a, NULL };
+
+static struct mu_cfg_param config[] = {
+  { "do-the-right-thing", mu_c_int, &dtrt_option, 0, NULL,
+    "do the right thing" },
+  { NULL }
+};
+
+struct mu_cli_setup cli = {
+  options,
+  config,
+  "Tests standard command line interface",
+  "ARGUMENTS"
+};
+
+static char **
+getcapa (void)
+{
+  struct mu_wordsplit ws;
+  char *p;
+  
+  p = getenv ("MU_CLI_CAPA");
+  if (!p)
+    return NULL;
+  ws.ws_delim = ",";
+  if (mu_wordsplit (p, &ws, 
+		    MU_WRDSF_DELIM | MU_WRDSF_NOVAR | MU_WRDSF_NOCMD
+		    | MU_WRDSF_WS | MU_WRDSF_SHOWERR))
+    exit (1);
+  return ws.ws_wordv;
+}
+  
+int
+main (int argc, char **argv)
+{
+  int i;
+  
+  mu_cli (argc, argv, &cli, getcapa (), NULL, &argc, &argv);
+  printf ("DTRT=%d\n", dtrt_option);
+  printf ("%d arguments:\n", argc);
+  for (i = 0; i < argc; i++)
+    printf ("%d: %s\n", i, argv[i]);
+  return 0;
+}
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index 331370c..89e3b52 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -35,15 +35,36 @@
 #include <mailutils/errno.h>
 #include <mailutils/util.h>
 #include <mailutils/property.h>
+#include <mailutils/cli.h>
+
+#define SSL_CERT_FILE_CHECKS  (MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_LINKED_WRDIR)
+
+#define SSL_KEY_FILE_CHECKS   (MU_FILE_SAFETY_ALL & \
+			       ~MU_FILE_SAFETY_OWNER_MISMATCH)
+
+#define SSL_CA_FILE_CHECKS    (MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_GROUP_WRITABLE |		\
+			       MU_FILE_SAFETY_LINKED_WRDIR)
 
 struct mu_tls_module_config mu_tls_module_config = {
 #ifdef WITH_TLS
-  1 /* enable by default */
+    1, /* enable by default */
+      
+    NULL,                /* Certificate file */
+    SSL_CERT_FILE_CHECKS,
+
+    NULL,                /* Key file */ 
+    SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
+
+    NULL,                /* CA file */
+    SSL_CA_FILE_CHECKS
 #else
   0
 #endif
 };
-  
+//FIXME: REMOVE  
 int
 mu_tls_module_init (enum mu_gocs_op op, void *data)
 {
@@ -774,8 +795,92 @@ mu_tls_client_stream_create (mu_stream_t *pstream,
 				_tls_client_open,
 				strin, strout, flags);
 }
+
+static int
+cb2_safety_checks (const char *name, void *data)
+{
+  int defval;
+  
+  if (data == &mu_tls_module_config.ssl_key_safety_checks)
+    defval = SSL_KEY_FILE_CHECKS;
+  else if (data == &mu_tls_module_config.ssl_cert_safety_checks)
+    defval = SSL_CERT_FILE_CHECKS;
+  else if (data == &mu_tls_module_config.ssl_cafile_safety_checks)
+    defval = SSL_CA_FILE_CHECKS;
+  else
+    {
+      mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
+		__FILE__, __LINE__);
+      defval = MU_FILE_SAFETY_ALL;
+    }
+  if (mu_file_safety_compose (data, name, defval))
+    mu_error (_("unknown keyword: %s"), name);
+  return 0;
+}
 
-
+static int
+cb_safety_checks (void *data, mu_config_value_t *arg)
+{
+  return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
+}
+
+static struct mu_cfg_param mu_tls_param[] = {
+  { "enable", mu_c_bool, &mu_tls_module_config.enable, 0, NULL,
+    N_("Enable TLS encryption.") },
+  { "ssl-cert", mu_c_string, &mu_tls_module_config.ssl_cert, 0, NULL,
+    N_("Specify SSL certificate file."),
+    N_("file") },
+  { "ssl-key", mu_c_string, &mu_tls_module_config.ssl_key, 0, NULL,
+    N_("Specify SSL certificate key file."),
+    N_("file") },
+  { "ssl-cafile", mu_c_string, &mu_tls_module_config.ssl_cafile, 0, NULL,
+    N_("Specify trusted CAs file."),
+    N_("file") },
+  { "ssl-priorities", mu_c_string, &mu_tls_module_config.priorities, 0, NULL,
+    N_("Set the priorities to use on the ciphers, key exchange methods, "
+       "macs and compression methods."),
+    NULL },
+  { "key-file-safety-checks", mu_cfg_callback,
+    &mu_tls_module_config.ssl_key_safety_checks, 0,
+    cb_safety_checks,
+    N_("Configure safety checks for SSL key file.  Argument is a list or "
+       "sequence of check names optionally prefixed with '+' to enable or "
+       "'-' to disable the corresponding check.  Valid check names are:\n"
+       "\n"
+       "  none          disable all checks\n"
+       "  all           enable all checks\n"
+       "  gwrfil        forbid group writable files\n"
+       "  awrfil        forbid world writable files\n"
+       "  grdfil        forbid group readable files\n"
+       "  ardfil        forbid world writable files\n"
+       "  linkwrdir     forbid symbolic links in group or world writable directories\n"
+       "  gwrdir        forbid files in group writable directories\n"
+       "  awrdir        forbid files in world writable directories\n"),
+    N_("arg: list") },  
+  { "cert-file-safety-checks", mu_cfg_callback,
+    &mu_tls_module_config.ssl_cert_safety_checks, 0,
+    cb_safety_checks,
+    N_("Configure safety checks for SSL certificate.  See above for a description of <arg>."),
+    N_("arg: list") },  
+  { "ca-file-safety-checks", mu_cfg_callback,
+    &mu_tls_module_config.ssl_cafile_safety_checks, 0,
+    cb_safety_checks,
+    N_("Configure safety checks for SSL certificate authority file.  See above for a description of <arg>."),
+    N_("arg: list") },  
+  { NULL }
+}; 
+
+struct mu_cli_capa mu_cli_capa_tls = {
+  "tls",
+  NULL,
+  mu_tls_param,
+  NULL, NULL
+};
+#else
+struct mu_cli_capa mu_cli_capa_tls = {
+  "tls",
+  NULL
+};
 #endif /* WITH_TLS */
 
 /* EOF */
diff --git a/libmu_sieve/conf.c b/libmu_sieve/conf.c
index 0f9283a..15b33aa 100644
--- a/libmu_sieve/conf.c
+++ b/libmu_sieve/conf.c
@@ -18,23 +18,28 @@
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
-#endif  
+#endif
+#include <stdlib.h>
 #include <sieve-priv.h>
 #include <string.h>
+#include <mailutils/cli.h>
 
 mu_list_t mu_sieve_include_path = NULL;
 mu_list_t mu_sieve_library_path = NULL;
 mu_list_t mu_sieve_library_path_prefix = NULL;
-
 mu_debug_handle_t mu_sieve_debug_handle;
 
+//FIXME: provide definition (from gocs.h)
+static struct mu_gocs_sieve sieve_settings;
+
 void
-mu_sieve_debug_init ()
+mu_sieve_debug_init (void)
 {
   if (!mu_sieve_debug_handle)
     mu_sieve_debug_handle = mu_debug_register_category ("sieve");
 }
 
+/*FIXME: REMOVE BEGIN */
 static int
 _path_append (void *item, void *data)
 {
@@ -73,7 +78,7 @@ mu_sieve_module_init (enum mu_gocs_op op, void *data)
       mu_list_destroy (&mu_sieve_library_path_prefix);
     }
   mu_list_foreach (p->library_path_prefix, _path_append,
-	      &mu_sieve_library_path_prefix);
+		   &mu_sieve_library_path_prefix);
   mu_list_foreach (p->library_path, _path_append, &mu_sieve_library_path);
   mu_list_destroy (&p->library_path);
   mu_list_destroy (&p->library_path_prefix);
@@ -81,3 +86,161 @@ mu_sieve_module_init (enum mu_gocs_op op, void *data)
   mu_sieve_debug_init ();
   return 0;
 }
+/* FIXME: REMOVE END */
+
+static int
+cb_clear_library_path (void *data, mu_config_value_t *val)
+{
+  int flag;
+
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
+    {
+      mu_error (_("not a boolean"));
+      return 1;
+    }
+  if (flag)
+    sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
+  return 0;
+}
+
+static int
+cb_clear_include_path (void *data, mu_config_value_t *val)
+{
+  int flag;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
+    {
+      mu_error (_("not a boolean"));
+      return 1;
+    }
+  if (flag)
+    sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
+  return 0;
+}
+
+static int
+_add_path (const char *arg, void *data)
+{
+  mu_list_t *plist = data;
+    
+  if (!*plist)
+    {
+      int rc = mu_list_create (plist);
+      if (rc)
+	{
+	  mu_error (_("cannot create list: %s"), mu_strerror (rc));
+	  exit (1);
+	}
+      mu_list_set_destroy_item (*plist, mu_list_free_item);
+    }
+  return mu_string_split (arg, ":", *plist);
+}
+
+static int
+cb_include_path (void *data, mu_config_value_t *val)
+{
+  return mu_cfg_string_value_cb (val, _add_path,
+				 &sieve_settings.include_path);
+}  
+
+static int
+cb_library_path (void *data, mu_config_value_t *val)
+{
+  return mu_cfg_string_value_cb (val, _add_path,
+				 &sieve_settings.library_path);
+}
+
+static int
+cb_library_path_prefix (void *data, mu_config_value_t *val)
+{
+  return mu_cfg_string_value_cb (val, _add_path,
+				 &sieve_settings.library_path_prefix);
+}
+
+static struct mu_cfg_param mu_sieve_param[] = {
+  { "clear-library-path", mu_cfg_callback, NULL, 0, cb_clear_library_path,
+     N_("Clear library search path.") },
+  { "clear-include-path", mu_cfg_callback, NULL, 0, cb_clear_include_path,
+     N_("Clear include search path.") },
+  { "library-path", mu_cfg_callback, NULL, 0, cb_library_path,
+    N_("Add directories to the library search path.  Argument is a "
+       "colon-separated list of directories."),
+    N_("list") },
+  { "library-path-prefix", mu_cfg_callback, NULL, 0, cb_library_path_prefix,
+    N_("Add directories to the beginning of the library search path.  "
+       "Argument is a colon-separated list of directories."),
+    N_("list") },
+  { "include-path", mu_cfg_callback, NULL, 0, cb_include_path,
+    N_("Add directories to the include search path.  Argument is a "
+       "colon-separated list of directories."),
+    N_("list") },
+  { NULL }
+};
+
+/* New capability support */
+static void
+cli_includedir (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  _add_path (arg, &sieve_settings.include_path);
+}
+
+static void
+cli_libdir  (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  _add_path (arg, &sieve_settings.library_path);
+}
+
+static void
+cli_libdir_prefix (struct mu_parseopt *po, struct mu_option *opt,
+		   char const *arg)
+{
+  _add_path (arg, &sieve_settings.library_path_prefix);
+}
+
+static void
+cli_clear_include_path (struct mu_parseopt *po, struct mu_option *opt,
+			char const *arg)
+{
+  sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
+}
+
+static void
+cli_clear_library_path (struct mu_parseopt *po, struct mu_option *opt,
+			char const *arg)
+{
+  sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
+}
+
+static struct mu_option sieve_option[] = {
+  MU_OPTION_GROUP (N_("Sieve options")),
+  { "includedir", 'I', N_("DIR"), MU_OPTION_DEFAULT,
+    N_("append DIR to the list of directories searched for include files"),
+    mu_c_string, NULL, cli_includedir },
+  { "libdir", 'L', N_("DIR"), MU_OPTION_DEFAULT,
+    N_("append DIR to the list of directories searched for library files"),
+    mu_c_string, NULL, cli_libdir },
+  { "libdir-prefix", 0, N_("DIR"), MU_OPTION_DEFAULT,
+    N_("add DIR to the beginning of the list of directories searched for "
+       "library files"),
+    mu_c_string, NULL, cli_libdir_prefix },
+  { "clear-include-path", 0, NULL, MU_OPTION_DEFAULT,
+    N_("clear Sieve include path"),
+    mu_c_string, NULL, cli_clear_include_path },
+  { "clear-library-path", 0, NULL, MU_OPTION_DEFAULT,
+    N_("clear Sieve library path"),
+    mu_c_string, NULL, cli_clear_library_path },
+  { "clearpath", 0, NULL, MU_OPTION_ALIAS },
+  MU_OPTION_END
+};
+
+struct mu_cli_capa mu_cli_capa_sieve = {
+  "sieve",
+  sieve_option,
+  mu_sieve_param,
+  NULL, NULL
+};
diff --git a/messages/Makefile.am b/messages/Makefile.am
index d611b2c..56ff5e7 100644
--- a/messages/Makefile.am
+++ b/messages/Makefile.am
@@ -22,7 +22,7 @@ SUBDIRS = . tests
 bin_PROGRAMS = messages
 messages_SOURCES = messages.c
 messages_LDADD =\
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/messages/messages.c b/messages/messages.c
index 4f5c614..84cf4bf 100644
--- a/messages/messages.c
+++ b/messages/messages.c
@@ -20,85 +20,44 @@
 #endif
 
 #include <stdio.h>
-#ifdef HAVE_MALLOC_H
-# include <malloc.h>
-#endif
 
 #include <mailutils/mailutils.h>
-#include "mailutils/libargp.h"
+#include <mailutils/cli.h>
 
 static int messages_count (const char *);
 
-static char doc[] = N_("GNU messages -- count the number of messages in a mailbox");
-static char args_doc[] = N_("[mailbox...]");
+/* are we loud or quiet? */
+static int silent = 0;
 
-static struct argp_option options[] = {
-  { NULL,         0, NULL,  0,
-    /* TRANSLATORS: 'messages' is a program name. Do not translate it! */
-    N_("messages specific switches:"), 0},
-  {"quiet",	'q',	NULL,	0,	N_("only display number of messages")},
-  {"silent",	's',	NULL,	OPTION_ALIAS, NULL },
-  { 0 }
+static struct mu_option messages_options[] = {
+  { "quiet",	'q',	NULL,	MU_OPTION_DEFAULT,
+    N_("only display number of messages"),
+    mu_c_bool, &silent },
+  {"silent",	's',	NULL,	MU_OPTION_ALIAS },
+  MU_OPTION_END
 };
 
-static const char *argp_capa[] = {
-  "mailutils",
-  "common",
+static char *capa[] = {
   "debug",
   "mailbox",
   "locking",
+  "tls",
   NULL
 };
 
-struct arguments
-{
-  int argc;
-  char **argv;
-};
+static struct mu_option *options[] = { messages_options, NULL };
 
-/* are we loud or quiet? */
-static int silent = 0;
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  struct arguments *args = state->input;
-  switch (key)
-    {
-    case 'q':
-    case 's':
-      silent = 1;
-      break;
-      
-    case ARGP_KEY_ARG:
-      args->argv = realloc (args->argv,
-			    sizeof (char *) * (state->arg_num + 2));
-      args->argv[state->arg_num] = arg;
-      args->argv[state->arg_num + 1] = NULL;
-      args->argc++;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp argp = {
+struct mu_cli_setup cli = {
   options,
-  parse_opt,
-  args_doc,
-  doc,
   NULL,
-  NULL, NULL
+  N_("GNU messages -- count the number of messages in a mailbox"),
+  N_("[mailbox...]")
 };
 
 int
 main (int argc, char **argv)
 {
-  int i = 1;
   int err = 0;
-  struct arguments args = {0, NULL};
 
   /* Native Language Support */
   MU_APP_INIT_NLS ();
@@ -106,20 +65,18 @@ main (int argc, char **argv)
   /* register the formats.  */
   mu_register_all_mbox_formats ();
 
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, argp_capa, NULL, argc, argv, 0, NULL, &args))
-    exit (1);
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
-  if (args.argc < 1 && messages_count (NULL) < 0)
+  if (argc == 0 && messages_count (NULL) < 0)
     err = 1;
-  else if (args.argc >= 1)
+  else if (argc >= 1)
     {
-      for (i = 0; i < args.argc; i++)
+      size_t i;
+      
+      for (i = 0; i < argc; i++)
 	{
-	  if (messages_count (args.argv[i]) < 0)
+	  if (messages_count (argv[i]) < 0)
 	    err = 1;
 	}
     }
diff --git a/mimeview/Makefile.am b/mimeview/Makefile.am
index b4c9108..d85eebb 100644
--- a/mimeview/Makefile.am
+++ b/mimeview/Makefile.am
@@ -47,7 +47,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h
 BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h
 
 mimeview_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MAILUTILS}\
  @LTLIBINTL@
  
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 4a7810c..0100f50 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -26,38 +26,11 @@
 #include <unistd.h>
 #include <fcntl.h>
 
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 #include "mailutils/argcv.h"
 
 #include "mailcap.h"
 
-static char doc[] = N_("GNU mimeview -- display files, using mailcap mechanism.")
-"\v"     
-N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
-N_("\n\nDebug flags are:\n\
-  g - Mime.types parser traces\n\
-  l - Mime.types lexical analyzer traces\n\
-  0-9 - Set debugging level\n");
-
-#define OPT_METAMAIL 256
-
-static struct argp_option options[] = {
-  {"no-ask", 'a', N_("TYPE-LIST"), OPTION_ARG_OPTIONAL,
-   N_("do not ask for confirmation before displaying files, or, if TYPE-LIST is given, do not ask for confirmation before displaying such files whose MIME type matches one of the patterns from TYPE-LIST"), 0},
-  {"no-interactive", 'h', NULL, 0,
-   N_("disable interactive mode"), 0 },
-  {"print", 0, NULL, OPTION_ALIAS, NULL, 0 },
-  {"debug",  'd', N_("FLAGS"),  OPTION_ARG_OPTIONAL,
-   N_("enable debugging output"), 0},
-  {"mimetypes", 't', N_("FILE"), 0,
-   N_("use this mime.types file"), 0},
-  {"dry-run", 'n', NULL, 0,
-   N_("do nothing, just print what would have been done"), 0},
-  {"metamail", OPT_METAMAIL, N_("FILE"), OPTION_ARG_OPTIONAL,
-   N_("use metamail to display files"), 0},
-  {0, 0, 0, 0}
-};
-
 int debug_level;       /* Debugging level set by --debug option */
 static int dry_run;    /* Dry run mode */
 static char *metamail; /* Name of metamail program, if requested */
@@ -88,68 +61,62 @@ set_debug_flags (const char *arg)
 	}
     }
 }  
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+
+static void
+cli_no_ask (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case ARGP_KEY_INIT:
-      mimetypes_lex_debug (0);
-      mimetypes_gram_debug (0);
-      if (interactive == -1)
-	interactive = isatty (fileno (stdin));
-      mu_argp_node_list_init (&lst);
-      break;
-
-    case ARGP_KEY_FINI:
-      if (dry_run && !debug_level)
-	debug_level = 1;
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
+  no_ask_types = mu_strdup (arg ? arg : "*");
+  setenv ("MM_NOASK", arg, 1); /* In case we are given --metamail option */
+}
 
-    case 'a':
-      no_ask_types = arg ? arg : "*";
-      setenv ("MM_NOASK", arg, 1); /* In case we are given --metamail option */
-      break;
-      
-    case 'd':
-      mu_argp_node_list_new (lst, "debug", arg ? arg : "9");
-      break;
+static void
+cli_no_interactive (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  interactive = 0;
+}
 
-    case 'h':
-      interactive = 0;
-      break;
-      
-    case 'n':
-      dry_run = 1;
-      break;
-      
-    case 't':
-      mu_argp_node_list_new (lst, "mimetypes", arg);
-      break;
+static void
+cli_debug (struct mu_parseopt *po, struct mu_option *opt,
+	   char const *arg)
+{
+  set_debug_flags (arg);
+}
 
-    case OPT_METAMAIL:
-      mu_argp_node_list_new (lst, "metamail", arg ? arg : "metamail");
-      break;
-      
-    default: 
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+cli_metamail (struct mu_parseopt *po, struct mu_option *opt,
+	      char const *arg)
+{
+  if (!arg)
+    arg = "metamail";
+  metamail = mu_strdup (arg);
 }
 
-static struct argp argp = {
-  options,
-  parse_opt,
-  N_("FILE [FILE ...]"),
-  doc,
-  NULL,
-  NULL, NULL
-};
+static struct mu_option mimeview_options[] = {
+  { "no-ask", 'a', N_("TYPE-LIST"), MU_OPTION_ARG_OPTIONAL,
+    N_("do not ask for confirmation before displaying files, or, if TYPE-LIST is given, do not ask for confirmation before displaying such files whose MIME type matches one of the patterns from TYPE-LIST"),
+    mu_c_string, NULL, cli_no_ask },
+  { "no-interactive", 'h', NULL, MU_OPTION_DEFAULT,
+   N_("disable interactive mode"),
+    mu_c_string, NULL, cli_no_interactive },
+  { "print",  0, NULL, MU_OPTION_ALIAS },
+  { "debug", 'd', N_("FLAGS"),  MU_OPTION_ARG_OPTIONAL,
+    N_("enable debugging output"),
+    mu_c_string, NULL, cli_debug },
+  { "mimetypes", 't', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("use this mime.types file"),
+    mu_c_string, &mimetypes_config },
+  
+  { "dry-run",   'n', NULL, MU_OPTION_DEFAULT,
+    N_("do nothing, just print what would have been done"),
+    mu_c_bool, &dry_run },
+  
+  { "metamail",    0, N_("FILE"), MU_OPTION_ARG_OPTIONAL,
+    N_("use metamail to display files"),
+    mu_c_string, NULL, cli_metamail },
 
+  MU_OPTION_END
+}, *options[] = { mimeview_options, NULL };
 
 static int
 cb_debug (void *data, mu_config_value_t *val)
@@ -172,12 +139,23 @@ struct mu_cfg_param mimeview_cfg_param[] = {
     N_("prog") },
   { NULL }
 };
-
 
-
-static const char *capa[] = {
-  "mailutils",
-  "common",
+struct mu_cli_setup cli = {
+  options,
+  mimeview_cfg_param,
+  N_("GNU mimeview -- display files, using mailcap mechanism."),
+  //FIXME:
+  /*
+  N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
+N_("\n\nDebug flags are:\n\
+  g - Mime.types parser traces\n\
+  l - Mime.types lexical analyzer traces\n\
+  0-9 - Set debugging level\n");
+  */
+  N_("FILE [FILE ...]")
+};
+
+static char *capa[] = {
   "debug",
   NULL
 };
@@ -267,16 +245,15 @@ display_file (const char *type)
 int
 main (int argc, char **argv)
 {
-  int index;
-  
   MU_APP_INIT_NLS ();
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, capa, mimeview_cfg_param, 
-		   argc, argv, 0, &index, NULL))
-    exit (1);
 
-  argc -= index;
-  argv += index;
+  mimetypes_lex_debug (0);
+  mimetypes_gram_debug (0);
+  interactive = isatty (fileno (stdin));
+  
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
+  if (dry_run && !debug_level)
+    debug_level = 1;
 
   if (argc == 0)
     {
diff --git a/movemail/Makefile.am b/movemail/Makefile.am
index e166b81..5d0b5c6 100644
--- a/movemail/Makefile.am
+++ b/movemail/Makefile.am
@@ -19,7 +19,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@
 bin_PROGRAMS = movemail
 
 movemail_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/movemail/movemail.c b/movemail/movemail.c
index 67b721f..8fdaf90 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -27,46 +27,9 @@
 #include <unistd.h>
 #include <mailutils/mailutils.h>
 #include <mailutils/tls.h>
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 #include <muaux.h>
 
-static char doc[] = N_("GNU movemail -- move messages across mailboxes.");
-static char args_doc[] = N_("inbox-url destfile [POP-password]");
-
-enum {
-  EMACS_OPTION=256,
-  IGNORE_ERRORS_OPTION,
-  PROGRAM_ID_OPTION,
-  MAX_MESSAGES_OPTION,
-  ONERROR_OPTION,
-  NOTIFY_OPTION
-};
-
-static struct argp_option options[] = {
-  { "preserve", 'p', NULL, 0, N_("preserve the source mailbox") },
-  { "keep-messages", 0, NULL, OPTION_ALIAS, NULL },
-  { "reverse",  'r', NULL, 0, N_("reverse the sorting order") },
-  { "emacs", EMACS_OPTION, NULL, 0,
-    N_("output information used by Emacs rmail interface") },
-  { "uidl", 'u', NULL, 0,
-    N_("use UIDLs to avoid downloading the same message twice") },
-  { "verbose", 'v', NULL, 0,
-    N_("increase verbosity level") },
-  { "owner", 'P', N_("MODELIST"), 0,
-    N_("control mailbox ownership") },
-  { "ignore-errors", IGNORE_ERRORS_OPTION, NULL, 0,
-    N_("try to continue after errors") },
-  { "onerror", ONERROR_OPTION, N_("KW[,KW...]"), 0,
-    N_("what to do on errors") },
-  { "program-id", PROGRAM_ID_OPTION, N_("FMT"), 0,
-    N_("set program identifier for diagnostics (default: program name)") },
-  { "max-messages", MAX_MESSAGES_OPTION, N_("NUMBER"), 0,
-    N_("process at most NUMBER messages") },
-  { "notify",  NOTIFY_OPTION, NULL,   0,
-    N_("enable biff notification") },  
-  { NULL,      0, NULL, 0, NULL, 0 }
-};
-
 static int reverse_order;
 static int preserve_mail; 
 static int emacs_mode;
@@ -135,84 +98,9 @@ mu_kwd_t method_kwd[] = {
   { "set-id", set_owner_id },
   { NULL }
 };
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case 'r':
-      mu_argp_node_list_new (lst, "reverse", "yes");
-      break;
-
-    case 'p':
-      mu_argp_node_list_new (lst, "preserve", "yes");
-      break;
-
-    case 'P':
-      mu_argp_node_list_new (lst, "mailbox-ownership", arg);
-      break;
-
-    case 'u':
-      mu_argp_node_list_new (lst, "uidl", "yes");
-      break;
-
-    case 'v':
-      verbose_option++;
-      break;
-      
-    case EMACS_OPTION:
-      mu_argp_node_list_new (lst, "emacs", "yes");
-      break;
-
-    case IGNORE_ERRORS_OPTION:
-      mu_argp_node_list_new (lst, "ignore-errors", "yes");
-      break;
-
-    case NOTIFY_OPTION:
-      notify = 1;
-      break;
-      
-    case ONERROR_OPTION:
-      mu_argp_node_list_new (lst, "onerror", arg);
-      break;
-      
-    case MAX_MESSAGES_OPTION:
-      mu_argp_node_list_new (lst, "max-messages", arg);
-      break;
-      
-    case PROGRAM_ID_OPTION:
-      mu_argp_node_list_new (lst, "program-id", arg);
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp argp = {
-  options,
-  parse_opt,
-  args_doc,
-  doc,
-  NULL,
-  NULL, NULL
-};
-
 
 static int
-_cb_mailbox_ownership (const char *str)
+set_mailbox_ownership (const char *str)
 {
   if (strcmp (str, "clear") == 0)
     so_method_num = 0;
@@ -280,50 +168,33 @@ _cb_mailbox_ownership (const char *str)
 }
 
 static int
-cb_mailbox_ownership (void *data, mu_config_value_t *val)
+set_mailbox_ownership_list (char const *str)
 {
-  int i;
-  
-  if (val->type == MU_CFG_STRING)
+  if (!strchr (str, ','))
+    return set_mailbox_ownership (str);
+  else
     {
-      const char *str = val->v.string;
-      if (!strchr (str, ','))
-	return _cb_mailbox_ownership (str);
-      else
+      struct mu_wordsplit ws;
+      size_t i;
+      
+      ws.ws_delim = ",";
+      if (mu_wordsplit (str, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM))
 	{
-	  struct mu_wordsplit ws;
-
-	  ws.ws_delim = ",";
-	  if (mu_wordsplit (str, &ws, MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM))
-	    {
-	      mu_error (_("cannot parse %s: %s"),
-			str, mu_wordsplit_strerror (&ws));
-	      return 1;
-	    }
-
-	  for (i = 0; i < ws.ws_wordc; i++)
-	    if (_cb_mailbox_ownership (ws.ws_wordv[i]))
-	      return 1;
-	  mu_wordsplit_free (&ws);
-	  return 0;
+	  mu_error (_("cannot parse %s: %s"),
+		    str, mu_wordsplit_strerror (&ws));
+	  return 1;
 	}
-    }
-		
-  if (mu_cfg_assert_value_type (val, MU_CFG_LIST))
-    return 1;
 
-  for (i = 0; i < val->v.arg.c; i++)
-    {
-      if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
-	return 1;
-      if (_cb_mailbox_ownership (val->v.arg.v[i].v.string))
-	return 1;
+      for (i = 0; i < ws.ws_wordc; i++)
+	if (set_mailbox_ownership (ws.ws_wordv[i]))
+	  return 1;
+      mu_wordsplit_free (&ws);
+      return 0;
     }
-  return 0;
 }
 
 static int
-cb_onerror (void *data, mu_config_value_t *val)
+set_onerror_action (char const *str)
 {
   struct mu_wordsplit ws;
   static struct mu_kwd onerror_kw[] = {
@@ -334,15 +205,13 @@ cb_onerror (void *data, mu_config_value_t *val)
   };
   int i, flag;
   
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  if (strcmp (val->v.string, "abort") == 0)
+  if (strcmp (str, "abort") == 0)
     {
       onerror_flags = 0;
       return 0;
     }
   ws.ws_delim = ",";
-  if (mu_wordsplit (val->v.string, &ws,
+  if (mu_wordsplit (str, &ws,
 		    MU_WRDSF_NOVAR | MU_WRDSF_NOCMD |
 		    MU_WRDSF_DELIM | MU_WRDSF_WS))
     {
@@ -369,6 +238,99 @@ cb_onerror (void *data, mu_config_value_t *val)
   mu_wordsplit_free (&ws);
   return 0;
 }
+
+static void
+cli_mailbox_ownership (struct mu_parseopt *po, struct mu_option *opt,
+		       char const *arg)
+{
+  if (set_mailbox_ownership_list (arg))
+    exit (po->po_exit_error);
+}
+
+static void
+cli_onerror (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (set_onerror_action (arg))
+    exit (po->po_exit_error);
+}
+
+static struct mu_option movemail_options[] = {
+  { "preserve", 'p', NULL, MU_OPTION_DEFAULT,
+    N_("preserve the source mailbox"),
+    mu_c_bool, &preserve_mail },
+  { "keep-messages", 0, NULL, MU_OPTION_ALIAS },
+  
+  { "reverse",  'r', NULL, MU_OPTION_DEFAULT,
+    N_("reverse the sorting order"),
+    mu_c_bool, &reverse_order },
+  
+  { "emacs",      0, NULL, MU_OPTION_DEFAULT,
+    N_("output information used by Emacs rmail interface"),
+    mu_c_bool, &emacs_mode },
+  
+  { "uidl",     'u', NULL, MU_OPTION_DEFAULT,
+    N_("use UIDLs to avoid downloading the same message twice"),
+    mu_c_bool, &uidl_option },
+  
+  { "verbose",  'v', NULL, MU_OPTION_DEFAULT,
+    N_("increase verbosity level"),
+    mu_c_incr, &verbose_option },
+  
+  { "owner",    'P', N_("MODELIST"), MU_OPTION_DEFAULT,
+    N_("control mailbox ownership"),
+    mu_c_string, cli_mailbox_ownership },
+  
+  { "ignore-errors", 0, NULL, MU_OPTION_DEFAULT,
+    N_("try to continue after errors"),
+    mu_c_bool, &ignore_errors },
+  
+  { "onerror",       0, N_("KW[,KW...]"), MU_OPTION_DEFAULT,
+    N_("what to do on errors"),
+    mu_c_string, NULL, cli_onerror },
+  
+  { "program-id",    0, N_("FMT"), MU_OPTION_DEFAULT,
+    N_("set program identifier for diagnostics (default: program name)"),
+    mu_c_string, &program_id_option },
+  
+  { "max-messages",  0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("process at most NUMBER messages"),
+    mu_c_size, &max_messages_option },
+  
+  { "notify",        0, NULL,   MU_OPTION_DEFAULT,
+    N_("enable biff notification"),
+    mu_c_bool, &notify },
+
+  MU_OPTION_END
+}, *options[] = { movemail_options, NULL };
+
+static int
+cb_mailbox_ownership (void *data, mu_config_value_t *val)
+{
+  int i;
+  
+  if (val->type == MU_CFG_STRING)
+    set_mailbox_ownership_list (val->v.string);
+		
+  if (mu_cfg_assert_value_type (val, MU_CFG_LIST))
+    return 1;
+
+  for (i = 0; i < val->v.arg.c; i++)
+    {
+      if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
+	return 1;
+      if (set_mailbox_ownership (val->v.arg.v[i].v.string))
+	return 1;
+    }
+  return 0;
+}
+
+static int
+cb_onerror (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  return set_onerror_action (val->v.string);
+}
   
 struct mu_cfg_param movemail_cfg_param[] = {
   { "preserve", mu_c_bool, &preserve_mail, 0, NULL,
@@ -406,15 +368,20 @@ struct mu_cfg_param movemail_cfg_param[] = {
        "Setting onerror=abort reverts to the default behavior.") },
   { NULL }
 };
-
 
-static const char *movemail_capa[] = {
-  "mailutils",
-  "common",
+struct mu_cli_setup cli = {
+  options,
+  movemail_cfg_param,
+  N_("GNU movemail -- move messages across mailboxes."),
+  N_("inbox-url destfile [POP-password]")
+};
+
+static char *movemail_capa[] = {
   "debug",
   "locking",
   "mailbox",
   "auth",
+  "tls",
   NULL 
 };
 
@@ -863,7 +830,6 @@ set_program_id (const char *source_name, const char *dest_name)
 int
 main (int argc, char **argv)
 {
-  int index;
   size_t total;
   int rc = 0;
   char *source_name, *dest_name;
@@ -880,16 +846,8 @@ main (int argc, char **argv)
 
   /* argument parsing */
   
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, movemail_capa, movemail_cfg_param, 
-		   argc, argv, 0, &index, NULL))
-    exit (1);
-
-  argc -= index;
-  argv += index;
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv);
 
   if (argc < 2 || argc > 3)
     {
diff --git a/readmsg/Makefile.am b/readmsg/Makefile.am
index 66ffef6..57c9dc3 100644
--- a/readmsg/Makefile.am
+++ b/readmsg/Makefile.am
@@ -23,7 +23,7 @@ bin_PROGRAMS = readmsg
 readmsg_SOURCES = readmsg.c msglist.c readmsg.h
 
 readmsg_LDADD =\
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/readmsg/readmsg.c b/readmsg/readmsg.c
index 794c0f1..bbbabf5 100644
--- a/readmsg/readmsg.c
+++ b/readmsg/readmsg.c
@@ -20,7 +20,7 @@
 #endif
 
 #include "readmsg.h"
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 #include "mu_umaxtostr.h"
 
 #define WEEDLIST_SEPARATOR " :,"
@@ -30,41 +30,6 @@ static void print_header (mu_message_t, int, int, char **);
 static void print_body (mu_message_t);
 static int  string_starts_with (const char * s1, const char *s2);
 
-static char doc[] = N_("GNU readmsg -- print messages.");
-static error_t readmsg_parse_opt  (int key, char *arg, struct argp_state *astate);
-
-static struct argp_option options[] = 
-{
-  { "debug", 'd', 0, 0, N_("display debugging information"), 1 },
-  { "header", 'h', 0, 0, N_("display entire header"), 1 },
-  { "weedlist", 'w', N_("LIST"), 0,
-    N_("list of header names separated by whitespace or commas"), 1 },
-  { "folder", 'f', N_("FOLDER"), 0, N_("folder to use"), 1 },
-  { "no-header", 'n', 0, 0, N_("exclude all headers"), 1 },
-  { "form-feeds", 'p', 0, 0, N_("output formfeeds between messages"), 1 },
-  { "show-all-match", 'a', NULL, 0,
-    N_("print all messages matching pattern, not only the first"), 1 },
-  {0, 0, 0, 0}
-};
-
-static struct argp argp = {
-  options,
-  readmsg_parse_opt,
-  NULL,
-  doc,
-  NULL,
-  NULL, NULL
-};
-
-static const char *readmsg_argp_capa[] = {
-  "mailutils",
-  "common",
-  "debug",
-  "mailbox",
-  "locking",
-  NULL
-};
-
 int dbug = 0;
 const char *mailbox_name = NULL;
 const char *weedlist = NULL;
@@ -73,57 +38,30 @@ int all_header = 0;
 int form_feed = 0;
 int show_all = 0;
 
-static error_t
-readmsg_parse_opt (int key, char *arg, struct argp_state *astate)
+static struct mu_option readmsg_options[] = 
 {
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case 'd':
-      dbug++;
-      break;
-
-    case 'h':
-      mu_argp_node_list_new (lst, "header", "yes");
-      break;
-
-    case 'f':
-      mu_argp_node_list_new (lst, "folder", arg);
-      break;
-
-    case 'w':
-      mu_argp_node_list_new (lst, "weedlist", arg);
-      break;
-
-    case 'n':
-      mu_argp_node_list_new (lst, "no-header", "yes");
-      break;
-
-    case 'p':
-      mu_argp_node_list_new (lst, "form-feeds", "yes");
-      break;
-	  
-    case 'a':
-      mu_argp_node_list_new (lst, "show-all-match", "yes");
-      break;
-
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      if (dbug)
-	mu_argp_node_list_new (lst, "debug", mu_umaxtostr (0, dbug));
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+  { "debug", 'd', NULL, MU_OPTION_DEFAULT,
+    N_("display debugging information"),
+    mu_c_incr, &dbug },
+  { "header", 'h', NULL, MU_OPTION_DEFAULT,
+    N_("display entire headers"),
+    mu_c_bool, &all_header },
+  { "weedlist", 'w', N_("LIST"), MU_OPTION_DEFAULT,
+    N_("list of header names separated by whitespace or commas"),
+    mu_c_string, &weedlist },
+  { "folder", 'f', N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("folder to use"), mu_c_string, &mailbox_name },
+  { "no-header", 'n', NULL, MU_OPTION_DEFAULT,
+    N_("exclude all headers"),
+    mu_c_bool, &no_header },
+  { "form-feeds", 'p', NULL, MU_OPTION_DEFAULT,
+    N_("output formfeeds between messages"),
+    mu_c_bool, &form_feed },
+  { "show-all-match", 'a', NULL, MU_OPTION_DEFAULT,
+    N_("print all messages matching pattern, not only the first"),
+    mu_c_bool, &show_all },
+  MU_OPTION_END
+}, *options[] = { readmsg_options, NULL };
 
 struct mu_cfg_param readmsg_cfg_param[] = {
   { "debug", mu_c_int, &dbug, 0, NULL,
@@ -145,6 +83,21 @@ struct mu_cfg_param readmsg_cfg_param[] = {
   { NULL }
 };
 
+struct mu_cli_setup cli = {
+  options,
+  readmsg_cfg_param,
+  N_("GNU readmsg -- print messages."),
+  NULL
+};
+
+static char *readmsg_argp_capa[] = {
+  "debug",
+  "mailbox",
+  "locking",
+  "tls",
+  NULL
+};
+
 static int
 string_starts_with (const char * s1, const char *s2)
 {
@@ -158,7 +111,7 @@ string_starts_with (const char * s1, const char *s2)
 
   while (*p1 && *p2)
     {
-      if ((n = toupper (*p1++) - toupper (*p2++)) != 0)
+      if ((n = mu_toupper (*p1++) - mu_toupper (*p2++)) != 0)
 	break;
     }
   return (n == 0);
@@ -276,7 +229,6 @@ main (int argc, char **argv)
   int *set = NULL;
   int n = 0;
   int i;
-  int index;
   mu_mailbox_t mbox = NULL;
   struct mu_wordsplit ws;
   char **weedv;
@@ -290,15 +242,9 @@ main (int argc, char **argv)
   mu_register_all_mbox_formats ();
   mu_register_extra_formats ();
 
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, readmsg_argp_capa, readmsg_cfg_param, 
-		   argc, argv, 0, &index, NULL))
-    exit (1);
+  mu_cli_capa_register (&mu_cli_capa_tls);
 
-  argc -= index;
+  mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
 
   if (argc == 0)
     {
@@ -376,7 +322,7 @@ main (int argc, char **argv)
     }
 
   /* Build an array containing the message number.  */
-  msglist (mbox, show_all, argc, &argv[index], &set, &n);
+  msglist (mbox, show_all, argc, argv, &set, &n);
 
   for (i = 0; i < n; ++i)
     {
diff --git a/sieve/Makefile.am b/sieve/Makefile.am
index d51db0c..2a294ba 100644
--- a/sieve/Makefile.am
+++ b/sieve/Makefile.am
@@ -22,7 +22,7 @@ EXTRA_DIST = examples
 bin_PROGRAMS = sieve
 sieve_SOURCES = sieve.c
 sieve_LDADD =\
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_SIEVE}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 32a8a0b..5de8e61 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -43,64 +43,10 @@
 #include <mailutils/stream.h>
 #include <mailutils/nls.h>
 #include <mailutils/tls.h>
-
-#include "mailutils/libargp.h"
-
-static char doc[] =
-N_("GNU sieve -- a mail filtering tool.")
-"\v"
-N_("Debug flags:\n\
-  g - main parser traces\n\
-  T - mailutils traces (same as --debug-level=sieve.trace0-trace1)\n\
-  P - network protocols (same as --debug-level=sieve.=prot)\n\
-  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
-  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n");
+#include <mailutils/cli.h>
 
 #define D_DEFAULT "TPt"
 
-#define ARG_LINE_INFO 257
-#define ARG_NO_PROGRAM_NAME 258
-
-static struct argp_option options[] =
-{
-  {"no-actions", 'n', 0, 0,
-   N_("do not execute any actions, just print what would be done"), 0},
-  {"dry-run", 0, NULL, OPTION_ALIAS, NULL },
-  {"keep-going", 'k', 0, 0,
-   N_("keep on going if execution fails on a message"), 0},
-
-  {"compile-only", 'c', 0, 0,
-   N_("compile script and exit"), 0},
-
-  {"dump", 'D', 0, 0,
-   N_("compile script, dump disassembled sieve code to terminal and exit"), 0 },
-  
-  {"mbox-url", 'f', N_("MBOX"), 0,
-   N_("mailbox to sieve (defaults to user's mail spool)"), 0},
-
-  {"ticket", 't', N_("TICKET"), 0,
-   N_("ticket file for user authentication"), 0},
-
-  {"debug", 'd', N_("FLAGS"), OPTION_ARG_OPTIONAL,
-   N_("debug flags (defaults to \"" D_DEFAULT "\")"), 0},
-
-  {"verbose", 'v', NULL, 0,
-   N_("log all actions"), 0},
-
-  {"line-info", ARG_LINE_INFO, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print source location along with action logs (default)") },
-   
-  {"email", 'e', N_("ADDRESS"), 0,
-   N_("override user email address"), 0},
-  {"expression", 'E', NULL, 0,
-   N_("treat SCRIPT as Sieve program text"), 0},
-  
-  {"no-program-name", ARG_NO_PROGRAM_NAME, NULL, 0,
-   N_("do not prefix diagnostic messages with the program name"), 0},
-  
-  {0}
-};
-
 int keep_going;
 int compile_only;
 char *mbox_url;
@@ -112,17 +58,6 @@ int expression_option;
 static int sieve_print_locus = 1; /* Should the log messages include the
 				     locus */
 
-static int
-is_true_p (char *p)
-{
-  int rc;
-  if (!p)
-    return 1;
-  if ((rc = mu_true_answer_p (p)) == -1)
-    return 0;
-  return rc;
-}
-
 static void
 set_debug_level (const char *arg)
 {
@@ -164,98 +99,88 @@ set_debug_level (const char *arg)
     }
 }
 
-int
-mu_compat_printer (void *data, mu_log_level_t level, const char *buf)
+static void
+cli_dry_run (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  fputs (buf, stderr);
-  return 0;
+  sieve_debug |= MU_SIEVE_DRY_RUN;
+  verbose = 1;
 }
 
-static error_t
-parser (int key, char *arg, struct argp_state *state)
+static void
+cli_compile_and_dump (struct mu_parseopt *po, struct mu_option *opt,
+		      char const *arg)
 {
-  static mu_list_t lst;
-  
-  switch (key)
-    {
-    case 'E':
-      expression_option = 1;
-      break;
-      
-    case 'e':
-      mu_argp_node_list_new (lst, "email", arg);
-      break;
-      
-    case 'n':
-      sieve_debug |= MU_SIEVE_DRY_RUN;
-      mu_argp_node_list_new (lst, "verbose", "yes");
-      break;
-
-    case 'k':
-      mu_argp_node_list_new (lst, "keep-going", "yes");
-      break;
-
-    case 'c':
-      compile_only = 1;
-      break;
-
-    case 'D':
-      compile_only = 2;
-      break;
-      
-    case 'f':
-      mu_argp_node_list_new (lst, "mbox-url", arg);
-      break;
-      
-    case 't':
-      mu_argp_node_list_new (lst, "ticket", arg);
-      break;
-      
-    case 'd':
-      mu_argp_node_list_new (lst, "debug", arg ? arg : D_DEFAULT);
-      break;
-
-    case 'v':
-      mu_argp_node_list_new (lst, "verbose", "yes");
-      break;
-
-    case ARG_LINE_INFO:
-      mu_argp_node_list_new (lst, "line-info",
-			     is_true_p (arg) ? "yes" : "no");
-      break;
-
-    case ARG_NO_PROGRAM_NAME:
-      mu_log_tag = NULL;
-      break;
-      
-    case ARGP_KEY_ARG:
-      if (script)
-	argp_error (state, _("Only one SCRIPT can be specified"));
-      script = mu_tilde_expansion (arg, MU_HIERARCHY_DELIMITER, NULL);
-      break;
-
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
+  compile_only = 2;
+}
 
-  return 0;
+static void
+cli_debug (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  set_debug_level (arg);
 }
 
-static struct argp argp =
+static void
+cli_email (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  options,
-  parser,
-  N_("SCRIPT"),
-  doc
-};
+  int rc = mu_set_user_email (arg);
+  if (rc)
+    mu_parseopt_error (po, _("invalid email: %s"), mu_strerror (rc));
+}
+
+static void
+cli_no_program_name (struct mu_parseopt *po, struct mu_option *opt,
+		     char const *arg)
+{
+  mu_log_tag = NULL;
+}
+
+static struct mu_option sieve_options[] = {
+  { "no-actions", 'n', NULL, MU_OPTION_DEFAULT,
+    N_("do not execute any actions, just print what would be done"),
+    mu_c_string, NULL, cli_dry_run },
+  { "dry-run", 0, NULL, MU_OPTION_ALIAS },
+  { "keep-going", 'k', NULL, MU_OPTION_DEFAULT,
+    N_("keep on going if execution fails on a message"),
+    mu_c_bool, &keep_going },
+  { "compile-only", 'c', NULL, MU_OPTION_DEFAULT,
+    N_("compile script and exit"),
+    mu_c_bool, &compile_only },
+  { "dump", 'D', NULL, MU_OPTION_DEFAULT,
+    N_("compile script, dump disassembled sieve code to terminal and exit"),
+    mu_c_string, NULL, cli_compile_and_dump },  
+  { "mbox-url", 'f', N_("MBOX"), MU_OPTION_DEFAULT,
+    N_("mailbox to sieve (defaults to user's mail spool)"),
+    mu_c_string, &mbox_url },
+  { "ticket", 't', N_("TICKET"), MU_OPTION_DEFAULT,
+    N_("ticket file for user authentication"),
+    mu_c_string, &mu_ticket_file },
+  { "debug", 'd', N_("FLAGS"), MU_OPTION_ARG_OPTIONAL,
+    N_("debug flags (defaults to \"" D_DEFAULT "\")"),
+    mu_c_string, NULL, cli_debug },
+  { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
+    N_("log all actions"), 
+    mu_c_bool, &verbose },
+  { "line-info", 0, N_("BOOL"), MU_OPTION_DEFAULT,
+    N_("print source location along with action logs (default)"),
+    mu_c_bool, &sieve_print_locus },
+  { "email", 'e', N_("ADDRESS"), MU_OPTION_DEFAULT,
+    N_("override user email address"),
+    mu_c_string, NULL, cli_email }, 
+  { "expression", 'E', NULL, MU_OPTION_DEFAULT,
+    N_("treat SCRIPT as Sieve program text"), 
+    mu_c_bool, &expression_option },
+  { "no-program-name", 0, NULL, MU_OPTION_DEFAULT,
+    N_("do not prefix diagnostic messages with the program name"),
+    mu_c_string, NULL, cli_no_program_name },
+  MU_OPTION_END
+}, *options[] = { sieve_options, NULL };
+
+int
+mu_compat_printer (void *data, mu_log_level_t level, const char *buf)
+{
+  fputs (buf, stderr);
+  return 0;
+}
 
 
 static int 
@@ -307,18 +232,24 @@ static struct mu_cfg_param sieve_cfg_param[] = {
 };
 
 
-static const char *sieve_argp_capa[] =
-{
-  "mailutils",
-  "common",
+static char *sieve_argp_capa[] = {
   "debug",
   "mailbox",
   "locking",
   "logging",
   "mailer",
+  "tls",
+  "sieve",
   NULL
 };
 
+static struct mu_cli_setup cli = {
+  options,
+  sieve_cfg_param,
+  N_("GNU sieve -- a mail filtering tool."),
+  "SCRIPT"
+};
+
 static void
 _sieve_action_log (void *unused,
 		   mu_stream_t stream, size_t msgno,
@@ -456,25 +387,29 @@ main (int argc, char *argv[])
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mu_argp_init (NULL, NULL);
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_gocs_register ("sieve", mu_sieve_module_init);
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli_capa_register (&mu_cli_capa_sieve);
   mu_sieve_debug_init ();
   
   mu_register_all_formats ();
 
-  if (mu_app_init (&argp, sieve_argp_capa, sieve_cfg_param, 
-		   argc, argv, ARGP_IN_ORDER, NULL, NULL))
-    exit (EX_USAGE);
-  
-  if (!script)
+  mu_cli (argc, argv, &cli, sieve_argp_capa, NULL, &argc, &argv);
+
+  if (argc == 0)
     {
       mu_error (_("script must be specified"));
       exit (EX_USAGE);
     }
-  
+  else if (argc == 1)
+    {
+      script = mu_tilde_expansion (argv[0], MU_HIERARCHY_DELIMITER, NULL);
+    }
+  else
+    {
+      mu_error (_("only one SCRIPT can be specified"));
+      exit (EX_USAGE);
+    }
+
   /* Sieve interpreter setup. */
   rc = mu_sieve_machine_init (&mach);
   if (rc)


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Oct 13 03:40:28 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1buact-0006eV-S4
	for mharc-commit-mailutils@gnu.org; Thu, 13 Oct 2016 03:40:27 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39392)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1buacq-0006bn-9z
	for commit-mailutils@gnu.org; Thu, 13 Oct 2016 03:40:26 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1buaco-00079I-8w
	for commit-mailutils@gnu.org; Thu, 13 Oct 2016 03:40:24 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:53278)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1buaco-00079C-5R
	for commit-mailutils@gnu.org; Thu, 13 Oct 2016 03:40:22 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id C861F220168; Thu, 13 Oct 2016 07:40:21 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-771-gd4a938f
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d56b82437f909ff323d9cd87f2ed9f04322f9966
X-Git-Newrev: d4a938f6d533981a77ddd55972e4c98b016d03d3
Message-Id: <20161013074021.C861F220168@vcs.savannah.gnu.org>
Date: Thu, 13 Oct 2016 07:40:21 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 13 Oct 2016 07:40:26 -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=d4a938f6d533981a77ddd55972e4c98b016d03d3

The branch, master has been updated
       via  d4a938f6d533981a77ddd55972e4c98b016d03d3 (commit)
       via  af83aaff0e41587fcdbe78983b6e116e442f17a1 (commit)
      from  d56b82437f909ff323d9cd87f2ed9f04322f9966 (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 d4a938f6d533981a77ddd55972e4c98b016d03d3
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 13 10:38:33 2016 +0300

    Bugfixes in libmailutils/opt/opt.c

commit af83aaff0e41587fcdbe78983b6e116e442f17a1
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Oct 12 11:30:32 2016 +0300

    Fix some incompatibilities in the previous commit.
    
    * dotlock/dotlock.c (force): Change type to unsigned.
    Provide default value for --force.
    (cli): Set exit codes and extra docstring.
    
    * include/mailutils/cli.h (mu_cli_setup): New members: prog_extra_doc,
    ex_usage, ex_config.
    * include/mailutils/opt.h (mu_parseopt_getcolumn)
    (mu_parseopt_fmt_text): New prototypes.
    * libmailutils/cli/cli.c (extra_help_hook): New hook.
    (mu_cli): Set up customized exit codes.
    Pass pointer to struct mu_cli_setup in hints.data.
    All uses changed.
    Set up help hook if setup->prog_extra_doc is defined.
    
    * libmailutils/opt/help.c (mu_parseopt_getcolumn): New
    function.
    (print_option_descr): Honor explicit newlines.
    (mu_parseopt_fmt_text): New function.
    
    * mimeview/mimeview.c (cli): Provide extra docs.
    * sieve/sieve.c: Likewise.

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

Summary of changes:
 dotlock/dotlock.c       |   39 ++++++++++++++++++++++++++++++---------
 include/mailutils/cli.h |   13 +++++++++----
 include/mailutils/opt.h |    3 +++
 libmailutils/cli/cli.c  |   44 +++++++++++++++++++++++++++++++++++---------
 libmailutils/opt/help.c |   28 ++++++++++++++++++++++++++++
 libmailutils/opt/opt.c  |   30 +++++++++++++++++++-----------
 mimeview/mimeview.c     |   10 +++-------
 sieve/sieve.c           |    8 +++++++-
 8 files changed, 134 insertions(+), 41 deletions(-)

diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index 0a8cfec..f0e07d6 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -31,9 +31,33 @@ static const char *file;
 static int unlock;
 static int flags;
 static int retries;
-static time_t force;
+static unsigned force;
 static int debug;
 
+static void
+cli_force (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (arg)
+    {
+      int rc;
+      char *errmsg;
+      rc = mu_str_to_c (arg, opt->opt_type, opt->opt_ptr, &errmsg);
+      if (rc)
+	{
+	  if (opt->opt_long)
+	    mu_parseopt_error (po, "--%s: %s", opt->opt_long,
+			       errmsg ? errmsg : mu_strerror (rc));
+	  else
+	    mu_parseopt_error (po, "-%c: %s", opt->opt_short,
+			       errmsg ? errmsg : mu_strerror (rc));
+	  free (errmsg);
+	  exit (po->po_exit_error);
+	}
+    }
+  else
+    *(unsigned*)opt->opt_ptr = 1;
+}
+
 static struct mu_option dotlock_options[] = {
   { "unlock", 'u', NULL, MU_OPTION_DEFAULT,
     N_("unlock"),
@@ -41,7 +65,7 @@ static struct mu_option dotlock_options[] = {
 
   { "force",  'f', N_("MINUTES"), MU_OPTION_ARG_OPTIONAL,
     N_("forcibly break an existing lock older than a certain time"),
-    mu_c_time, &force },//FIXME: Default value
+    mu_c_uint, &force, cli_force },
  
   { "retry",  'r', N_("RETRIES"), MU_OPTION_ARG_OPTIONAL,
     N_("retry the lock a few times"),
@@ -68,12 +92,11 @@ static struct mu_cli_setup cli = {
   options,
   dotlock_cfg_param,
   N_("GNU dotlock -- lock mail spool files."),
-  //FIXME:
-  /*
+  N_("FILE"),
   N_("Returns 0 on success, 3 if locking the file fails because\
- it's already locked, and 1 if some other kind of error occurred.");
-  */
-  N_("FILE")
+ it's already locked, and 1 if some other kind of error occurred."),
+  MU_DL_EX_ERROR,
+  MU_DL_EX_ERROR
 };
 
 
@@ -99,8 +122,6 @@ main (int argc, char *argv[])
   if (setegid (usergid) < 0)
     return MU_DL_EX_ERROR;
 
-  /* FIXME: Force mu_cli to exit with MU_DL_EX_ERROR on errors? */
-
   mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   switch (argc)
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index 2943bc4..8f31f7b 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -39,10 +39,15 @@ void mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits);
 
 struct mu_cli_setup
 {
-  struct mu_option **optv;
-  struct mu_cfg_param *cfg;
-  char *prog_doc;
-  char *prog_args;
+  struct mu_option **optv;     /* Command-line options */
+  struct mu_cfg_param *cfg;    /* Configuration parameters */
+  char *prog_doc;              /* Program documentation string */
+  char *prog_args;             /* Program arguments string */
+  char *prog_extra_doc;        /* Extra documentation.  This will be
+				  displayed after options. */
+  int ex_usage;                /* If not 0, exit code on usage errors */
+  int ex_config;               /* If not 0, exit code on configuration
+				  errors */
 };
 
 void mu_version_func (struct mu_parseopt *po, FILE *stream);
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index cc56342..68204b9 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -168,6 +168,9 @@ void mu_parseopt_error (struct mu_parseopt *po, char const *fmt, ...);
 int mu_parseopt_apply (struct mu_parseopt *p);
 void mu_parseopt_free (struct mu_parseopt *p);
 
+unsigned mu_parseopt_getcolumn (const char *name);
+void mu_parseopt_fmt_text (const char *text, size_t col);
+
 void mu_option_describe_options (struct mu_option **optbuf, size_t optcnt);
 void mu_program_help (struct mu_parseopt *p);
 void mu_program_usage (struct mu_parseopt *p);
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 597ac91..a75a684 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -77,7 +77,17 @@ There is NO WARRANTY, to the extent permitted by law.\n\
 
 static char gnu_general_help_url[] =
   N_("General help using GNU software: <http://www.gnu.org/gethelp/>");
-
+
+static void
+extra_help_hook (struct mu_parseopt *po, FILE *stream)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  struct mu_cli_setup *setup = hints->data;
+  char *extra_doc = _(setup->prog_extra_doc);
+  /* FIXME: mu_parseopt help output should get FILE * argument */
+  mu_parseopt_fmt_text (extra_doc, 0);
+  fputc ('\n', stdout);
+}
 
 static void
 change_progname (struct mu_parseopt *po, struct mu_option *opt,
@@ -235,8 +245,12 @@ show_config_help (struct mu_parseopt *po, struct mu_option *opt,
   mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
 					dummy_include_param, NULL);
   if (hints->data)
-    mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
-					  hints->data, NULL);
+    {
+      struct mu_cli_setup *setup = hints->data;
+      mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
+					    setup->cfg, NULL);
+    }
+  
   mu_cfg_format_container (stream, cont);
   mu_config_destroy_container (&cont);
       
@@ -325,6 +339,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   struct mu_cfg_parse_hints hints;
   struct mu_option **optv;
   mu_list_t com_list;
+
+  /* Set up defaults */
+  if (setup->ex_usage == 0)
+    setup->ex_usage = EX_USAGE;
+  if (setup->ex_config == 0)
+    setup->ex_config = EX_CONFIG;
   
   /* Set program name */
   mu_set_program_name (argv[0]);
@@ -346,7 +366,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   hints.flags |= MU_CFG_PARSE_PROGRAM;
   hints.program = (char*) mu_program_name;
 
-  hints.data = setup->cfg;
+  hints.data = setup;
   
   /* Initialize po */
   if (setup->prog_doc)
@@ -376,10 +396,16 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   po.po_version_hook = mu_version_func;
   flags |= MU_PARSEOPT_VERSION_HOOK;
 
+  if (setup->prog_extra_doc)
+    {
+      po.po_help_hook = extra_help_hook;
+      flags |= MU_PARSEOPT_HELP_HOOK;
+    }
+  
   po.po_data = &hints;
   flags |= MU_PARSEOPT_DATA;
 
-  po.po_exit_error = EX_USAGE;
+  po.po_exit_error = setup->ex_usage;
 
   optv = init_options (capa, setup, &com_list);
 
@@ -398,13 +424,13 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
     mu_parseopt_error (&po, "%s", _("unexpected arguments"));
 
   if (mu_cfg_parse_config (&parse_tree, &hints))
-    exit (EX_CONFIG);
+    exit (setup->ex_config);
 
   if (mu_cfg_tree_reduce (parse_tree, &hints, setup->cfg, data))
-    exit (EX_CONFIG);
+    exit (setup->ex_config);
 
-  if (mu_cfg_error_count) //FIXME
-    exit (EX_CONFIG);
+  if (mu_cfg_error_count)
+    exit (setup->ex_config);
   
   mu_parseopt_apply (&po);
 
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index f91c126..96ab1dc 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -63,6 +63,23 @@ static struct usage_var
   { NULL }
 };
 
+unsigned
+mu_parseopt_getcolumn (const char *name)
+{
+  struct usage_var *p;
+  unsigned retval = 0;
+  for (p = usage_var; p->name; p++)
+    {
+      if (strcmp (p->name, name) == 0)
+	{
+	  if (p->valptr)
+	    retval = *p->valptr;
+	  break;
+	}
+    }
+  return retval;
+}
+
 static void
 set_usage_var (struct mu_parseopt *po, char const *id)
 {
@@ -195,6 +212,11 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
 	      if (descr[i] == 0)
 		break;
 	    }
+	  else if (descr[i] == '\n')
+	    {
+	      s = i;
+	      break;
+	    }
 	}
       fwrite (descr, 1, s, stdout);
       fputc ('\n', stdout);
@@ -207,6 +229,12 @@ print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
     }
 }
 
+void
+mu_parseopt_fmt_text (const char *text, size_t col)
+{
+  print_option_descr (text, col, rmargin);
+}
+
 
 static size_t
 print_opt_arg (struct mu_option *opt, int delim)
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 37c22ab..0e31a47 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -34,21 +34,29 @@ optcmp (const void *a, const void *b)
 {
   struct mu_option const *ap = *(struct mu_option const **)a;
   struct mu_option const *bp = *(struct mu_option const **)b;
-
+  
   while (ap->opt_flags & MU_OPTION_ALIAS)
     ap--;
   while (bp->opt_flags & MU_OPTION_ALIAS)
     bp--;
-  
-  if (MU_OPTION_IS_VALID_SHORT_OPTION (ap)
-      && MU_OPTION_IS_VALID_SHORT_OPTION (bp))
-    return ap->opt_short - bp->opt_short;
-  if (MU_OPTION_IS_VALID_LONG_OPTION (ap)
+
+  if (!MU_OPTION_IS_VALID_SHORT_OPTION (ap)
+      && MU_OPTION_IS_VALID_LONG_OPTION (ap)
+      && !MU_OPTION_IS_VALID_SHORT_OPTION (bp)
       && MU_OPTION_IS_VALID_LONG_OPTION (bp))
-    return strcmp (ap->opt_long, bp->opt_long);
-  if (MU_OPTION_IS_VALID_LONG_OPTION (ap))
-    return 1;
-  return -1;
+    return strcasecmp (ap->opt_long, bp->opt_long);
+  else
+    {
+      char afirst, bfirst;
+      int res;
+
+      afirst = ap->opt_short ? ap->opt_short : ap->opt_long ? *ap->opt_long : 0;
+      bfirst = bp->opt_short ? bp->opt_short : bp->opt_long ? *bp->opt_long : 0;
+
+      res = mu_tolower (afirst) - mu_tolower (bfirst);
+      
+      return res ? res : afirst - bfirst;
+    }
 }
 
 /* Sort a group of options in OPTBUF, starting at index START (first
@@ -545,7 +553,7 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
   /* Ensure sane start of options.  This is necessary, in particular,
      because optcmp backs up until it finds an element with cleared
      MU_OPTION_ALIAS bit. */
-  po->po_optv[0]->opt_flags &= MU_OPTION_ALIAS;
+  po->po_optv[0]->opt_flags &= ~MU_OPTION_ALIAS;
   if (!(flags & MU_PARSEOPT_NO_SORT))
     {
       /* Sort the options */
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 0100f50..011c6af 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -144,15 +144,11 @@ struct mu_cli_setup cli = {
   options,
   mimeview_cfg_param,
   N_("GNU mimeview -- display files, using mailcap mechanism."),
-  //FIXME:
-  /*
-  N_("Default mime.types file is ") DEFAULT_CUPS_CONFDIR "/mime.types"
-N_("\n\nDebug flags are:\n\
+  N_("FILE [FILE ...]"),
+  N_("Debug flags are:\n\
   g - Mime.types parser traces\n\
   l - Mime.types lexical analyzer traces\n\
-  0-9 - Set debugging level\n");
-  */
-  N_("FILE [FILE ...]")
+  0-9 - Set debugging level\n")
 };
 
 static char *capa[] = {
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 5de8e61..2627bd1 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -247,7 +247,13 @@ static struct mu_cli_setup cli = {
   options,
   sieve_cfg_param,
   N_("GNU sieve -- a mail filtering tool."),
-  "SCRIPT"
+  "SCRIPT",
+  N_("Debug flags:\n\
+  g - main parser traces\n\
+  T - mailutils traces (same as --debug-level=sieve.trace0-trace1)\n\
+  P - network protocols (same as --debug-level=sieve.=prot)\n\
+  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
+  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n")
 };
 
 static void


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 15 03:21:47 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bvJHv-0001Rf-1n
	for mharc-commit-mailutils@gnu.org; Sat, 15 Oct 2016 03:21:47 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42586)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvJHo-0001RW-W6
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 03:21:46 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvJHi-0003k4-6X
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 03:21:39 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:60328)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvJHi-0003jx-0n
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 03:21:34 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id E0AAE220168; Sat, 15 Oct 2016 07:21:33 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-773-g2a28ab5
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d4a938f6d533981a77ddd55972e4c98b016d03d3
X-Git-Newrev: 2a28ab58762f9ae9cd00ca3e467ee6f90f241201
Message-Id: <20161015072133.E0AAE220168@vcs.savannah.gnu.org>
Date: Sat, 15 Oct 2016 07:21:33 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 15 Oct 2016 07:21:46 -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=2a28ab58762f9ae9cd00ca3e467ee6f90f241201

The branch, master has been updated
       via  2a28ab58762f9ae9cd00ca3e467ee6f90f241201 (commit)
       via  06c13b3498a236a518df76bdb1b9895540c1df3b (commit)
      from  d4a938f6d533981a77ddd55972e4c98b016d03d3 (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 2a28ab58762f9ae9cd00ca3e467ee6f90f241201
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 15 10:11:23 2016 +0300

    Rewrite parseopt help routines using wordwrap streams
    
    * include/mailutils/stream.h (MU_IOCTL_WORDWRAP_SET_NEXT_MARGIN)
    (MU_IOCTL_WORDWRAP_GET_OFFSET): New opcodes.
    * libmailutils/stream/wordwrap.c (_wordwrap_flush_line): Replace
    whitespace-only lines with single newline on output.
    (_wordwrap_flush): Fix condition.
    (set_margin): Bugfix.
    (_wordwrap_ctl): Handle new opcodes.
    
    * include/mailutils/cli.h (mu_version_func): Change signature.
    * include/mailutils/opt.h (mu_parseopt) <po_help_hook>
    <po_version_hook>: Change signature.
    (mu_parseopt_fmt_text): Remove.
    (mu_option_describe_options, mu_program_help)
    (mu_program_usage): Change signature.
    (mu_program_version): New prototype.
    * libmailutils/cli/cli.c (mu_version_func): Take mu_stream_t as
    2nd argument.  Use mu_stream_printf for output.
    (extra_help_hook): Likewise.
    * libmailutils/opt/help.c: Rewrite using wordwrap streams.
    * libmailutils/opt/opt.c (fn_help, fn_usage, fn_version): Update.
    * libmailutils/tests/parseopt.c (version_hook): Write to mu_stream_t.
    
    * libmailutils/tests/parseopt_help00.at: Fix expected output.
    * libmailutils/tests/parseopt_help01.at: Likewise.
    * libmailutils/tests/parseopt_help02.at: Likewise.
    * libmailutils/tests/parseopt_help03.at: Likewise.
    * libmailutils/tests/parseopt_help04.at: Likewise.
    * libmailutils/tests/parseopt_help05.at: Likewise.
    * libmailutils/tests/parseopt_help06.at: Likewise.
    * libmailutils/tests/parseopt_help07.at: Likewise.
    * libmailutils/tests/parseopt_help08.at: Likewise.
    * libmailutils/tests/parseopt_help09.at: Likewise.
    * libmailutils/tests/parseopt_help10.at: Likewise.
    * libmailutils/tests/parseopt_help11.at: Likewise.

commit 06c13b3498a236a518df76bdb1b9895540c1df3b
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Fri Oct 14 23:15:16 2016 +0300

    Implement simple word-wrapping stream
    
    * include/mailutils/stream.h (MU_IOCTL_WORDWRAPSTREAM): New ioctl.
    (mu_wordwrap_stream_create): New proto.
    * libmailutils/stream/Makefile.am: add wordwrap.c
    * libmailutils/stream/wordwrap.c: New file.
    * libmailutils/tests/Makefile.am: Add new testcases.
    * libmailutils/tests/testsuite.at: Include new testcases.
    * libmailutils/tests/wordwrap.c: New file.
    * libmailutils/tests/wordwrap00.at: New file.
    * libmailutils/tests/wordwrap01.at: New file.
    * libmailutils/tests/wordwrap02.at: New file.
    * libmailutils/tests/wordwrap03.at: New file.

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

Summary of changes:
 include/mailutils/cli.h                            |    2 +-
 include/mailutils/opt.h                            |   14 +-
 include/mailutils/stream.h                         |   13 +-
 libmailutils/cli/cli.c                             |   25 +-
 libmailutils/opt/help.c                            |  325 ++++++++----------
 libmailutils/opt/opt.c                             |    7 +-
 libmailutils/stream/Makefile.am                    |    1 +
 libmailutils/stream/wordwrap.c                     |  354 ++++++++++++++++++++
 libmailutils/tests/Makefile.am                     |    7 +-
 libmailutils/tests/parseopt.c                      |    4 +-
 libmailutils/tests/parseopt_help00.at              |    2 +-
 libmailutils/tests/parseopt_help01.at              |    4 +-
 libmailutils/tests/parseopt_help02.at              |    2 +-
 libmailutils/tests/parseopt_help03.at              |    2 +-
 libmailutils/tests/parseopt_help04.at              |    2 +-
 libmailutils/tests/parseopt_help05.at              |    2 +-
 libmailutils/tests/parseopt_help06.at              |    2 +-
 libmailutils/tests/parseopt_help07.at              |    2 +-
 libmailutils/tests/parseopt_help08.at              |    2 +-
 libmailutils/tests/parseopt_help09.at              |    4 +-
 libmailutils/tests/parseopt_help10.at              |    4 +-
 libmailutils/tests/parseopt_help11.at              |    2 +-
 libmailutils/tests/testsuite.at                    |    6 +
 libmailutils/tests/wordwrap.c                      |  162 +++++++++
 libmailutils/tests/wordwrap00.at                   |   45 +++
 libmailutils/tests/wordwrap01.at                   |   37 ++
 libmailutils/tests/wordwrap02.at                   |   33 ++
 .../tests/{parseopt25.at => wordwrap03.at}         |   15 +-
 28 files changed, 849 insertions(+), 231 deletions(-)
 create mode 100644 libmailutils/stream/wordwrap.c
 create mode 100644 libmailutils/tests/wordwrap.c
 create mode 100644 libmailutils/tests/wordwrap00.at
 create mode 100644 libmailutils/tests/wordwrap01.at
 create mode 100644 libmailutils/tests/wordwrap02.at
 copy libmailutils/tests/{parseopt25.at => wordwrap03.at} (77%)

diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index 8f31f7b..097759e 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -50,7 +50,7 @@ struct mu_cli_setup
 				  errors */
 };
 
-void mu_version_func (struct mu_parseopt *po, FILE *stream);
+void mu_version_func (struct mu_parseopt *po, mu_stream_t stream);
 void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
 	     char **capa, void *data,
 	     int *ret_argc, char ***ret_argv);
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 68204b9..7752117 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -131,9 +131,8 @@ struct mu_parseopt
   char const *po_package_url;
   char const *po_extra_info;
 
-  /* FIXME: should these take mu_stream_t ?*/
-  void (*po_help_hook) (struct mu_parseopt *po, FILE *stream); 
-  void (*po_version_hook) (struct mu_parseopt *po, FILE *stream);
+  void (*po_help_hook) (struct mu_parseopt *po, mu_stream_t stream); 
+  void (*po_version_hook) (struct mu_parseopt *po, mu_stream_t stream);
   
   /* Output data */
   int po_ind;                      /* Index of the next option */
@@ -169,11 +168,12 @@ int mu_parseopt_apply (struct mu_parseopt *p);
 void mu_parseopt_free (struct mu_parseopt *p);
 
 unsigned mu_parseopt_getcolumn (const char *name);
-void mu_parseopt_fmt_text (const char *text, size_t col);
 
-void mu_option_describe_options (struct mu_option **optbuf, size_t optcnt);
-void mu_program_help (struct mu_parseopt *p);
-void mu_program_usage (struct mu_parseopt *p);
+void mu_option_describe_options (mu_stream_t str,
+				 struct mu_option **optbuf, size_t optcnt);
+void mu_program_help (struct mu_parseopt *p, mu_stream_t str);
+void mu_program_usage (struct mu_parseopt *p, mu_stream_t str);
+void mu_program_version (struct mu_parseopt *po, mu_stream_t str);
 
 void mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
 			  char const *arg);
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index d870306..4f0ef69 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -78,7 +78,8 @@ enum mu_buffer_type
 				       always returns the topmost substream.
 				    */
 #define MU_IOCTL_TLSSTREAM       13 /* TLS stream */
-
+#define MU_IOCTL_WORDWRAPSTREAM  14 /* Word-wrapper stream */
+  
   /* Opcodes common for various families */
 #define MU_IOCTL_OP_GET 0
 #define MU_IOCTL_OP_SET 1  
@@ -206,6 +207,13 @@ enum mu_buffer_type
 #define MU_TRANSPORT_VALID_TYPE(n) \
   ((n) == MU_TRANSPORT_INPUT || (n) == MU_TRANSPORT_OUTPUT)
 
+/* Word wrapper streams */
+#define MU_IOCTL_WORDWRAP_GET_MARGIN      0
+#define MU_IOCTL_WORDWRAP_SET_MARGIN      1  
+#define MU_IOCTL_WORDWRAP_MOVE_MARGIN     2
+#define MU_IOCTL_WORDWRAP_SET_NEXT_MARGIN 3
+#define MU_IOCTL_WORDWRAP_GET_OFFSET      4
+
 struct mu_nullstream_pattern
 {
   char *pattern;
@@ -360,6 +368,9 @@ int mu_rdcache_stream_create (mu_stream_t *pstream, mu_stream_t transport,
 			      int flags);
 
 int mu_nullstream_create (mu_stream_t *pref, int flags);
+
+int mu_wordwrap_stream_create (mu_stream_t *pstream, mu_stream_t transport,
+			       size_t left_margin, size_t right_margin);
   
 #ifdef __cplusplus
 }
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index a75a684..5b8507a 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -53,40 +53,37 @@ const char mu_version_copyright[] =
   "Copyright %s 2007-2016 Free Software Foundation, inc.";
 
 void
-mu_version_func (struct mu_parseopt *po, FILE *stream)
+mu_version_func (struct mu_parseopt *po, mu_stream_t stream)
 {
 #ifdef GIT_DESCRIBE
-  fprintf (stream, "%s (%s) %s [%s]\n",
-	   mu_program_name, PACKAGE_NAME, PACKAGE_VERSION, GIT_DESCRIBE);
+  mu_stream_printf (stream, "%s (%s) %s [%s]\n",
+		    mu_program_name, PACKAGE_NAME, PACKAGE_VERSION,
+		    GIT_DESCRIBE);
 #else
-  fprintf (stream, "%s (%s) %s\n", mu_program_name,
-	   PACKAGE_NAME, PACKAGE_VERSION);
+  mu_stream_printf (stream, "%s (%s) %s\n", mu_program_name,
+		    PACKAGE_NAME, PACKAGE_VERSION);
 #endif
   /* TRANSLATORS: Translate "(C)" to the copyright symbol
      (C-in-a-circle), if this symbol is available in the user's
      locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
-  fprintf (stream, mu_version_copyright, _("(C)"));
-  fputs (_("\
+  mu_stream_printf (stream, mu_version_copyright, _("(C)"));
+  mu_stream_printf (stream, _("\
 \n\
 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
 There is NO WARRANTY, to the extent permitted by law.\n\
 \n\
-"),
-	 stream);
+"));
 }
 
 static char gnu_general_help_url[] =
   N_("General help using GNU software: <http://www.gnu.org/gethelp/>");
 
 static void
-extra_help_hook (struct mu_parseopt *po, FILE *stream)
+extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
 {
   struct mu_cfg_parse_hints *hints = po->po_data;
   struct mu_cli_setup *setup = hints->data;
-  char *extra_doc = _(setup->prog_extra_doc);
-  /* FIXME: mu_parseopt help output should get FILE * argument */
-  mu_parseopt_fmt_text (extra_doc, 0);
-  fputc ('\n', stdout);
+  mu_stream_printf (stream, "%s\n", _(setup->prog_extra_doc));
 }
 
 static void
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index 96ab1dc..c4ef8d3 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -27,6 +27,7 @@
 #include <mailutils/cctype.h>
 #include <mailutils/nls.h>
 #include <mailutils/wordsplit.h>
+#include <mailutils/stream.h>
 
 unsigned short_opt_col = 2;
 unsigned long_opt_col = 6;
@@ -184,91 +185,69 @@ init_usage_vars (struct mu_parseopt *po)
 
   mu_wordsplit_free (&ws);
 }
-
-static int
-indent (int start, int col)
+
+static void
+set_margin (mu_stream_t str, unsigned margin)
 {
-  for (; start < col; start++)
-    putchar (' ');
-  return start;
+  mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		   MU_IOCTL_WORDWRAP_SET_MARGIN,
+		   &margin);
 }
-
 static void
-print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
+set_next_margin (mu_stream_t str, unsigned margin)
 {
-  while (*descr)
-    {
-      size_t s = 0;
-      size_t i;
-      size_t width = rmargin - lmargin;
-      
-      for (i = 0; ; i++)
-	{
-	  if (descr[i] == 0 || descr[i] == ' ' || descr[i] == '\t')
-	    {
-	      if (i > width)
-		break;
-	      s = i;
-	      if (descr[i] == 0)
-		break;
-	    }
-	  else if (descr[i] == '\n')
-	    {
-	      s = i;
-	      break;
-	    }
-	}
-      fwrite (descr, 1, s, stdout);
-      fputc ('\n', stdout);
-      descr += s;
-      if (*descr)
-	{
-	  indent (0, lmargin);
-	  descr++;
-	}
-    }
+  mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		   MU_IOCTL_WORDWRAP_SET_NEXT_MARGIN,
+		   &margin);
 }
-
-void
-mu_parseopt_fmt_text (const char *text, size_t col)
+static void
+get_offset (mu_stream_t str, unsigned *offset)
 {
-  print_option_descr (text, col, rmargin);
+  mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		   MU_IOCTL_WORDWRAP_GET_OFFSET,
+		   offset);
+}
+static void
+move_margin (mu_stream_t str, int margin)
+{
+  mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		   MU_IOCTL_WORDWRAP_MOVE_MARGIN,
+		   &margin);
 }
-
 
-static size_t
-print_opt_arg (struct mu_option *opt, int delim)
+static void
+print_opt_arg (mu_stream_t str, struct mu_option *opt, int delim)
 {
-  int w = 0;
   if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
     {
       if (delim == '=')
-	w = printf ("[=%s]", gettext (opt->opt_arg));
+	mu_stream_printf (str, "[=%s]", gettext (opt->opt_arg));
       else
-	w = printf ("[%s]", gettext (opt->opt_arg));
+	mu_stream_printf (str, "[%s]", gettext (opt->opt_arg));
     }
   else
-    w = printf ("%c%s", delim, gettext (opt->opt_arg));
-  return w;
+    mu_stream_printf (str, "%c%s", delim, gettext (opt->opt_arg));
 }
 
 static size_t
-print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
+print_option (mu_stream_t str,
+	      struct mu_option **optbuf, size_t optcnt, size_t num,
 	      int *argsused)
 {
   struct mu_option *opt = optbuf[num];
   size_t next, i;
   int delim;
-  int w;
+  int first_option = 1;
+  int first_long_option = 1;
   
   if (MU_OPTION_IS_GROUP_HEADER (opt))
     {
       if (num)
-	putchar ('\n');
+	mu_stream_printf (str, "\n");
       if (opt->opt_doc[0])
 	{
-	  indent (0, header_col);
-	  print_option_descr (gettext (opt->opt_doc), header_col, rmargin);
+	  set_margin (str, header_col);
+	  mu_stream_printf (str, "%s", gettext (opt->opt_doc));
 	}
       return num + 1;
     }
@@ -281,22 +260,19 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
   if (opt->opt_flags & MU_OPTION_HIDDEN)
     return next;
 
-  w = 0;
+  set_margin (str, short_opt_col); 
   for (i = num; i < next; i++)
     {
       if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]))
 	{
-	  if (w == 0)
-	    {
-	      indent (0, short_opt_col);
-	      w = short_opt_col;
-	    }
+	  if (first_option)
+	    first_option = 0;
 	  else
-	    w += printf (", ");
-	  w += printf ("-%c", optbuf[i]->opt_short);
+	    mu_stream_printf (str, ", ");
+	  mu_stream_printf (str, "-%c", optbuf[i]->opt_short);
 	  delim = ' ';
 	  if (opt->opt_arg && dup_args)
-	    w += print_opt_arg (opt, delim);
+	    print_opt_arg (str, opt, delim);
 	}
     }
 
@@ -304,19 +280,24 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
     {
       if (MU_OPTION_IS_VALID_LONG_OPTION (optbuf[i]))
 	{
-	  if (w == 0)
+	  if (first_option)
+	    first_option = 0;
+	  else
+	    mu_stream_printf (str, ", ");
+
+	  if (first_long_option)
 	    {
-	      indent (0, short_opt_col);
-	      w = short_opt_col;
+	      unsigned off;
+	      get_offset (str, &off);
+	      if (off < long_opt_col)
+		set_margin (str, long_opt_col);
+	      first_long_option = 0;
 	    }
-	  else
-	    w += printf (", ");
-	  if (i == num)
-	    w = indent (w, long_opt_col);
-  	  w += printf ("--%s", optbuf[i]->opt_long);
+	  
+  	  mu_stream_printf (str, "--%s", optbuf[i]->opt_long);
 	  delim = '=';
 	  if (opt->opt_arg && dup_args)
-	    w += print_opt_arg (opt, delim);
+	    print_opt_arg (str, opt, delim);
 	}
     }
   
@@ -324,70 +305,87 @@ print_option (struct mu_option **optbuf, size_t optcnt, size_t num,
     {
       *argsused = 1;
       if (!dup_args)
-	w += print_opt_arg (opt, delim);
-    }
-  if (w >= opt_doc_col)
-    {
-      putchar ('\n');
-      w = 0;
+	print_opt_arg (str, opt, delim);
     }
-  indent (w, opt_doc_col);
-  print_option_descr (gettext (opt->opt_doc), opt_doc_col, rmargin);
+
+  set_margin (str, opt_doc_col);
+  mu_stream_printf (str, "%s\n", gettext (opt->opt_doc));
 
   return next;
 }
 
 void
-mu_option_describe_options (struct mu_option **optbuf, size_t optcnt)
+mu_option_describe_options (mu_stream_t str,
+			    struct mu_option **optbuf, size_t optcnt)
 {
   unsigned i;
   int argsused = 0;
 
   for (i = 0; i < optcnt; )
-    i = print_option (optbuf, optcnt, i, &argsused);
-  putchar ('\n');
+    i = print_option (str, optbuf, optcnt, i, &argsused);
+  mu_stream_printf (str, "\n");
 
   if (argsused && dup_args_note)
     {
-      print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, rmargin);
-      putchar ('\n');
+      set_margin (str, 0);
+      mu_stream_printf (str, "%s\n\n",
+			_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."));
     }
 }
 
 void
-mu_program_help (struct mu_parseopt *po)
+mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
 {
+  mu_stream_t str;
+  int rc;
+  
   init_usage_vars (po);
 
-  printf ("%s", _("Usage:"));
+  rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
+  if (rc)
+    {
+      abort ();//FIXME
+    }
+  
+  mu_stream_printf (str, "%s", _("Usage:"));
   if (po->po_prog_name)
-    printf (" %s", po->po_prog_name);
-  printf (" [%s]...", _("OPTION"));
+    mu_stream_printf (str, " %s ", po->po_prog_name);
+  move_margin (str, 0);
+  mu_stream_printf (str, "[%s]...", _("OPTION"));
   if (po->po_prog_args)
-    printf (" %s", gettext (po->po_prog_args));
-  putchar ('\n');
+    mu_stream_printf (str, " %s", gettext (po->po_prog_args));
+  mu_stream_printf (str, "\n");
   
   if (po->po_prog_doc)
-    print_option_descr (gettext (po->po_prog_doc), 0, rmargin);
-  putchar ('\n');
-
-  mu_option_describe_options (po->po_optv, po->po_optc);
+    {
+      set_margin (str, 0);
+      mu_stream_printf (str, "%s\n", gettext (po->po_prog_doc));
+    }
+  mu_stream_printf (str, "\n");
+  
+  mu_option_describe_options (str, po->po_optv, po->po_optc);
 
   if (po->po_help_hook)
-    po->po_help_hook (po, stdout);
-
+    {
+      po->po_help_hook (po, str);
+      mu_stream_printf (str, "\n");
+    }
+  
+  set_margin (str, 0);
   if (po->po_bug_address)
     /* TRANSLATORS: The placeholder indicates the bug-reporting address
        for this package.  Please add _another line_ saying
        "Report translation bugs to <...>\n" with the address for translation
        bugs (typically your translation team's web or email address).  */
-    printf (_("Report bugs to <%s>.\n"), po->po_bug_address);
+    mu_stream_printf (str, _("Report bugs to <%s>.\n"), po->po_bug_address);
 
   if (po->po_package_name && po->po_package_url)
-    printf (_("%s home page: <%s>\n"),
-	    po->po_package_name, po->po_package_url);
+    mu_stream_printf (str, _("%s home page: <%s>\n"),
+		      po->po_package_name, po->po_package_url);
   if (po->po_flags & MU_PARSEOPT_EXTRA_INFO)
-    print_option_descr (_(po->po_extra_info), 0, rmargin);
+    mu_stream_printf (str, "%s\n", _(po->po_extra_info));
+
+  mu_stream_destroy (&str);
 }
 
 static struct mu_option **option_tab;
@@ -426,41 +424,32 @@ cmpidx_long (const void *a, const void *b)
 }
 
 void
-mu_program_usage (struct mu_parseopt *po)
+mu_program_usage (struct mu_parseopt *po, mu_stream_t outstr)
 {
+  int rc;
   unsigned i;
-  unsigned n;
-  char buf[rmargin+1];
   unsigned *idxbuf;
   unsigned nidx;
 
   struct mu_option **optbuf = po->po_optv;
   size_t optcnt = po->po_optc;
-  
-#define FLUSH								\
-  do									\
-    {									\
-      buf[n] = 0;							\
-      printf ("%s\n", buf);						\
-      n = usage_indent;						\
-      if (n) memset (buf, ' ', n);					\
-    }									\
-  while (0)
-#define ADDC(c)							        \
-  do									\
-    {									\
-      if (n == rmargin) FLUSH;						\
-      buf[n++] = c;							\
-    }									\
-  while (0)
+
+  mu_stream_t str;
 
   init_usage_vars (po);
 
+  rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
+  if (rc)
+    {
+      abort ();//FIXME
+    }  
+  
   option_tab = optbuf;
   
   idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
 
-  n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"),	po->po_prog_name);
+  mu_stream_printf (str, "%s %s ", _("Usage:"),	po->po_prog_name);
+  set_next_margin (str, usage_indent);
   
   /* Print a list of short options without arguments. */
   for (i = nidx = 0; i < optcnt; i++)
@@ -470,14 +459,12 @@ mu_program_usage (struct mu_parseopt *po)
   if (nidx)
     {
       qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
-
-      ADDC ('[');
-      ADDC ('-');
+      mu_stream_printf (str, "[-");
       for (i = 0; i < nidx; i++)
 	{
-	  ADDC (optbuf[idxbuf[i]]->opt_short);
+	  mu_stream_printf (str, "%c", optbuf[idxbuf[i]]->opt_short);
 	}
-      ADDC (']');
+      mu_stream_printf (str, "%c", ']');
     }
 
   /* Print a list of short options with arguments. */
@@ -495,19 +482,10 @@ mu_program_usage (struct mu_parseopt *po)
 	{
 	  struct mu_option *opt = optbuf[idxbuf[i]];
 	  const char *arg = gettext (opt->opt_arg);
-	  size_t len = 5 + strlen (arg) + 1;
-	  
-	  if (n + len >= rmargin)
-	    FLUSH;
+	  if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
+	    mu_stream_printf (str, " [-%c[%s]]", opt->opt_short, arg);
 	  else
-	    buf[n++] = ' ';
-	  buf[n++] = '[';
-	  buf[n++] = '-';
-	  buf[n++] = opt->opt_short;
-	  buf[n++] = ' ';
-	  strcpy (&buf[n], arg);
-	  n += strlen (arg);
-	  buf[n++] = ']';
+	    mu_stream_printf (str, " [-%c %s]", opt->opt_short, arg);
 	}
     }
   
@@ -526,52 +504,41 @@ mu_program_usage (struct mu_parseopt *po)
 	{
 	  struct mu_option *opt = optbuf[idxbuf[i]];
 	  const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL;
-	  size_t len = 5 + strlen (opt->opt_long)
-	                 + (arg ? 1 + strlen (arg) : 0);
-	  if (n + len >= rmargin)
-	    FLUSH;
-	  else
-	    buf[n++] = ' ';
-	  buf[n++] = '[';
-	  buf[n++] = '-';
-	  buf[n++] = '-';
-	  strcpy (&buf[n], opt->opt_long);
-	  n += strlen (opt->opt_long);
+
+	  mu_stream_printf (str, " [--%s", opt->opt_long);
 	  if (opt->opt_arg)
 	    {
-	      buf[n++] = '=';
-	      strcpy (&buf[n], arg);
-	      n += strlen (arg);
+	      if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
+		mu_stream_printf (str, "[=%s]", arg);
+	      else
+		mu_stream_printf (str, "=%s", arg);
 	    }
-	  buf[n++] = ']';
+	  mu_stream_printf (str, "%c", ']');
 	}
     }
 
   if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
-    {
-      char const *p = po->po_prog_args;
-
-      if (n + 1 >= rmargin)
-	FLUSH;
-      buf[n++] = ' ';
-      
-      while (*p)
-	{
-	  size_t len = strcspn (p, "  \t\n");
-	  if (len == 0)
-	    len = 1;
-	  if (n + len >= rmargin)
-	    FLUSH;
-	  else
-	    {
-	      memcpy (buf + n, p, len);
-	      p += len;
-	      n += len;
-	    }
-	}
-    }
+    mu_stream_printf (str, " %s", _(po->po_prog_args));
 
-  FLUSH;
+  mu_stream_destroy (&str);
+  
   free (idxbuf);
 }
 
+void
+mu_program_version (struct mu_parseopt *po, mu_stream_t outstr)
+{
+  int rc;
+  mu_stream_t str;
+  
+  init_usage_vars (po);
+
+  rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
+  if (rc)
+    {
+      abort ();//FIXME
+    }  
+  po->po_version_hook (po, str);
+
+  mu_stream_destroy (&str);
+}
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 0e31a47..bf3d4cd 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -24,6 +24,7 @@
 #include <mailutils/opt.h>
 #include <mailutils/nls.h>
 #include <mailutils/errno.h>
+#include <mailutils/stdstream.h>
 
 #define EXIT_SUCCESS 0
 #define EXIT_ERROR   1
@@ -78,7 +79,7 @@ sort_group (struct mu_option **optbuf, size_t start)
 static void
 fn_help (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
-  mu_program_help (po);
+  mu_program_help (po, mu_strout);
   exit (EXIT_SUCCESS);
 }
 
@@ -86,14 +87,14 @@ fn_help (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 static void
 fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
-  mu_program_usage (po);
+  mu_program_usage (po, mu_strout);
   exit (EXIT_SUCCESS);
 }
 
 static void
 fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
-  po->po_version_hook (po, stdout);
+  mu_program_version (po, mu_strout);
   exit (EXIT_SUCCESS);
 }
 
diff --git a/libmailutils/stream/Makefile.am b/libmailutils/stream/Makefile.am
index df76fd8..d64a45e 100644
--- a/libmailutils/stream/Makefile.am
+++ b/libmailutils/stream/Makefile.am
@@ -38,6 +38,7 @@ libstream_la_SOURCES = \
  syslogstream.c\
  tcp.c\
  temp_file_stream.c\
+ wordwrap.c\
  xscript-stream.c
 
 AM_CPPFLAGS = @MU_LIB_COMMON_INCLUDES@ -I/libmailutils
diff --git a/libmailutils/stream/wordwrap.c b/libmailutils/stream/wordwrap.c
new file mode 100644
index 0000000..b91a36e
--- /dev/null
+++ b/libmailutils/stream/wordwrap.c
@@ -0,0 +1,354 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <mailutils/types.h>
+#include <mailutils/stream.h>
+#include <mailutils/sys/stream.h>
+#include <mailutils/alloc.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+#include <mailutils/nls.h>
+#include <mailutils/cctype.h>
+
+struct mu_wordwrap_stream
+{
+  struct _mu_stream stream;
+  unsigned left_margin;
+  unsigned right_margin;
+  char *buffer;
+  unsigned offset;
+  mu_stream_t transport;
+};
+
+static int
+is_word (int c)
+{
+  return !mu_isspace (c);
+}
+
+static int
+full_write (struct mu_wordwrap_stream *str, size_t length)
+{
+  size_t n, rdsize;
+  for (n = 0; n < length; )
+    {
+      int rc = mu_stream_write (str->transport,
+				str->buffer + n, length - n,
+				&rdsize);
+      if (rc)
+	return rc;
+      n += rdsize;
+    }
+  return 0;
+}
+
+static int
+_wordwrap_flush_line (struct mu_wordwrap_stream *str, int lookahead)
+{
+  size_t length, word_start, word_len = 0;
+  int nl = 0;
+  char savech;
+  int rc;
+  
+  length = word_start = str->offset;
+  if (str->offset > 0 && lookahead)
+    {
+      if (is_word (str->buffer[str->offset - 1]) && is_word (lookahead))
+	{
+	  /* Find the nearest word boundary */
+	  for (length = str->offset; length > str->left_margin; length--)
+	    {
+	      if (!is_word (str->buffer[length - 1]))
+		break;
+	    }
+	  if (length == str->left_margin)
+	    {
+	      rc = full_write (str, str->offset);
+	      if (rc == 0)
+		str->offset = 0;
+	      return rc;
+	    }
+	  word_start = length;
+	}
+    }
+
+  while (length > 0 && mu_isspace (str->buffer[length - 1]))
+    length--;
+  
+  if (length == 0 || str->buffer[length - 1] != '\n')
+    {
+      savech = str->buffer[length];
+      str->buffer[length] = '\n';
+      nl = 1;
+    }
+  else
+    nl = 0;
+  
+  /* Flush the line buffer content */
+  rc = full_write (str, length + nl);
+  if (rc)
+    /* FIXME: Inconsistent state after error */
+    return rc;
+
+  if (nl)
+    str->buffer[length] = savech;
+  
+  /* Adjust the buffer */
+  memset (str->buffer, ' ', str->left_margin);
+  if (word_start > str->left_margin)
+    {
+      word_len = str->offset - word_start;
+      if (word_len)
+	memmove (str->buffer + str->left_margin, str->buffer + word_start,
+		 word_len);
+    }
+  str->offset = str->left_margin + word_len;
+  return 0;
+}
+  
+static int
+_wordwrap_write (mu_stream_t stream, const char *iptr, size_t isize,
+		 size_t *nbytes)
+{
+  struct mu_wordwrap_stream *str = (struct mu_wordwrap_stream *) stream;
+  size_t n;
+
+  for (n = 0; n < isize; n++)
+    {
+      if (str->offset == str->right_margin
+	  || (str->offset > 0 && str->buffer[str->offset - 1] == '\n'))
+	_wordwrap_flush_line (str, iptr[n]);
+      if (str->offset == str->left_margin && mu_isblank (iptr[n]))
+	continue;
+      str->buffer[str->offset++] = iptr[n];
+    }
+  if (nbytes)
+    *nbytes = isize;
+  return 0;
+}
+
+static int
+_wordwrap_flush (mu_stream_t stream)
+{
+  struct mu_wordwrap_stream *str = (struct mu_wordwrap_stream *)stream;
+  if (str->offset > str->left_margin)
+    _wordwrap_flush_line (str, 0);
+  return mu_stream_flush (str->transport);
+}
+
+static void
+_wordwrap_done (mu_stream_t stream)
+{
+  struct mu_wordwrap_stream *str = (struct mu_wordwrap_stream *)stream;
+  mu_stream_destroy (&str->transport);
+}
+
+static int
+_wordwrap_close (mu_stream_t stream)
+{
+  struct mu_wordwrap_stream *str = (struct mu_wordwrap_stream *)stream;
+  return mu_stream_close (str->transport);
+}
+
+static int
+set_margin (mu_stream_t stream, unsigned lmargin, int off)
+{
+  struct mu_wordwrap_stream *str = (struct mu_wordwrap_stream *)stream;
+
+  if (off < 0 && -off > str->left_margin)
+    return EINVAL;
+  lmargin += off;
+  
+  if (lmargin >= str->right_margin)
+    return EINVAL;
+
+  str->left_margin = lmargin;
+  if (lmargin < str->offset ||
+      (str->offset > 0 && str->buffer[str->offset - 1] == '\n'))
+    {
+      _wordwrap_flush (stream);
+    }
+  else if (lmargin > str->offset)
+    {
+      memset (str->buffer + str->offset, ' ', lmargin - str->offset);
+      str->offset = lmargin;
+    }
+      
+  return 0;
+}
+
+static int
+_wordwrap_ctl (mu_stream_t stream, int code, int opcode, void *arg)
+{
+  struct mu_wordwrap_stream *str = (struct mu_wordwrap_stream *)stream;
+  int status;
+
+  switch (code)
+    {
+    case MU_IOCTL_WORDWRAPSTREAM:
+      switch (opcode)
+	{
+	case MU_IOCTL_WORDWRAP_GET_MARGIN:
+	  /* Get left margin */
+	  if (!arg)
+	    return MU_ERR_OUT_PTR_NULL;
+	  *(unsigned *)arg = str->left_margin;
+	  break;
+	    
+	case MU_IOCTL_WORDWRAP_SET_MARGIN:
+	  /* Set left margin */
+	  if (!arg)
+	    return EINVAL;
+	  else
+	    return set_margin (stream, *(unsigned*)arg, 0);
+
+	case MU_IOCTL_WORDWRAP_SET_NEXT_MARGIN:
+	  if (!arg)
+	    return EINVAL;
+	  else
+	    {
+	      unsigned marg = *(unsigned*)arg;
+	      if (marg >= str->right_margin)
+		return EINVAL;
+	      str->left_margin = marg;
+	    }
+	  break;
+	  
+	case MU_IOCTL_WORDWRAP_MOVE_MARGIN:
+	  if (!arg)
+	    return EINVAL;
+	  else
+	    return set_margin (stream, str->offset, *(int*)arg);
+
+	case MU_IOCTL_WORDWRAP_GET_OFFSET:
+	  if (!arg)
+	    return EINVAL;
+	  *(unsigned*)arg = str->offset;
+	  break;
+
+	default:
+	  return EINVAL;
+	}
+      break;
+      
+    case MU_IOCTL_TRANSPORT:
+      if (!arg)
+	return EINVAL;
+      else
+	{
+	  mu_transport_t *ptrans = arg;
+	  switch (opcode)
+	    {
+	    case MU_IOCTL_OP_GET:
+	      ptrans[0] = (mu_transport_t) str->transport;
+	      ptrans[1] = NULL;
+	      break;
+
+	    case MU_IOCTL_OP_SET:
+	      ptrans = arg;
+	      if (ptrans[0])
+		str->transport = (mu_stream_t) ptrans[0];
+	      break;
+
+	    default:
+	      return EINVAL;
+	    }
+	}
+      break;
+
+    case MU_IOCTL_SUBSTREAM:
+      if (str->transport &&
+          ((status = mu_stream_ioctl (str->transport, code, opcode, arg)) == 0 ||
+           status != ENOSYS))
+        return status;
+      /* fall through */
+
+    case MU_IOCTL_TOPSTREAM:
+      if (!arg)
+	return EINVAL;
+      else
+	{
+	  mu_stream_t *pstr = arg;
+	  switch (opcode)
+	    {
+	    case MU_IOCTL_OP_GET:
+	      pstr[0] = str->transport;
+	      mu_stream_ref (pstr[0]);
+	      pstr[1] = NULL;
+	      break;
+
+	    case MU_IOCTL_OP_SET:
+	      mu_stream_unref (str->transport);
+	      str->transport = pstr[0];
+	      mu_stream_ref (str->transport);
+	      break;
+
+	    default:
+	      return EINVAL;
+	    }
+	}
+      break;
+
+    case MU_IOCTL_FILTER:
+      return mu_stream_ioctl (str->transport, code, opcode, arg);
+      
+    default:
+      return ENOSYS;
+    }
+  return 0;
+}
+  
+int
+mu_wordwrap_stream_create (mu_stream_t *pstream, mu_stream_t transport,
+			   size_t left_margin, size_t right_margin)
+{
+  int rc;
+  mu_stream_t stream;
+  struct mu_wordwrap_stream *str;
+
+  if (right_margin == 0 || left_margin >= right_margin)
+    return EINVAL;
+  
+  str = (struct mu_wordwrap_stream *)
+             _mu_stream_create (sizeof (*str), MU_STREAM_APPEND);
+  if (!str)
+    return ENOMEM;
+  str->stream.close = _wordwrap_close;
+  str->stream.write = _wordwrap_write;
+  //  str->stream.size = _wordwrap_size;
+  str->stream.done = _wordwrap_done;
+  str->stream.flush = _wordwrap_flush;
+  str->stream.ctl = _wordwrap_ctl;
+  
+  str->transport = transport;
+  mu_stream_ref (transport);
+  str->left_margin = left_margin;
+  str->right_margin = right_margin;
+  str->buffer = mu_alloc (str->right_margin+1);
+  memset (str->buffer, ' ', str->left_margin);
+  str->offset = str->left_margin;
+  
+  stream = (mu_stream_t) str;
+  rc = mu_stream_open (stream);
+  if (rc)
+    mu_stream_destroy (&stream);
+  else
+    *pstream = stream;
+  return rc;
+}
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index 728eaec..bdd4b20 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -68,6 +68,7 @@ noinst_PROGRAMS = \
  url-comp\
  url-parse\
  wicket\
+ wordwrap\
  wsp
 
 LDADD = ${MU_LIB_MAILUTILS}
@@ -155,7 +156,11 @@ TESTSUITE_AT = \
  url-comp.at\
  xml.at\
  wicket.at\
- wordsplit.at
+ wordsplit.at\
+ wordwrap00.at\
+ wordwrap01.at\
+ wordwrap02.at\
+ wordwrap03.at
 
 TESTSUITE = $(srcdir)/testsuite
 M4=m4
diff --git a/libmailutils/tests/parseopt.c b/libmailutils/tests/parseopt.c
index f25aabf..214a93d 100644
--- a/libmailutils/tests/parseopt.c
+++ b/libmailutils/tests/parseopt.c
@@ -64,9 +64,9 @@ struct mu_option group_b[] = {
 struct mu_option *optv[] = { group_a, group_b, NULL };
 
 static void
-version_hook (struct mu_parseopt *po, FILE *fp)
+version_hook (struct mu_parseopt *po, mu_stream_t str)
 {
-  fputs ("version hook called\n", fp);
+  mu_stream_printf (str, "version hook called\n");
 }
 
 #define S(s) ((s)?(s):"(null)")
diff --git a/libmailutils/tests/parseopt_help00.at b/libmailutils/tests/parseopt_help00.at
index c3751ac..894d524 100644
--- a/libmailutils/tests/parseopt_help00.at
+++ b/libmailutils/tests/parseopt_help00.at
@@ -30,8 +30,8 @@ parseopt --help
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help01.at b/libmailutils/tests/parseopt_help01.at
index 63ecf56..cacfb7c 100644
--- a/libmailutils/tests/parseopt_help01.at
+++ b/libmailutils/tests/parseopt_help01.at
@@ -21,8 +21,8 @@ PARSEOPT_DEFAULT
 parseopt --usage
 ],
 [0],
-[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
+[[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all]
             [--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
-            [--optional=FILE] [--usage] [--verbose]
+            [--optional[=FILE]] [--usage] [--verbose]
 ]])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt_help02.at b/libmailutils/tests/parseopt_help02.at
index 79aef4d..61dbac3 100644
--- a/libmailutils/tests/parseopt_help02.at
+++ b/libmailutils/tests/parseopt_help02.at
@@ -30,8 +30,8 @@ MU_PARSEOPT_PROG_NAME=newname parseopt --help
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help03.at b/libmailutils/tests/parseopt_help03.at
index f004bcf..8435a9c 100644
--- a/libmailutils/tests/parseopt_help03.at
+++ b/libmailutils/tests/parseopt_help03.at
@@ -31,8 +31,8 @@ Tests option parsing
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help04.at b/libmailutils/tests/parseopt_help04.at
index 1c6de2e..bcce1e1 100644
--- a/libmailutils/tests/parseopt_help04.at
+++ b/libmailutils/tests/parseopt_help04.at
@@ -30,8 +30,8 @@ MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help05.at b/libmailutils/tests/parseopt_help05.at
index 4fe6960..2856e61 100644
--- a/libmailutils/tests/parseopt_help05.at
+++ b/libmailutils/tests/parseopt_help05.at
@@ -30,8 +30,8 @@ MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org' parseopt --help
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help06.at b/libmailutils/tests/parseopt_help06.at
index 5ba784f..4562a21 100644
--- a/libmailutils/tests/parseopt_help06.at
+++ b/libmailutils/tests/parseopt_help06.at
@@ -30,8 +30,8 @@ MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailuti
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help07.at b/libmailutils/tests/parseopt_help07.at
index 91c3c19..1b2e388 100644
--- a/libmailutils/tests/parseopt_help07.at
+++ b/libmailutils/tests/parseopt_help07.at
@@ -37,8 +37,8 @@ Tests option parsing
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/parseopt_help08.at b/libmailutils/tests/parseopt_help08.at
index c9f1029..becc899 100644
--- a/libmailutils/tests/parseopt_help08.at
+++ b/libmailutils/tests/parseopt_help08.at
@@ -31,8 +31,8 @@ ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-co
  -x                             short-only option
 
           Group B
- -F VALUE, --find=VALUE         find VALUE
  -d, -v, --debug, --verbose     another option
+ -F VALUE, --find=VALUE         find VALUE
  -j N, --jobs=N                 sets numeric value
 
  -?,  --help                    give this help list
diff --git a/libmailutils/tests/parseopt_help09.at b/libmailutils/tests/parseopt_help09.at
index d727bdf..bd4ccc2 100644
--- a/libmailutils/tests/parseopt_help09.at
+++ b/libmailutils/tests/parseopt_help09.at
@@ -23,7 +23,7 @@ ARGP_HELP_FMT=rmargin=62,usage-indent=1\
 ],
 [0],
 [[Usage: parseopt [-advx?] [-f FILE] [-F VALUE] [-j N]
- [-o FILE] [--all] [--debug] [--file=FILE] [--find=VALUE]
- [--help] [--jobs=N] [--optional=FILE] [--usage] [--verbose]
+ [-o[FILE]] [--all] [--debug] [--file=FILE] [--find=VALUE]
+ [--help] [--jobs=N] [--optional[=FILE]] [--usage] [--verbose]
 ]])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt_help10.at b/libmailutils/tests/parseopt_help10.at
index 3f70616..3deb4f7 100644
--- a/libmailutils/tests/parseopt_help10.at
+++ b/libmailutils/tests/parseopt_help10.at
@@ -21,8 +21,8 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_VERSION_HOOK=1 parseopt --usage
 ],
 [0],
-[[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o FILE] [--all]
+[[Usage: parseopt [-advVx?] [-f FILE] [-F VALUE] [-j N] [-o[FILE]] [--all]
             [--debug] [--file=FILE] [--find=VALUE] [--help] [--jobs=N]
-            [--optional=FILE] [--usage] [--verbose] [--version]
+            [--optional[=FILE]] [--usage] [--verbose] [--version]
 ]])
 AT_CLEANUP
diff --git a/libmailutils/tests/parseopt_help11.at b/libmailutils/tests/parseopt_help11.at
index a8bda93..9b7dc2b 100644
--- a/libmailutils/tests/parseopt_help11.at
+++ b/libmailutils/tests/parseopt_help11.at
@@ -30,8 +30,8 @@ MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
   -x                         short-only option
 
  Group B
-  -F, --find=VALUE           find VALUE
   -d, -v, --debug, --verbose another option
+  -F, --find=VALUE           find VALUE
   -j, --jobs=N               sets numeric value
 
   -?, --help                 give this help list
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 12043f9..f9b1bcc 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -56,6 +56,12 @@ AT_INIT
 AT_BANNER([Conversions])
 m4_include([strtoc.at])
 
+AT_BANNER([Word wrapper])
+m4_include([wordwrap00.at])
+m4_include([wordwrap01.at])
+m4_include([wordwrap02.at])
+m4_include([wordwrap03.at])
+
 AT_BANNER([Command line parser])
 m4_define([PARSEOPT_DEFAULT],[
 unset ARGP_HELP_FMT
diff --git a/libmailutils/tests/wordwrap.c b/libmailutils/tests/wordwrap.c
new file mode 100644
index 0000000..781f9a1
--- /dev/null
+++ b/libmailutils/tests/wordwrap.c
@@ -0,0 +1,162 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2011-2012, 2014-2016 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 <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <mailutils/stream.h>
+#include <mailutils/stdstream.h>
+#include <mailutils/diag.h>
+#include <mailutils/debug.h>
+#include <mailutils/errno.h>
+
+static void
+usage (FILE *fp)
+{
+  fprintf (fp,
+	   "usage: %s [-r N] [-l [+-]N] FILE [[-l [+-]N] FILE...]\n",
+	   mu_program_name);
+  fprintf (fp, "\n");
+  fprintf (fp, "  -l N       set left margin\n");
+  fprintf (fp, "  -l +N      move left margin N chars to the right from the current position\n");
+  fprintf (fp, "  -l -N      move left margin N chars to the left from the current position\n");
+  fprintf (fp, "  -r N       set right margin\n");
+  fprintf (fp, "  -h, -?     display this help\n");
+}
+
+int
+main (int argc, char **argv)
+{
+  unsigned left = 0, right = 80;
+  mu_stream_t str;
+  int i;
+  
+  mu_set_program_name (argv[0]);
+ 
+  for (i = 1; i < argc; i++)
+    {
+      char *arg = argv[i];
+      if (strncmp (arg, "-l", 2) == 0)
+	{
+	  if (arg[2] == 0)
+	    {
+	      ++i;
+	      left = strtoul (argv[i], NULL, 10);
+	    }
+	  else
+	    {
+	      left = strtoul (argv[i] + 2, NULL, 10);
+	    }
+	}
+      else if (strncmp (arg, "-r", 2) == 0)
+	{
+	  if (arg[2] == 0)
+	    {
+	      ++i;
+	      right = strtoul (argv[i], NULL, 10);
+	    }
+	  else
+	    {
+	      right = strtoul (argv[i] + 2, NULL, 10);
+	    }
+	}
+      else if (strcmp (arg, "--") == 0)
+	{
+	  i++;
+	  break;
+	}
+      else if (arg[0] == '-')
+	{
+	  if (arg[1] == 0)
+	    break;
+	  else if ((arg[1] == 'h' || arg[1] == '?') && arg[2] == 0)
+	    {
+	      usage (stdout);
+	      return 0;
+	    }
+	  else
+	    {
+	      fprintf (stderr, "%s: unrecognized argument %s\n",
+		       mu_program_name, arg);
+	      usage (stderr);
+	      return 1;
+	    }
+	}
+      else
+	break;
+    }
+
+  if (i == argc)
+    {
+      fprintf (stderr, "%s: no files\n", mu_program_name);
+      usage (stderr);
+      return 1;
+    }
+  
+  mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
+  MU_ASSERT (mu_wordwrap_stream_create (&str, mu_strout, left, right));
+
+  for (; i < argc; i++)
+    {
+      char *arg = argv[i];
+      if (strncmp (arg, "-l", 2) == 0)
+	{
+	  if (arg[2] == 0)
+	    {
+	      ++i;
+	      arg = argv[i];
+	    }
+	  else
+	    arg += 2;
+
+	  if (arg[0] == '+' || arg[0] == '-')
+	    {
+	      int off = strtol (arg, NULL, 10);
+	      MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+					  MU_IOCTL_WORDWRAP_MOVE_MARGIN,
+					  &off));
+	    }
+	  else
+	    {
+	      left = strtoul (arg, NULL, 10);
+	      MU_ASSERT (mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+					  MU_IOCTL_WORDWRAP_SET_MARGIN,
+					  &left));
+	    }
+	}
+      else if (arg[0] == '-' && arg[1] == 0)
+	{
+	  MU_ASSERT (mu_stream_copy (str, mu_strin, 0, NULL));
+	  mu_stream_close (mu_strin);
+	}
+      else
+	{
+	  mu_stream_t in;
+	  MU_ASSERT (mu_file_stream_create (&in, arg, MU_STREAM_READ));
+	  MU_ASSERT (mu_stream_copy (str, in, 0, NULL));
+	  mu_stream_destroy (&in);
+	}
+    }
+  mu_stream_destroy (&str);
+  return 0;
+}
+    
+
+  
+	    
diff --git a/libmailutils/tests/wordwrap00.at b/libmailutils/tests/wordwrap00.at
new file mode 100644
index 0000000..07d5802
--- /dev/null
+++ b/libmailutils/tests/wordwrap00.at
@@ -0,0 +1,45 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Fixed margins])
+AT_KEYWORDS([wordwrap wordwrap00])
+AT_DATA([input],[My Father had a small Estate in Nottinghamshire; I was the Third of five Sons. He sent me to Emanuel-College in Cambridge, at Fourteen Years old, where I resided three Years, and applyed my self close to my Studies: But the Charge of maintaining me (although I had a very scanty Allowance) being too great for a narrow Fortune; I was bound Apprentice to Mr. James Bates, an eminent Surgeon in London, with whom I continued four Years; and my Father now and then sending me small Sums of Money,  I laid them out in learning Navigation, and other parts of the Mathematicks, useful to those who intend to travel, as I always believed it would be some time or other my Fortune to do. When I left Mr. Bates, I went down to my Father; where, by the Assistance of him and my Uncle John, and some other Relations, I got Forty Pounds, and a Promise of Thirty Pounds a Year to maintain me at Leyden: There I studied Physick two Years and seven Months, knowing it would be useful in 
 long Voyages.
+])
+AT_CHECK([wordwrap -l 20 -r 70 input],
+[0],
+[                    My Father had a small Estate in Nottinghamshire; I
+                    was the Third of five Sons. He sent me to 
+                    Emanuel-College in Cambridge, at Fourteen Years 
+                    old, where I resided three Years, and applyed my 
+                    self close to my Studies: But the Charge of 
+                    maintaining me (although I had a very scanty 
+                    Allowance) being too great for a narrow Fortune; I
+                    was bound Apprentice to Mr. James Bates, an 
+                    eminent Surgeon in London, with whom I continued 
+                    four Years; and my Father now and then sending me 
+                    small Sums of Money,  I laid them out in learning 
+                    Navigation, and other parts of the Mathematicks, 
+                    useful to those who intend to travel, as I always 
+                    believed it would be some time or other my Fortune
+                    to do. When I left Mr. Bates, I went down to my 
+                    Father; where, by the Assistance of him and my 
+                    Uncle John, and some other Relations, I got Forty 
+                    Pounds, and a Promise of Thirty Pounds a Year to 
+                    maintain me at Leyden: There I studied Physick two
+                    Years and seven Months, knowing it would be useful
+                    in long Voyages.
+])
+AT_CLEANUP
\ No newline at end of file
diff --git a/libmailutils/tests/wordwrap01.at b/libmailutils/tests/wordwrap01.at
new file mode 100644
index 0000000..2274378
--- /dev/null
+++ b/libmailutils/tests/wordwrap01.at
@@ -0,0 +1,37 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Move margin right])
+AT_KEYWORDS([wordwrap wordwrap01])
+AT_DATA([input0],[My Father had a small Estate in Nottinghamshire; I was the Third of five Sons.
+])
+AT_DATA([input1],[He sent me to Emanuel-College in Cambridge, at Fourteen Years old, where I resided three Years, and applyed my self close to my Studies:
+])
+AT_CHECK([cat input0 | tr -d '\n' | wordwrap -l 20 -r 70 - -l +8 input1],
+[0],
+[                    My Father had a small Estate in Nottinghamshire; I
+                    was the Third of five Sons.        He sent me to
+                                                       Emanuel-College
+                                                       in Cambridge,
+                                                       at Fourteen
+                                                       Years old,
+                                                       where I resided
+                                                       three Years,
+                                                       and applyed my
+                                                       self close to
+                                                       my Studies:
+])
+AT_CLEANUP
\ No newline at end of file
diff --git a/libmailutils/tests/wordwrap02.at b/libmailutils/tests/wordwrap02.at
new file mode 100644
index 0000000..f631684
--- /dev/null
+++ b/libmailutils/tests/wordwrap02.at
@@ -0,0 +1,33 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2016 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Move margin left])
+AT_KEYWORDS([wordwrap wordwrap02])
+AT_DATA([input0],[My Father had a small Estate in Nottinghamshire; I was the Third of five Sons.
+])
+AT_DATA([input1],[He sent me to Emanuel-College in Cambridge, at Fourteen Years old, where I resided three Years, and applyed my self close to my Studies:
+])
+AT_CHECK([cat input0 | tr -d '\n' | wordwrap -l 20 -r 70 - -l -8 input1],
+[0],
+[                    My Father had a small Estate in Nottinghamshire; I
+                    was the Third of five Sons.
+                                       He sent me to Emanuel-College
+                                       in Cambridge, at Fourteen Years
+                                       old, where I resided three
+                                       Years, and applyed my self
+                                       close to my Studies:
+])
+AT_CLEANUP
\ No newline at end of file
diff --git a/libmailutils/tests/parseopt25.at b/libmailutils/tests/wordwrap03.at
similarity index 77%
copy from libmailutils/tests/parseopt25.at
copy to libmailutils/tests/wordwrap03.at
index 2cbbe3f..22854bc 100644
--- a/libmailutils/tests/parseopt25.at
+++ b/libmailutils/tests/wordwrap03.at
@@ -13,14 +13,13 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-
-AT_SETUP([MU_PARSEOPT_VERSION_HOOK])
-AT_KEYWORDS([parseopt MU_PARSEOPT_VERSION_HOOK parseopt25])
-AT_CHECK([
-PARSEOPT_DEFAULT
-MU_PARSEOPT_VERSION_HOOK=1 parseopt -V
+AT_SETUP([Corner cases])
+AT_KEYWORDS([wordwrap wordwrap03])
+AT_CHECK([echo abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz|\
+ wordwrap -r 10 -
 ],
 [0],
-[version hook called
+[abcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyz
 ])
-AT_CLEANUP
+AT_CLEANUP
\ No newline at end of file


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 15 17:56:06 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bvWw1-0005Ye-Vr
	for mharc-commit-mailutils@gnu.org; Sat, 15 Oct 2016 17:56:06 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:40700)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvWvy-0005WM-50
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 17:56:04 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvWvw-0000gi-0v
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 17:56:02 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:42864)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvWvv-0000gZ-Sy
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 17:55:59 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 95166220168; Sat, 15 Oct 2016 21:55:59 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-774-gee71e77
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 2a28ab58762f9ae9cd00ca3e467ee6f90f241201
X-Git-Newrev: ee71e7712297f5e2ca6ed38fce4a0fc1e72ca5d0
Message-Id: <20161015215559.95166220168@vcs.savannah.gnu.org>
Date: Sat, 15 Oct 2016 21:55:59 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 15 Oct 2016 21:56:04 -0000

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

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

The branch, master has been updated
       via  ee71e7712297f5e2ca6ed38fce4a0fc1e72ca5d0 (commit)
      from  2a28ab58762f9ae9cd00ca3e467ee6f90f241201 (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 ee71e7712297f5e2ca6ed38fce4a0fc1e72ca5d0
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 16 00:44:30 2016 +0300

    Allow for multiple argument sets in help output.
    
    Alternative invocations follow the main one, each on a separate line,
    preceded by " or: ".
    
    * include/mailutils/cli.h (mu_cli_setup) <prog_alt_args>: New member.
    * include/mailutils/opt.h (mu_parseopt) <po_prog_args>: Change type.
    (mu_program_usage): Change signature.
    * include/mailutils/stream.h (MU_IOCTL_WORDWRAP_GET_OFFSET): Rename to
    MU_IOCTL_WORDWRAP_GET_COLUMN. All uses changed.
    * libmailutils/cli/cli.c (mu_cli): Construct po.po_prog_args from
    prog_args and prog_alt_args.
    * libmailutils/opt/help.c (move_margin): Remove.
    (print_program_usage): New static function.
    (mu_program_usage): Second argument instructs how to display options.
    Main work is done by print_program_usage.
    (mu_program_help): Call print_program_usage.
    * libmailutils/opt/opt.c: Update.
    * libmailutils/stream/wordwrap.c (set_margin): Avoid unnecessary flushes.
    
    * libmailutils/tests/parseopt.c (MU_PARSEOPT_PROG_ARGS): Alternative
    argument sets are separated by the pipe sign.
    * libmailutils/tests/Makefile.am: Add new testcase.
    * libmailutils/tests/testsuite.at: Likewise.
    * libmailutils/tests/parseopt_help04.at: Add MU_PARSEOPT_PROG_ARGS
    to keywords.
    * libmailutils/tests/parseopt_help12.at: New file.
    
    * libmailutils/tests/tcli.c (cli): Add alternative arguments.
    
    * dotlock/dotlock.c: Update.
    * mimeview/mimeview.c: Likewise.
    * sieve/sieve.c: Likewise.

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

Summary of changes:
 dotlock/dotlock.c                                  |    1 +
 include/mailutils/cli.h                            |    1 +
 include/mailutils/opt.h                            |    4 +-
 include/mailutils/stream.h                         |    9 +-
 libmailutils/cli/cli.c                             |   32 ++++++-
 libmailutils/opt/help.c                            |  101 +++++++++++++-------
 libmailutils/opt/opt.c                             |    2 +-
 libmailutils/stream/wordwrap.c                     |   16 ++--
 libmailutils/tests/.gitignore                      |    2 +
 libmailutils/tests/Makefile.am                     |    1 +
 libmailutils/tests/parseopt.c                      |   44 ++++++++-
 libmailutils/tests/parseopt_help04.at              |    2 +-
 .../{parseopt_help04.at => parseopt_help12.at}     |   10 +-
 libmailutils/tests/tcli.c                          |    5 +-
 libmailutils/tests/testsuite.at                    |    1 +
 mimeview/mimeview.c                                |    1 +
 sieve/sieve.c                                      |    1 +
 17 files changed, 175 insertions(+), 58 deletions(-)
 copy libmailutils/tests/{parseopt_help04.at => parseopt_help12.at} (82%)

diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c
index f0e07d6..8304c10 100644
--- a/dotlock/dotlock.c
+++ b/dotlock/dotlock.c
@@ -93,6 +93,7 @@ static struct mu_cli_setup cli = {
   dotlock_cfg_param,
   N_("GNU dotlock -- lock mail spool files."),
   N_("FILE"),
+  NULL,
   N_("Returns 0 on success, 3 if locking the file fails because\
  it's already locked, and 1 if some other kind of error occurred."),
   MU_DL_EX_ERROR,
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index 097759e..dec27de 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -43,6 +43,7 @@ struct mu_cli_setup
   struct mu_cfg_param *cfg;    /* Configuration parameters */
   char *prog_doc;              /* Program documentation string */
   char *prog_args;             /* Program arguments string */
+  char const **prog_alt_args;  /* Alternative arguments string */
   char *prog_extra_doc;        /* Extra documentation.  This will be
 				  displayed after options. */
   int ex_usage;                /* If not 0, exit code on usage errors */
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 7752117..87a9839 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -125,7 +125,7 @@ struct mu_parseopt
   /* Informational: */
   char const *po_prog_name;
   char const *po_prog_doc;	
-  char const *po_prog_args;
+  char const **po_prog_args;
   char const *po_bug_address;
   char const *po_package_name;
   char const *po_package_url;
@@ -172,7 +172,7 @@ unsigned mu_parseopt_getcolumn (const char *name);
 void mu_option_describe_options (mu_stream_t str,
 				 struct mu_option **optbuf, size_t optcnt);
 void mu_program_help (struct mu_parseopt *p, mu_stream_t str);
-void mu_program_usage (struct mu_parseopt *p, mu_stream_t str);
+void mu_program_usage (struct mu_parseopt *p, int optsummary, mu_stream_t str);
 void mu_program_version (struct mu_parseopt *po, mu_stream_t str);
 
 void mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
diff --git a/include/mailutils/stream.h b/include/mailutils/stream.h
index 4f0ef69..dbd9262 100644
--- a/include/mailutils/stream.h
+++ b/include/mailutils/stream.h
@@ -208,11 +208,16 @@ enum mu_buffer_type
   ((n) == MU_TRANSPORT_INPUT || (n) == MU_TRANSPORT_OUTPUT)
 
 /* Word wrapper streams */
+/* Get left margin. */
 #define MU_IOCTL_WORDWRAP_GET_MARGIN      0
-#define MU_IOCTL_WORDWRAP_SET_MARGIN      1  
+/* Set left margin */  
+#define MU_IOCTL_WORDWRAP_SET_MARGIN      1
+/* Shift left margin relative to current position */ 
 #define MU_IOCTL_WORDWRAP_MOVE_MARGIN     2
+/* Set left margin for the next line */
 #define MU_IOCTL_WORDWRAP_SET_NEXT_MARGIN 3
-#define MU_IOCTL_WORDWRAP_GET_OFFSET      4
+/* Get current column */
+#define MU_IOCTL_WORDWRAP_GET_COLUMN      4
 
 struct mu_nullstream_pattern
 {
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 5b8507a..2dd142a 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -336,7 +336,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   struct mu_cfg_parse_hints hints;
   struct mu_option **optv;
   mu_list_t com_list;
-
+#define DFLARGC 2
+  char const *dfl_args[DFLARGC];
+  char **args = NULL;
+  size_t argcnt;
+  
   /* Set up defaults */
   if (setup->ex_usage == 0)
     setup->ex_usage = EX_USAGE;
@@ -374,7 +378,28 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 
   if (setup->prog_args)
     {
-      po.po_prog_args = setup->prog_args;
+      size_t i;
+      argcnt = 1;
+
+      if (setup->prog_alt_args)
+	{
+	  for (i = 0; setup->prog_alt_args[i]; i++)
+	    argcnt++;
+	}
+
+      if (argcnt < DFLARGC)
+	po.po_prog_args = dfl_args;
+      else
+	{
+	  args = mu_calloc (argcnt + 1, sizeof (args[0]));
+	  po.po_prog_args = (char const **) args;
+	}
+      
+      po.po_prog_args[0] = setup->prog_args;
+      for (i = 1; i < argcnt; i++)
+	po.po_prog_args[i] = setup->prog_alt_args[i-1];
+      po.po_prog_args[i] = NULL;
+
       flags |= MU_PARSEOPT_PROG_ARGS;
     }
   
@@ -439,5 +464,8 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 
   mu_cfg_destroy_tree (&parse_tree);
   free (optv);
+  
+  free (args);
+
   mu_parseopt_free (&po);  
 }
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index c4ef8d3..07420dc 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -204,16 +204,9 @@ static void
 get_offset (mu_stream_t str, unsigned *offset)
 {
   mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
-		   MU_IOCTL_WORDWRAP_GET_OFFSET,
+		   MU_IOCTL_WORDWRAP_GET_COLUMN,
 		   offset);
 }
-static void
-move_margin (mu_stream_t str, int margin)
-{
-  mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
-		   MU_IOCTL_WORDWRAP_MOVE_MARGIN,
-		   &margin);
-}
 
 static void
 print_opt_arg (mu_stream_t str, struct mu_option *opt, int delim)
@@ -333,6 +326,9 @@ mu_option_describe_options (mu_stream_t str,
     }
 }
 
+static void print_program_usage (struct mu_parseopt *po, int optsum,
+				 mu_stream_t str);
+
 void
 mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
 {
@@ -346,15 +342,8 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
     {
       abort ();//FIXME
     }
-  
-  mu_stream_printf (str, "%s", _("Usage:"));
-  if (po->po_prog_name)
-    mu_stream_printf (str, " %s ", po->po_prog_name);
-  move_margin (str, 0);
-  mu_stream_printf (str, "[%s]...", _("OPTION"));
-  if (po->po_prog_args)
-    mu_stream_printf (str, " %s", gettext (po->po_prog_args));
-  mu_stream_printf (str, "\n");
+
+  print_program_usage (po, 0, str);
   
   if (po->po_prog_doc)
     {
@@ -423,34 +412,20 @@ cmpidx_long (const void *a, const void *b)
   return strcmp (ap->opt_long, bp->opt_long);
 }
 
-void
-mu_program_usage (struct mu_parseopt *po, mu_stream_t outstr)
+static void
+option_summary (struct mu_parseopt *po, mu_stream_t str)
 {
-  int rc;
   unsigned i;
   unsigned *idxbuf;
   unsigned nidx;
 
   struct mu_option **optbuf = po->po_optv;
   size_t optcnt = po->po_optc;
-
-  mu_stream_t str;
-
-  init_usage_vars (po);
-
-  rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
-  if (rc)
-    {
-      abort ();//FIXME
-    }  
   
   option_tab = optbuf;
   
   idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
 
-  mu_stream_printf (str, "%s %s ", _("Usage:"),	po->po_prog_name);
-  set_next_margin (str, usage_indent);
-  
   /* Print a list of short options without arguments. */
   for (i = nidx = 0; i < optcnt; i++)
     if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && !optbuf[i]->opt_arg)
@@ -517,12 +492,66 @@ mu_program_usage (struct mu_parseopt *po, mu_stream_t outstr)
 	}
     }
 
+  free (idxbuf);
+}  
+
+static void
+print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
+{
+  char const *usage_text;
+  char const **arg_text;
+  size_t i;
+  
+  usage_text = _("Usage:");
+
   if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
-    mu_stream_printf (str, " %s", _(po->po_prog_args));
+    arg_text = po->po_prog_args;
+  else
+    arg_text = NULL;
+  i = 0;
+  
+  do
+    {
+      mu_stream_printf (str, "%s %s ", usage_text, po->po_prog_name);
+      set_next_margin (str, usage_indent);
 
-  mu_stream_destroy (&str);
+      if (optsum)
+	{
+	  option_summary (po, str);
+	  optsum = 0;
+	}
+      else
+	mu_stream_printf (str, "[%s]...", _("OPTION"));
+
+      if (arg_text)
+	{
+	  mu_stream_printf (str, " %s\n", gettext (arg_text[i]));
+	  if (i == 0)
+	    usage_text = _("or: ");
+	  set_margin (str, 2);
+	  i++;
+	}
+      else
+	mu_stream_flush (str);
+    }
+  while (arg_text && arg_text[i]);
+}
+
+void
+mu_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t outstr)
+{
+  int rc;
+  mu_stream_t str;
   
-  free (idxbuf);
+  init_usage_vars (po);
+
+  rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
+  if (rc)
+    {
+      abort ();//FIXME
+    }  
+  print_program_usage (po, optsum, str);
+  mu_stream_destroy (&str);
 }
 
 void
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index bf3d4cd..7dd28a1 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -87,7 +87,7 @@ fn_help (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 static void
 fn_usage (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
-  mu_program_usage (po, mu_strout);
+  mu_program_usage (po, 1, mu_strout);
   exit (EXIT_SUCCESS);
 }
 
diff --git a/libmailutils/stream/wordwrap.c b/libmailutils/stream/wordwrap.c
index b91a36e..789966e 100644
--- a/libmailutils/stream/wordwrap.c
+++ b/libmailutils/stream/wordwrap.c
@@ -178,18 +178,20 @@ set_margin (mu_stream_t stream, unsigned lmargin, int off)
   if (lmargin >= str->right_margin)
     return EINVAL;
 
-  str->left_margin = lmargin;
-  if (lmargin < str->offset ||
-      (str->offset > 0 && str->buffer[str->offset - 1] == '\n'))
+  if (str->offset > str->left_margin
+      && (lmargin < str->offset || str->buffer[str->offset - 1] == '\n'))
     {
+      str->left_margin = lmargin;
       _wordwrap_flush (stream);
     }
-  else if (lmargin > str->offset)
+  else
     {
-      memset (str->buffer + str->offset, ' ', lmargin - str->offset);
+      if (lmargin > str->offset)
+	memset (str->buffer + str->offset, ' ', lmargin - str->offset);
+      str->left_margin = lmargin;
       str->offset = lmargin;
     }
-      
+
   return 0;
 }
 
@@ -236,7 +238,7 @@ _wordwrap_ctl (mu_stream_t stream, int code, int opcode, void *arg)
 	  else
 	    return set_margin (stream, str->offset, *(int*)arg);
 
-	case MU_IOCTL_WORDWRAP_GET_OFFSET:
+	case MU_IOCTL_WORDWRAP_GET_COLUMN:
 	  if (!arg)
 	    return EINVAL;
 	  *(unsigned*)arg = str->offset;
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index 62b06b4..b8c5ee6 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -18,6 +18,7 @@ imapio
 listop
 mailcap
 mimehdr
+modmesg
 modtofsaf
 msgset
 parseopt
@@ -32,4 +33,5 @@ tempfile
 url-comp
 url-parse
 wicket
+wordwrap
 wsp
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index bdd4b20..72850f2 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -144,6 +144,7 @@ TESTSUITE_AT = \
  parseopt_help09.at\
  parseopt_help10.at\
  parseopt_help11.at\
+ parseopt_help12.at\
  prop.at\
  scantime.at\
  strftime.at\
diff --git a/libmailutils/tests/parseopt.c b/libmailutils/tests/parseopt.c
index 214a93d..d335823 100644
--- a/libmailutils/tests/parseopt.c
+++ b/libmailutils/tests/parseopt.c
@@ -77,8 +77,43 @@ struct parseopt_param
   int flag;
   mu_c_type_t type;
   size_t off;
+  void (*setfn) (struct parseopt_param *param, char const *val, void *target);
 };
 
+static void
+set_prog_args (struct parseopt_param *param, char const *str, void *target)
+{
+  char ***args_ptr = target;
+  char **args;
+  char *p;
+  size_t size, i;
+
+  size = 1;
+  for (i = 0; str[i]; i++)
+    if (str[i] == '\n')
+      size++;
+
+  args = mu_calloc (size + 1, sizeof (args[0]));
+
+  i = 0;
+  while (1)
+    {
+      size_t len = strcspn (str, "|");
+      p = mu_alloc (len + 1);
+      memcpy (p, str, len);
+      p[len] = 0;
+      args[i++] = p;
+      str += len;
+      if (str[0])
+	++str;
+      else
+	break;
+    }
+  args[i] = NULL;
+  
+  *args_ptr = args;
+}
+  
 static struct parseopt_param parseopt_param[] = {
   { "MU_PARSEOPT_ARGV0", MU_PARSEOPT_ARGV0, mu_c_void },
   { "MU_PARSEOPT_IGNORE_ERRORS", MU_PARSEOPT_IGNORE_ERRORS, mu_c_void },
@@ -93,7 +128,8 @@ static struct parseopt_param parseopt_param[] = {
   { "MU_PARSEOPT_PROG_DOC", MU_PARSEOPT_PROG_DOC,
     mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_doc) },
   { "MU_PARSEOPT_PROG_ARGS", MU_PARSEOPT_PROG_ARGS,
-    mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_args) },
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_prog_args),
+    set_prog_args },
   { "MU_PARSEOPT_BUG_ADDRESS", MU_PARSEOPT_BUG_ADDRESS,
     mu_c_string, mu_offsetof(struct mu_parseopt, po_bug_address) },
   { "MU_PARSEOPT_PACKAGE_NAME", MU_PARSEOPT_PACKAGE_NAME,
@@ -129,7 +165,11 @@ main (int argc, char *argv[])
 	  if (val)
 	    {
 	      flags |= param->flag;
-	      if (param->type != mu_c_void)
+	      if (param->setfn)
+		{
+		  param->setfn (param, val, ((char*)&po + param->off));
+		}
+	      else if (param->type != mu_c_void)
 		{
 		  char *errmsg;
 		  int rc = mu_str_to_c (val, param->type,
diff --git a/libmailutils/tests/parseopt_help04.at b/libmailutils/tests/parseopt_help04.at
index bcce1e1..473c0fb 100644
--- a/libmailutils/tests/parseopt_help04.at
+++ b/libmailutils/tests/parseopt_help04.at
@@ -15,7 +15,7 @@
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AT_SETUP([MU_PARSEOPT_PROG_ARGS])
-AT_KEYWORDS([parseopt parseopt_help parseopt_help04])
+AT_KEYWORDS([parseopt parseopt_help MU_PARSEOPT_PROG_ARGS parseopt_help04])
 AT_CHECK([
 PARSEOPT_DEFAULT
 MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
diff --git a/libmailutils/tests/parseopt_help04.at b/libmailutils/tests/parseopt_help12.at
similarity index 82%
copy from libmailutils/tests/parseopt_help04.at
copy to libmailutils/tests/parseopt_help12.at
index bcce1e1..674bdf4 100644
--- a/libmailutils/tests/parseopt_help04.at
+++ b/libmailutils/tests/parseopt_help12.at
@@ -14,15 +14,17 @@
 # You should have received a copy of the GNU General Public License
 # along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
-AT_SETUP([MU_PARSEOPT_PROG_ARGS])
-AT_KEYWORDS([parseopt parseopt_help parseopt_help04])
+AT_SETUP([MU_PARSEOPT_PROG_ARGS (alternative)])
+AT_KEYWORDS([parseopt parseopt_help MU_PARSEOPT_PROG_ARGS parseopt_help12])
 AT_CHECK([
 PARSEOPT_DEFAULT
-MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
+MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS|ALTERNATIVE ARGS|ANOTHER ARGS" parseopt --help
 ],
 [0],
 [Usage: parseopt [[OPTION]]... SOME MORE ARGS
-
+  or:  parseopt [[OPTION]]... ALTERNATIVE ARGS
+  or:  parseopt [[OPTION]]... ANOTHER ARGS
+  
  Group A
   -a, --all                  no arguments to this one
   -f, --file=FILE            set file name
diff --git a/libmailutils/tests/tcli.c b/libmailutils/tests/tcli.c
index 9a640d5..bfa619d 100644
--- a/libmailutils/tests/tcli.c
+++ b/libmailutils/tests/tcli.c
@@ -37,11 +37,14 @@ static struct mu_cfg_param config[] = {
   { NULL }
 };
 
+char const *alt_args[] = { "ALT ARGUMENTS 1", "ALT ARGUMENTS 2", NULL };
+
 struct mu_cli_setup cli = {
   options,
   config,
   "Tests standard command line interface",
-  "ARGUMENTS"
+  "ARGUMENTS",
+  alt_args
 };
 
 static char **
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index f9b1bcc..67f5c3b 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -121,6 +121,7 @@ m4_include([parseopt_help08.at])
 m4_include([parseopt_help09.at])
 m4_include([parseopt_help10.at])
 m4_include([parseopt_help11.at])
+m4_include([parseopt_help12.at])
 
 AT_BANNER([Standard streams])
 m4_include([strin.at])
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 011c6af..75ea9c7 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -145,6 +145,7 @@ struct mu_cli_setup cli = {
   mimeview_cfg_param,
   N_("GNU mimeview -- display files, using mailcap mechanism."),
   N_("FILE [FILE ...]"),
+  NULL,
   N_("Debug flags are:\n\
   g - Mime.types parser traces\n\
   l - Mime.types lexical analyzer traces\n\
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 2627bd1..d3738df 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -248,6 +248,7 @@ static struct mu_cli_setup cli = {
   sieve_cfg_param,
   N_("GNU sieve -- a mail filtering tool."),
   "SCRIPT",
+  NULL,
   N_("Debug flags:\n\
   g - main parser traces\n\
   T - mailutils traces (same as --debug-level=sieve.trace0-trace1)\n\


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 15 18:07:02 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bvX6c-000838-16
	for mharc-commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:07:02 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:44854)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvX6Y-00082w-6E
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:07:00 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvX6V-000775-MP
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:06:58 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:43025)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvX6V-00076v-HO
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:06:55 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 5AF71220168; Sat, 15 Oct 2016 22:06:55 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-775-ga29af22
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: ee71e7712297f5e2ca6ed38fce4a0fc1e72ca5d0
X-Git-Newrev: a29af229e7675aaabe28bdabf6cc2bd4b549e2cb
Message-Id: <20161015220655.5AF71220168@vcs.savannah.gnu.org>
Date: Sat, 15 Oct 2016 22:06:55 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 15 Oct 2016 22:07:00 -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=a29af229e7675aaabe28bdabf6cc2bd4b549e2cb

The branch, master has been updated
       via  a29af229e7675aaabe28bdabf6cc2bd4b549e2cb (commit)
      from  ee71e7712297f5e2ca6ed38fce4a0fc1e72ca5d0 (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 a29af229e7675aaabe28bdabf6cc2bd4b549e2cb
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Oct 16 01:04:30 2016 +0300

    Convert mail to mu_cli

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

Summary of changes:
 mail/Makefile.am |    2 +-
 mail/mail.c      |  368 +++++++++++++++++++++++++++++-------------------------
 mail/mail.h      |    4 +-
 mail/send.c      |    4 +-
 4 files changed, 204 insertions(+), 174 deletions(-)

diff --git a/mail/Makefile.am b/mail/Makefile.am
index 7134b5a..7af953a 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -25,7 +25,7 @@ mailbindir=@MAILBINDIR@
 mailbin_PROGRAMS = mail
 
 mail_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/mail/mail.c b/mail/mail.c
index a3d2901..a10d061 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -16,108 +16,47 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 
 /* Global variables and constants*/
 mu_mailbox_t mbox;            /* Mailbox being operated upon */
 size_t total;                 /* Total number of messages in the mailbox */
 int interactive;              /* Is the session interactive */  
 
-static mu_list_t command_list;   /* List of commands to be executed after parsing
+static mu_list_t command_list;/* List of commands to be executed after parsing
 				 command line */
-
 const char *program_version = "mail (" PACKAGE_STRING ")";
-static char doc[] = N_("GNU mail -- process mail messages.\n"
-"If -f or --file is given, mail operates on the mailbox named "
-"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_ENCODING     257
-#define F_CONTENT_TYPE 258
-
-static struct argp_option options[] = {
-  { NULL,     'f', NULL,      OPTION_HIDDEN, NULL, 0 },
-  {"file",    F_OPTION, "FILE",   OPTION_ARG_OPTIONAL|OPTION_HIDDEN, 0},
-
-  {"exist",   'e', NULL,      0, N_("return true if mail exists"), 0},
-  {"byname",  'F', NULL,      0, N_("save messages according to sender"), 0},
-  {"headers", 'H', NULL,      0, N_("write a header summary and exit"), 0},
-  {"ignore",  'i', NULL,      0, N_("ignore interrupts"), 0},
-  {"norc",    'n', NULL,      0, N_("do not read the system mailrc file"), 0},
-  {"nosum",   'N', NULL,      0,
-   N_("do not display initial header summary"), 0},
-  {"print",   'p', NULL,      0, N_("print all mail to standard output"), 0},
-  {"read",    0,   NULL,      OPTION_ALIAS },
-  {"return-address", 'r', N_("ADDRESS"), 0,
-   N_("use address as the return address when sending mail"), 0},
-  {"quit",    'q', NULL,      0,
-   N_("cause interrupts to terminate program"), 0},
-  {"subject", 's', N_("SUBJ"), 0,
-   N_("send a message with the given SUBJECT"), 0},
-  {"to",      't', NULL,      0,
-   N_("precede message by a list of addresses"), 0},
-  {"user",    'u', N_("USER"), 0, N_("operate on USER's mailbox"), 0},
-  {"append",  'a', N_("HEADER: VALUE"), 0,
-   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 }
-};
-
 
+
 #define HINT_SEND_MODE   0x1
 #define HINT_FILE_OPTION 0x2
-
-struct arguments
+int hint;
+char *file;
+char *user;
+
+static void
+cli_f_option (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  int argc;
-  char **argv;
-  char *file;
-  char *user;
-  int hint;
-};
+  hint |= HINT_FILE_OPTION;
+}
 
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+static void
+cli_file_option (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  struct arguments *args = state->input;
+  if (arg)
+    file = mu_strdup (arg);  
+  hint |= HINT_FILE_OPTION;
+}
 
-  switch (key)
+static void
+cli_command_option (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  switch (opt->opt_short)
     {
-    case 'a':
-      args->hint |= HINT_SEND_MODE;
-      send_append_header (arg);
-      break;
-
-    case 'A':
-      args->hint |= HINT_SEND_MODE;
-      if (send_attach_file_default (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");
       break;
-
-    case F_OPTION:
-      if (arg)
-	args->file = arg;
-      /* fall through */
-    case 'f':
-      args->hint |= HINT_FILE_OPTION;
-      break;
       
     case 'p':
       util_cache_command (&command_list, "setq mode=print");
@@ -151,90 +90,157 @@ parse_opt (int key, char *arg, struct argp_state *state)
       util_cache_command (&command_list, "set noheader");
       break;
       
-    case 's':
-      args->hint |= HINT_SEND_MODE;
-      send_append_header2 (MU_HEADER_SUBJECT, arg, COMPOSE_REPLACE);
-      util_cache_command (&command_list, "set noasksub");
-      break;
-      
-    case 'u':
-      args->user = arg;
-      break;
-
     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");
       break;
 
-    case ARGP_KEY_ARG:
-      args->argv = realloc (args->argv,
-			    sizeof (char *) * (state->arg_num + 2));
-      args->argv[state->arg_num] = arg;
-      args->argv[state->arg_num + 1] = NULL;
-      args->argc = state->arg_num + 1;
-      break;
-
-    case ARGP_KEY_FINI:
-      if ((args->hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) ==
-	  (HINT_SEND_MODE|HINT_FILE_OPTION))
-	argp_error (state, _("conflicting options"));
-      else if (args->hint & HINT_FILE_OPTION)
-	{
-	  if (args->file)
-	    {
-	      if (args->argc > 1)
-		argp_error (state,
-			    _("-f requires at most one command line argument"));
-	    }
-	  else if (args->argc)
-	    {
-	      args->file = args->argv[0];
-	  
-	      if (args->argc > 1)
-		argp_error (state,
-			    _("-f requires at most one command line argument"));
-	    }
-	  else if (args->user)
-	    mu_asprintf (&args->file, "~/%s/mbox", args->user);
-	  else
-	    args->file = "~/mbox";
-	}
-      else if (args->argc || (args->hint & HINT_SEND_MODE))
-	util_cache_command (&command_list, "setq mode=send");
-      else if (args->user)
-	mu_asprintf (&args->file, "%%%s", args->user);
-      break;
+    case 0:
+      mu_parseopt_error (po,
+			 _("--%s: option should have been recognized"),
+			 opt->opt_long);
+      exit (po->po_exit_error);
       
     default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+      mu_parseopt_error (po,
+			 _("-%c: option should have been recognized"),
+			 opt->opt_short);
+      exit (po->po_exit_error);
+    }      
 }
 
-static struct argp argp = {
+static void
+cli_subject (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  hint |= HINT_SEND_MODE;
+  send_append_header2 (MU_HEADER_SUBJECT, arg, COMPOSE_REPLACE);
+  util_cache_command (&command_list, "set noasksub");
+}
+
+static void
+cli_append (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  hint |= HINT_SEND_MODE;
+  send_append_header (arg);
+}
+
+static void
+cli_attach (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  hint |= HINT_SEND_MODE;
+  if (send_attach_file_default (arg))
+    exit (1);
+}
+
+static struct mu_option mail_options[] = {
+  { NULL,     'f', NULL,      MU_OPTION_HIDDEN,
+    NULL,
+    mu_c_string, NULL, cli_f_option },
+  { "file",   0,  N_("FILE"), MU_OPTION_ARG_OPTIONAL|MU_OPTION_HIDDEN,
+    NULL,
+    mu_c_string, NULL, cli_file_option },
+
+  { "exist",  'e', NULL,      MU_OPTION_DEFAULT,
+    N_("return true if mail exists"),
+    mu_c_string, NULL, cli_command_option },
+  
+  { "byname", 'F', NULL,      MU_OPTION_DEFAULT,
+    N_("save messages according to sender"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "headers", 'H', NULL,     MU_OPTION_DEFAULT,
+    N_("write a header summary and exit"),
+    mu_c_string, NULL, cli_command_option },
+  
+  { "ignore",  'i', NULL,     MU_OPTION_DEFAULT,
+    N_("ignore interrupts"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "norc",    'n', NULL,     MU_OPTION_DEFAULT,
+    N_("do not read the system mailrc file"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "nosum",   'N', NULL,     MU_OPTION_DEFAULT,
+    N_("do not display initial header summary"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "print",   'p', NULL,     MU_OPTION_DEFAULT,
+    N_("print all mail to standard output"),
+    mu_c_string, NULL, cli_command_option },    
+  { "read",    0,   NULL,     MU_OPTION_ALIAS },
+  
+  { "return-address", 'r', N_("ADDRESS"), MU_OPTION_DEFAULT,
+    N_("use address as the return address when sending mail"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "quit",    'q', NULL,     MU_OPTION_DEFAULT,
+    N_("cause interrupts to terminate program"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "subject", 's', N_("SUBJ"), MU_OPTION_DEFAULT,
+    N_("send a message with the given SUBJECT"),
+    mu_c_string, NULL, cli_subject },
+  
+  { "to",      't', NULL,       MU_OPTION_DEFAULT,
+    N_("precede message by a list of addresses"),
+    mu_c_string, NULL, cli_command_option },
+    
+  { "user",    'u', N_("USER"), MU_OPTION_DEFAULT,
+    N_("operate on USER's mailbox"),
+    mu_c_string, &user },
+  
+  { "append",   'a', N_("HEADER: VALUE"), MU_OPTION_DEFAULT,
+    N_("append given header to the message being sent"),
+    mu_c_string, NULL, cli_append },
+    
+  { "exec" ,    'E', N_("COMMAND"), MU_OPTION_DEFAULT,
+    N_("execute COMMAND"),
+    mu_c_string, NULL, cli_command_option },
+  
+  { "encoding",  0, N_("NAME"), MU_OPTION_DEFAULT,
+    N_("set encoding for subsequent --attach options"),
+    mu_c_string, &default_encoding },
+  
+  { "content-type", 0, N_("TYPE"), MU_OPTION_DEFAULT,
+    N_("set content type for subsequent --attach options"),
+    mu_c_string, &default_content_type },
+  
+  { "attach",  'A', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("attach FILE"),
+    mu_c_string, NULL, cli_attach },
+
+  MU_OPTION_END
+}, *options[] = { mail_options, NULL };
+
+static const char *alt_args[] = {
+  N_("[OPTION...] [file]"),
+  N_("--file [OPTION...] [file]"),
+  N_("--file=file [OPTION...]"),
+  NULL
+};
+
+static struct mu_cli_setup cli = {
   options,
-  parse_opt,
-  args_doc,
-  doc,
   NULL,
-  NULL, NULL
+  N_("GNU mail -- process mail messages.\n"
+"If -f or --file is given, mail operates on the mailbox named "
+     "by the first argument, or the user's mbox, if no argument given."),
+  N_("[address...]"),
+  alt_args,
+  NULL,
+  1,
+  1
 };
 
-static const char *mail_capa[] = {
-  "mailutils",
-  "common",
+static char *mail_capa[] = {
   "address",
   "debug",
   "mailbox",
   "locking",
+  "tls",
   NULL 
 };
 			     
@@ -351,7 +357,6 @@ int
 main (int argc, char **argv)
 {
   char *mode = NULL, *prompt = NULL, *p;
-  struct arguments args;
   int i, rc;
   
   mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
@@ -411,19 +416,45 @@ main (int argc, char **argv)
 	       mu_strdup ("sendmail:" PATH_SENDMAIL), mailvar_type_string,
 	       MOPTF_OVERWRITE);
 
-  args.argc = 0;
-  args.argv = NULL;
-  args.file = NULL;
-  args.user = NULL;
-  args.hint = 0;
-  
   /* argument parsing */
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, mail_capa, NULL, argc, argv, 0, NULL, &args))
-    exit (1);
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli (argc, argv, &cli, mail_capa, NULL, &argc, &argv);
+
+  if ((hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) ==
+      (HINT_SEND_MODE|HINT_FILE_OPTION))
+    {
+      mu_error (_("conflicting options"));
+      exit (1);
+    }
+  else if (hint & HINT_FILE_OPTION)
+    {
+      if (file)
+	{
+	  if (argc)
+	    {
+	      mu_error (_("-f requires at most one command line argument"));
+	      exit (1);
+	    }
+	}
+      else if (argc)
+	{
+	  if (argc > 1)
+	    {
+	      mu_error (_("-f requires at most one command line argument"));
+	      exit (1);
+	    }
+	  file = argv[0];
+	}
+      else if (user)
+	mu_asprintf (&file, "~/%s/mbox", user);
+      else
+	file = "~/mbox";
+    }
+  else if (argc || (hint & HINT_SEND_MODE))
+    util_cache_command (&command_list, "setq mode=send");
+  else if (user)
+    mu_asprintf (&file, "%%%s", user);
+
   
   /* read system-wide mail.rc and user's .mailrc */
   if (mailvar_get (NULL, "rc", mailvar_type_boolean, 0) == 0)
@@ -461,7 +492,7 @@ main (int argc, char **argv)
   /* Interactive mode */
 
   ml_readline_init ();
-  mail_set_my_name (args.user);
+  mail_set_my_name (user);
 
   /* Mode is just sending */
   if (strcmp (mode, "send") == 0)
@@ -469,17 +500,17 @@ main (int argc, char **argv)
       char *buf = NULL;
       int rc;
 
-      mu_argcv_string (args.argc, args.argv, &buf);
+      mu_argcv_string (argc, argv, &buf);
       rc = util_do_command ("mail %s", buf);
       return mailvar_get (NULL, "mailx", mailvar_type_boolean, 0) ? rc : 0;
     }
   /* Or acting as a normal reader */
   else 
     {
-      if ((rc = mu_mailbox_create_default (&mbox, args.file)) != 0)
+      if ((rc = mu_mailbox_create_default (&mbox, file)) != 0)
 	{
-	  if (args.file)
-	    mu_error (_("Cannot create mailbox %s: %s"), args.file,
+	  if (file)
+	    mu_error (_("Cannot create mailbox %s: %s"), file,
 			mu_strerror (rc));
 	  else
 	    mu_error (_("Cannot create mailbox: %s"),
@@ -530,11 +561,10 @@ main (int argc, char **argv)
 	  && (strcmp (mode, "read")
 	      || mailvar_get (NULL, "emptystart", mailvar_type_boolean, 0)))
         {
-	  if (args.file)
-	    mu_printf (_("%s: 0 messages\n"), args.file);
+	  if (file)
+	    mu_printf (_("%s: 0 messages\n"), file);
 	  else
-	    mu_printf (_("No mail for %s\n"),
-			      args.user ? args.user : mail_whoami ());
+	    mu_printf (_("No mail for %s\n"), user ? user : mail_whoami ());
           return 1;
         }
 
diff --git a/mail/mail.h b/mail/mail.h
index 074ed87..b589d3e 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -256,8 +256,8 @@ extern int mail_header_is_unfoldable (const char *str);
 extern int mail_mbox_close (void);
 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 void send_append_header (char const *text);
+extern void send_append_header2 (char const *name, char const *value, int mode);
 extern int send_attach_file_default (const char *name);
 
 extern int escape_check_args (int argc, char **argv, int minargs, int maxargs);
diff --git a/mail/send.c b/mail/send.c
index d7fcdc0..c2ed4e4 100644
--- a/mail/send.c
+++ b/mail/send.c
@@ -81,7 +81,7 @@ add_header (char *name, char *value, int mode)
 }
 
 void
-send_append_header (char *text)
+send_append_header (char const *text)
 {
   char *p;
   size_t len;
@@ -104,7 +104,7 @@ send_append_header (char *text)
 }
 
 void
-send_append_header2 (char *name, char *value, int mode)
+send_append_header2 (char const *name, char const *value, int mode)
 {
   add_header (mu_strdup (name), mu_strdup (value), mode);
 }


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 15 18:55:59 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bvXrz-0007iR-RD
	for mharc-commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:55:59 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52231)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvXrx-0007iJ-7v
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:55:59 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvXrv-0005n7-A4
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:55:57 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:43430)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvXrv-0005mn-5c
	for commit-mailutils@gnu.org; Sat, 15 Oct 2016 18:55:55 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id CC8AB220168; Sat, 15 Oct 2016 22:55:54 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-777-ge384046
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: a29af229e7675aaabe28bdabf6cc2bd4b549e2cb
X-Git-Newrev: e3840467baf287cc14177d224dddc282674f1609
Message-Id: <20161015225554.CC8AB220168@vcs.savannah.gnu.org>
Date: Sat, 15 Oct 2016 22:55:54 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 15 Oct 2016 22:55:59 -0000

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

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

The branch, master has been updated
       via  e3840467baf287cc14177d224dddc282674f1609 (commit)
       via  a76bffd55d3657bfb369656e7225eca21323c454 (commit)
      from  a29af229e7675aaabe28bdabf6cc2bd4b549e2cb (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 e3840467baf287cc14177d224dddc282674f1609
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 16 01:26:03 2016 +0300

    Convert examples to mu_cli

commit a76bffd55d3657bfb369656e7225eca21323c454
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 16 01:10:01 2016 +0300

    Minor fix in help output.
    
    Print "[OPTION...]", instead of "[OPTION]..."

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

Summary of changes:
 examples/Makefile.am                  |    4 +-
 examples/muauth.c                     |   87 ++++++++++++++-------------------
 examples/muemail.c                    |   20 ++++----
 libmailutils/opt/help.c               |    2 +-
 libmailutils/tests/parseopt_help00.at |    2 +-
 libmailutils/tests/parseopt_help02.at |    2 +-
 libmailutils/tests/parseopt_help03.at |    2 +-
 libmailutils/tests/parseopt_help04.at |    2 +-
 libmailutils/tests/parseopt_help05.at |    2 +-
 libmailutils/tests/parseopt_help06.at |    2 +-
 libmailutils/tests/parseopt_help07.at |    2 +-
 libmailutils/tests/parseopt_help08.at |    2 +-
 libmailutils/tests/parseopt_help11.at |    2 +-
 libmailutils/tests/parseopt_help12.at |    6 +--
 14 files changed, 61 insertions(+), 76 deletions(-)

diff --git a/examples/Makefile.am b/examples/Makefile.am
index 55b53df..5ffabeb 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -113,14 +113,14 @@ lsf_LDADD = \
 
 muauth_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
 muauth_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_AUTH}\
  @MU_AUTHLIBS@ \
  ${MU_LIB_MAILUTILS}
 
 muemail_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
 muemail_LDADD = \
- ${MU_APP_LIBRARIES} \
+ ${MU_APP_NEW_LIBRARIES} \
  ${MU_LIB_MAILUTILS}
 
 mboxidx_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
diff --git a/examples/muauth.c b/examples/muauth.c
index 24b4143..5c32157 100644
--- a/examples/muauth.c
+++ b/examples/muauth.c
@@ -24,89 +24,74 @@
 #include <ctype.h>
 #include <string.h>
 #include <mailutils/mailutils.h>
-#include "mailutils/libargp.h"
-
-static char doc[] =
-"muauth -- test mailutils authentication and authorization schemes";
-static char args_doc[] = "key";
-
-static const char *capa[] = {
-  "mailutils",
-  "auth",
-  "common",
-  "debug",
-  NULL
-};
-
-static struct argp_option options[] = {
-  { "password", 'p', "STRING", 0, "user password", 0 },
-  { "uid", 'u', NULL, 0, "test getpwuid functions", 0 },
-  { "name", 'n', NULL, 0, "test getpwnam functions", 0 },
-  { NULL },
-};
 
 enum mu_auth_key_type key_type = mu_auth_key_name;
 char *password;
 
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+static void
+use_uid (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case 'p':
-      password = arg;
-      break;
+  key_type = mu_auth_key_uid;
+}
 
-    case 'u':
-      key_type = mu_auth_key_uid;
-      break;
+static void
+use_name (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  key_type = mu_auth_key_name;
+}
 
-    case 'n':
-      key_type = mu_auth_key_name;
-      break;
+static struct mu_option muauth_options[] = {
+  { "password", 'p', "STRING", MU_OPTION_DEFAULT,
+    "user password",
+    mu_c_string, &password },
+  { "uid", 'u', NULL, MU_OPTION_DEFAULT,
+    "test getpwuid functions",
+    mu_c_string, NULL, use_uid },
+  { "name", 'n', NULL, MU_OPTION_DEFAULT,
+    "test getpwnam functions",
+    mu_c_string, NULL, use_name },
+  MU_OPTION_END
+}, *options[] = { muauth_options, NULL };
 
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
+static char *capa[] = {
+  "auth",
+  "debug",
+  NULL
+};
 
-static struct argp argp = {
+static struct mu_cli_setup cli = {
   options,
-  parse_opt,
-  args_doc,
-  doc,
   NULL,
-  NULL, NULL
+  "muauth -- test mailutils authentication and authorization schemes",
+  "key"
 };
            
 int
 main (int argc, char * argv [])
 {
-  int rc, index;
+  int rc;
   struct mu_auth_data *auth;
   void *key;
   uid_t uid;
   
   MU_AUTH_REGISTER_ALL_MODULES ();
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, capa, NULL, argc, argv, 0, &index, NULL))
-    exit (1);
 
-  if (index == argc)
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
+
+  if (argc == 0)
     {
       mu_error ("not enough arguments, try `%s --help' for more info",
-		argv[0]);
+		mu_program_name);
       return 1;
     }
 
   if (key_type == mu_auth_key_uid)
     {
-      uid = strtoul (argv[index], NULL, 0);
+      uid = strtoul (argv[0], NULL, 0);
       key = &uid;
     }
   else
-    key = argv[index];
+    key = argv[0];
   
   rc = mu_get_auth (&auth, key_type, key);
   printf ("mu_get_auth => %d, %s\n", rc, mu_strerror (rc));
diff --git a/examples/muemail.c b/examples/muemail.c
index 23350cd..e30a8b4 100644
--- a/examples/muemail.c
+++ b/examples/muemail.c
@@ -21,28 +21,28 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <mailutils/util.h>
-#include "mailutils/libargp.h"
+#include <mailutils/cli.h>
 
-const char *capa[] = {
-  "mailutils",
+char *capa[] = {
   "address",
   NULL
 };
 
+static struct mu_cli_setup cli = { NULL };
+  
+
 int
 main (int argc, char *argv[])
 {
-  int arg = 1;
-
-  if (mu_app_init (NULL, capa, NULL, argc, argv, 0, &arg, NULL))
-    exit (1);
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
-  if (!argv[arg])
+  if (argc == 0)
     printf ("current user -> %s\n", mu_get_user_email (0));
   else
     {
-      for (; argv[arg]; arg++)
-        printf ("%s -> %s\n", argv[arg], mu_get_user_email (argv[arg]));
+      int i;
+      for (i = 0; i < argc; i++)
+        printf ("%s -> %s\n", argv[i], mu_get_user_email (argv[i]));
     }
 
   return 0;
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index 07420dc..b1a81ea 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -521,7 +521,7 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
 	  optsum = 0;
 	}
       else
-	mu_stream_printf (str, "[%s]...", _("OPTION"));
+	mu_stream_printf (str, "[%s...]", _("OPTION"));
 
       if (arg_text)
 	{
diff --git a/libmailutils/tests/parseopt_help00.at b/libmailutils/tests/parseopt_help00.at
index 894d524..df43dc3 100644
--- a/libmailutils/tests/parseopt_help00.at
+++ b/libmailutils/tests/parseopt_help00.at
@@ -21,7 +21,7 @@ PARSEOPT_DEFAULT
 parseopt --help
 ],
 [0],
-[[Usage: parseopt [OPTION]...
+[[Usage: parseopt [OPTION...]
 
  Group A
   -a, --all                  no arguments to this one
diff --git a/libmailutils/tests/parseopt_help02.at b/libmailutils/tests/parseopt_help02.at
index 61dbac3..b88cdf0 100644
--- a/libmailutils/tests/parseopt_help02.at
+++ b/libmailutils/tests/parseopt_help02.at
@@ -21,7 +21,7 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_PROG_NAME=newname parseopt --help
 ],
 [0],
-[[Usage: newname [OPTION]...
+[[Usage: newname [OPTION...]
 
  Group A
   -a, --all                  no arguments to this one
diff --git a/libmailutils/tests/parseopt_help03.at b/libmailutils/tests/parseopt_help03.at
index 8435a9c..cc89a1e 100644
--- a/libmailutils/tests/parseopt_help03.at
+++ b/libmailutils/tests/parseopt_help03.at
@@ -21,7 +21,7 @@ unset ARGP_HELP_FMT
 MU_PARSEOPT_PROG_DOC="Tests option parsing" parseopt --help
 ],
 [0],
-[[Usage: parseopt [OPTION]...
+[[Usage: parseopt [OPTION...]
 Tests option parsing
 
  Group A
diff --git a/libmailutils/tests/parseopt_help04.at b/libmailutils/tests/parseopt_help04.at
index 473c0fb..f859d72 100644
--- a/libmailutils/tests/parseopt_help04.at
+++ b/libmailutils/tests/parseopt_help04.at
@@ -21,7 +21,7 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS" parseopt --help
 ],
 [0],
-[Usage: parseopt [[OPTION]]... SOME MORE ARGS
+[Usage: parseopt [[OPTION...]] SOME MORE ARGS
 
  Group A
   -a, --all                  no arguments to this one
diff --git a/libmailutils/tests/parseopt_help05.at b/libmailutils/tests/parseopt_help05.at
index 2856e61..69058a7 100644
--- a/libmailutils/tests/parseopt_help05.at
+++ b/libmailutils/tests/parseopt_help05.at
@@ -21,7 +21,7 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_BUG_ADDRESS='gray@gnu.org' parseopt --help
 ],
 [0],
-[Usage: parseopt [[OPTION]]...
+[Usage: parseopt [[OPTION...]]
 
  Group A
   -a, --all                  no arguments to this one
diff --git a/libmailutils/tests/parseopt_help06.at b/libmailutils/tests/parseopt_help06.at
index 4562a21..2a2067a 100644
--- a/libmailutils/tests/parseopt_help06.at
+++ b/libmailutils/tests/parseopt_help06.at
@@ -21,7 +21,7 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_PACKAGE_NAME='GNU Mailutils' MU_PARSEOPT_PACKAGE_URL='http://mailutils.org' parseopt --help
 ],
 [0],
-[[Usage: parseopt [OPTION]...
+[[Usage: parseopt [OPTION...]
 
  Group A
   -a, --all                  no arguments to this one
diff --git a/libmailutils/tests/parseopt_help07.at b/libmailutils/tests/parseopt_help07.at
index 1b2e388..0a824c2 100644
--- a/libmailutils/tests/parseopt_help07.at
+++ b/libmailutils/tests/parseopt_help07.at
@@ -27,7 +27,7 @@ MU_PARSEOPT_PROG_DOC="Tests option parsing"\
  parseopt --help
 ],
 [0],
-[[Usage: parseopt [OPTION]... SOME MORE ARGS
+[[Usage: parseopt [OPTION...] SOME MORE ARGS
 Tests option parsing
 
  Group A
diff --git a/libmailutils/tests/parseopt_help08.at b/libmailutils/tests/parseopt_help08.at
index becc899..6d8e193 100644
--- a/libmailutils/tests/parseopt_help08.at
+++ b/libmailutils/tests/parseopt_help08.at
@@ -22,7 +22,7 @@ ARGP_HELP_FMT=dup-args,no-dup-args-note,short-opt-col=1,opt-doc-col=32,header-co
  parseopt --help
 ],
 [0],
-[[Usage: parseopt [OPTION]...
+[[Usage: parseopt [OPTION...]
 
           Group A
  -a,  --all                     no arguments to this one
diff --git a/libmailutils/tests/parseopt_help11.at b/libmailutils/tests/parseopt_help11.at
index 9b7dc2b..93d4d25 100644
--- a/libmailutils/tests/parseopt_help11.at
+++ b/libmailutils/tests/parseopt_help11.at
@@ -21,7 +21,7 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_VERSION_HOOK=1 parseopt --help
 ],
 [0],
-[[Usage: parseopt [OPTION]...
+[[Usage: parseopt [OPTION...]
 
  Group A
   -a, --all                  no arguments to this one
diff --git a/libmailutils/tests/parseopt_help12.at b/libmailutils/tests/parseopt_help12.at
index 674bdf4..86737d0 100644
--- a/libmailutils/tests/parseopt_help12.at
+++ b/libmailutils/tests/parseopt_help12.at
@@ -21,9 +21,9 @@ PARSEOPT_DEFAULT
 MU_PARSEOPT_PROG_ARGS="SOME MORE ARGS|ALTERNATIVE ARGS|ANOTHER ARGS" parseopt --help
 ],
 [0],
-[Usage: parseopt [[OPTION]]... SOME MORE ARGS
-  or:  parseopt [[OPTION]]... ALTERNATIVE ARGS
-  or:  parseopt [[OPTION]]... ANOTHER ARGS
+[Usage: parseopt [[OPTION...]] SOME MORE ARGS
+  or:  parseopt [[OPTION...]] ALTERNATIVE ARGS
+  or:  parseopt [[OPTION...]] ANOTHER ARGS
   
  Group A
   -a, --all                  no arguments to this one


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Oct 16 04:02:34 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bvgOw-0008El-HB
	for mharc-commit-mailutils@gnu.org; Sun, 16 Oct 2016 04:02:34 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:48046)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvgOu-0008EF-2X
	for commit-mailutils@gnu.org; Sun, 16 Oct 2016 04:02:33 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvgOs-0007IH-Ar
	for commit-mailutils@gnu.org; Sun, 16 Oct 2016 04:02:32 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:48219)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvgOs-0007I5-7a
	for commit-mailutils@gnu.org; Sun, 16 Oct 2016 04:02:30 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 147B522016F; Sun, 16 Oct 2016 08:02:30 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-778-gf2279f2
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: e3840467baf287cc14177d224dddc282674f1609
X-Git-Newrev: f2279f27831f79d036ceab51e093250546f8b9d1
Message-Id: <20161016080230.147B522016F@vcs.savannah.gnu.org>
Date: Sun, 16 Oct 2016 08:02:29 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 16 Oct 2016 08:02:33 -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=f2279f27831f79d036ceab51e093250546f8b9d1

The branch, master has been updated
       via  f2279f27831f79d036ceab51e093250546f8b9d1 (commit)
      from  e3840467baf287cc14177d224dddc282674f1609 (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 f2279f27831f79d036ceab51e093250546f8b9d1
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 16 10:52:21 2016 +0300

    Convert comsat to mu_cli

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

Summary of changes:
 comsat/Makefile.am                    |    2 +-
 comsat/comsat.c                       |  165 +++++++++++++++------------------
 libmailutils/cli/Makefile.am          |    1 +
 {libmu_cfg => libmailutils/cli}/acl.c |    6 +-
 4 files changed, 81 insertions(+), 93 deletions(-)
 copy {libmu_cfg => libmailutils/cli}/acl.c (98%)

diff --git a/comsat/Makefile.am b/comsat/Makefile.am
index e67b218..a661ffe 100644
--- a/comsat/Makefile.am
+++ b/comsat/Makefile.am
@@ -31,7 +31,7 @@ biff.rc.h: $(top_srcdir)/comsat/biff.rc
 	  $(top_srcdir)/comsat/biff.rc > biff.rc.h
 
 comsatd_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/comsat/comsat.c b/comsat/comsat.c
index 0911a37..c12ed20 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -18,7 +18,7 @@
 #include "comsat.h"
 #define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
 #include "mailutils/libcfg.h"
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 
 #ifndef PATH_DEV
 # define PATH_DEV "/dev"
@@ -59,44 +59,62 @@ typedef struct utmp UTMP;
 #define MAX_TTY_SIZE (sizeof (PATH_TTY_PFX) + sizeof (((UTMP*)0)->ut_line))
 
 const char *program_version = "comsatd (" PACKAGE_STRING ")";
-static char doc[] = N_("GNU comsatd -- notify users about incoming mail");
-static char args_doc[] = N_("\n--test MBOX-URL MSG-QID");
 
-#define OPT_FOREGROUND 256
+int test_mode;
+char *biffrc = BIFF_RC;
+mu_m_server_t server;
 
-static struct argp_option options[] = 
+static void
+set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
 {
-  { "test", 't', NULL, 0, N_("run in test mode"), 0 },
-  { "foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), 0},
-  { "inetd",  'i', 0, 0, N_("run in inetd mode"), 0 },
-  { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
-    N_("runs in daemon mode with a maximum of NUMBER children"), 0 },
-  { "file", 'f', N_("FILE"), 0,
-    N_("read FILE instead of .biffrc"), 0 },
-  { NULL, 0, NULL, 0, NULL, 0 }
-};
-
-static error_t comsatd_parse_opt (int key, char *arg,
-				  struct argp_state *state);
+  mu_m_server_set_mode (server, MODE_INTERACTIVE);
+}
+  
+static void
+set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  mu_m_server_set_mode (server, MODE_DAEMON);
+  if (arg)
+    {
+      size_t max_children;
+      char *errmsg;
+      int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg);
+      if (rc)
+	{
+	  mu_parseopt_error (po, _("%s: bad argument"), arg);
+	  exit (po->po_exit_error);
+	}
+      mu_m_server_set_max_children (server, max_children);
+    }
+}
 
-static struct argp argp = {
-  options,
-  comsatd_parse_opt,
-  args_doc, 
-  doc,
-  NULL,
-  NULL, NULL
-};
+static void
+set_foreground (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  mu_m_server_set_foreground (server, 1);
+}
 
-static const char *comsat_argp_capa[] = {
-  "mailutils",
-  "common",
-  "debug",
-  "logging",
-  "mailbox",
-  "locking",
-  NULL
-};
+static struct mu_option comsat_options[] = {
+  { "test", 't', NULL, MU_OPTION_DEFAULT,
+    N_("run in test mode"),
+    mu_c_bool, &test_mode },
+  { "foreground",  0, NULL, MU_OPTION_DEFAULT,
+    N_("remain in foreground"),
+    mu_c_bool, NULL, set_foreground },
+  { "inetd",  'i', NULL, MU_OPTION_DEFAULT,
+    N_("run in inetd mode"),
+    mu_c_bool, NULL, set_inetd_mode },
+  { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
+    N_("runs in daemon mode with a maximum of NUMBER children"),
+    mu_c_string, NULL, set_daemon_mode },
+  { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read FILE instead of .biffrc"),
+    mu_c_string, &biffrc },
+  MU_OPTION_END
+}, *options[] = { comsat_options, NULL };
 
 #define SUCCESS 0
 #define NOT_HERE 1
@@ -107,7 +125,6 @@ char *hostname;
 const char *username;
 int require_tty;
 int biffrc_errors = BIFFRC_ERRORS_TO_TTY | BIFFRC_ERRORS_TO_ERR;
-mu_m_server_t server;
 
 static void comsat_init (void);
 static int comsat_main (int fd);
@@ -118,9 +135,6 @@ static char *mailbox_path (const char *user);
 static int change_user (const char *user);
 
 static int reload = 0;
-int test_mode;
-char *biffrc = BIFF_RC;
-
 static int
 biffrc_error_ctl (mu_config_value_t *val, int flag)
 {
@@ -171,55 +185,30 @@ struct mu_cfg_param comsat_cfg_param[] = {
     0, NULL,
     N_("Set overflow control interval.") },
   { "overflow-delay-time", mu_c_time, &overflow_delay_time,
-    0, NULL,
+   0, NULL,
     N_("Time to sleep after the first overflow occurs.") },
   { ".server", mu_cfg_section, NULL, 0, NULL,
     N_("Server configuration.") },
   { NULL }
 };
 
-static error_t
-comsatd_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case 'd':
-      mu_argp_node_list_new (lst, "mode", "daemon");
-      if (arg)
-	mu_argp_node_list_new (lst, "max-children", arg);
-      break;
-
-    case 'f':
-      biffrc = arg;
-      break;
-      
-    case 'i':
-      mu_argp_node_list_new (lst, "mode", "inetd");
-      break;
+static char const *alt_args[] = { N_("--test MBOX-URL MSG-QID"), NULL };
 
-    case OPT_FOREGROUND:
-      mu_argp_node_list_new (lst, "foreground", "yes");
-      break;
-
-    case 't':
-      test_mode = 1;
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
+static struct mu_cli_setup cli = {
+  options,
+  comsat_cfg_param,
+  N_("GNU comsatd -- notify users about incoming mail"),
+  "",
+  alt_args,
+};
 
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
+static char *capa[] = {
+  "debug",
+  "logging",
+  "mailbox",
+  "locking",
+  NULL
+};
 
 static RETSIGTYPE
 sig_hup (int sig)
@@ -558,12 +547,11 @@ int
 main (int argc, char **argv)
 {
   int c;
-  int ind;
-
+  char **save_argv;
+  
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mu_argp_init (NULL, NULL);
   comsat_init ();
   mu_acl_cfg_init ();
   mu_m_server_create (&server, program_version);
@@ -578,19 +566,16 @@ main (int argc, char **argv)
   
   /* FIXME: timeout is not needed. How to disable it? */
   mu_log_syslog = 1;
+
+  save_argv = argv;
   
-  if (mu_app_init (&argp, comsat_argp_capa, comsat_cfg_param, argc, argv, 0,
-		   &ind, server))
-    exit (EXIT_FAILURE);
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   if (test_mode)
     {
       struct passwd *pw;
       char *user;
       
-      argc -= ind;
-      argv += ind;
-  
       mu_stdstream_strerr_setup (MU_STRERR_STDERR);
       biffrc_errors = BIFFRC_ERRORS_TO_ERR;
       if (argc < 2 || argc > 2)
@@ -630,7 +615,7 @@ main (int argc, char **argv)
 
   if (mu_m_server_mode (server) == MODE_DAEMON)
     {
-      if (argv[0][0] != '/')
+      if (save_argv[0][0] != '/')
 	mu_diag_output (MU_DIAG_NOTICE,
 			_("program name is not absolute; reloading will not "
 			  "be possible"));
@@ -651,7 +636,7 @@ main (int argc, char **argv)
       if (reload)
 	{
 	  mu_diag_output (MU_DIAG_NOTICE, _("restarting"));
-	  execvp (argv[0], argv);
+	  execvp (save_argv[0], save_argv);
 	}
     }
   else
diff --git a/libmailutils/cli/Makefile.am b/libmailutils/cli/Makefile.am
index 48770e8..e506b91 100644
--- a/libmailutils/cli/Makefile.am
+++ b/libmailutils/cli/Makefile.am
@@ -18,6 +18,7 @@
 noinst_LTLIBRARIES = libcli.la
 
 libcli_la_SOURCES = \
+ acl.c\
  capa.c\
  cli.c\
  stdcapa.c
diff --git a/libmu_cfg/acl.c b/libmailutils/cli/acl.c
similarity index 98%
copy from libmu_cfg/acl.c
copy to libmailutils/cli/acl.c
index b4bfded..778c3f5 100644
--- a/libmu_cfg/acl.c
+++ b/libmailutils/cli/acl.c
@@ -18,10 +18,12 @@
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
-#include "mailutils/libcfg.h"
 #include "mailutils/acl.h"
 #include "mailutils/argcv.h"
 #include "mailutils/cidr.h"
+#include "mailutils/cfg.h"
+#include "mailutils/errno.h"
+#include "mailutils/nls.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -254,7 +256,7 @@ acl_section_parser (enum mu_cfg_section_stage stage,
 }
 
 void
-mu_acl_cfg_init ()
+mu_acl_cfg_init (void)
 {
   struct mu_cfg_section *section;
   if (mu_create_canned_section ("acl", &section) == 0)


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Oct 16 14:42:42 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bvqOQ-0003fN-FO
	for mharc-commit-mailutils@gnu.org; Sun, 16 Oct 2016 14:42:42 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41516)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvqOL-0003ey-6g
	for commit-mailutils@gnu.org; Sun, 16 Oct 2016 14:42:40 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvqOH-0008MG-Bu
	for commit-mailutils@gnu.org; Sun, 16 Oct 2016 14:42:37 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:54868)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bvqOH-0008M9-6B
	for commit-mailutils@gnu.org; Sun, 16 Oct 2016 14:42:33 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 30DDD22016F; Sun, 16 Oct 2016 18:42:32 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-780-g07d5028
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: f2279f27831f79d036ceab51e093250546f8b9d1
X-Git-Newrev: 07d50280d3a8493c9cc988a541373ba4a5aec81d
Message-Id: <20161016184232.30DDD22016F@vcs.savannah.gnu.org>
Date: Sun, 16 Oct 2016 18:42:32 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 16 Oct 2016 18:42:40 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=07d50280d3a8493c9cc988a541373ba4a5aec81d

The branch, master has been updated
       via  07d50280d3a8493c9cc988a541373ba4a5aec81d (commit)
       via  01adf04ce8e743b7344a8527bccb1959dc7c18d2 (commit)
      from  f2279f27831f79d036ceab51e093250546f8b9d1 (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 07d50280d3a8493c9cc988a541373ba4a5aec81d
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 16 21:37:40 2016 +0300

    Convert popauth to mu_cli

commit 01adf04ce8e743b7344a8527bccb1959dc7c18d2
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 16 20:23:22 2016 +0300

    Convert maidag to mu_cli

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

Summary of changes:
 include/mailutils/cli.h |    2 +
 maidag/Makefile.am      |    2 +-
 maidag/maidag.c         |  377 ++++++++++++++++++------------------
 maidag/maidag.h         |    2 -
 pop3d/popauth.c         |  491 +++++++++++++++++++++++------------------------
 5 files changed, 434 insertions(+), 440 deletions(-)

diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index dec27de..7067f21 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -58,4 +58,6 @@ void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
 
 char *mu_site_config_file (void);
 
+void mu_acl_cfg_init (void);
+
 #endif
diff --git a/maidag/Makefile.am b/maidag/Makefile.am
index 53c887e..008713e 100644
--- a/maidag/Makefile.am
+++ b/maidag/Makefile.am
@@ -36,7 +36,7 @@ maidag_LDADD = \
  @LIBMU_SCM@ @GUILE_LIBS@\
  @LIBMU_SCM_DEPS@\
  @MU_LIB_PY@ @PYTHON_LIBS@\
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_SIEVE}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 85d757b..ddca3ee 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -15,6 +15,7 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "maidag.h"
+#include "mailutils/cli.h"
 
 enum maidag_mode maidag_mode = mode_mda;
 int multiple_delivery;     /* Don't return errors when delivering to multiple
@@ -35,11 +36,11 @@ mu_script_t script_handler;
 mu_list_t script_list;
 
 char *forward_file = NULL;
-#define FORWARD_FILE_PERM_CHECK (					\
+#define FORWARD_FILE_PERM_CHECK (				\
 			   MU_FILE_SAFETY_OWNER_MISMATCH |	\
 			   MU_FILE_SAFETY_GROUP_WRITABLE |	\
 			   MU_FILE_SAFETY_WORLD_WRITABLE |	\
-			   MU_FILE_SAFETY_LINKED_WRDIR |		\
+			   MU_FILE_SAFETY_LINKED_WRDIR |	\
 			   MU_FILE_SAFETY_DIR_IWGRP |		\
 			   MU_FILE_SAFETY_DIR_IWOTH )
 int forward_file_checks = FORWARD_FILE_PERM_CHECK;
@@ -58,92 +59,7 @@ int reuse_lmtp_address = 1;
 int maidag_transcript;
 
 const char *program_version = "maidag (" PACKAGE_STRING ")";
-static char doc[] =
-N_("GNU maidag -- the mail delivery agent.")
-"\v"
-N_("Debug flags are:\n\
-  g - guile stack traces\n\
-  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
-  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
-  l - sieve action logs\n\
-  0-9 - Set maidag debugging level\n");
-
-static char args_doc[] = N_("[recipient...]");
-
-#define STDERR_OPTION 256
-#define MESSAGE_ID_HEADER_OPTION 257
-#define LMTP_OPTION 258
-#define FOREGROUND_OPTION 260
-#define URL_OPTION 261
-#define TRANSCRIPT_OPTION 262
-#define MDA_OPTION 263
-
-static struct argp_option options[] = 
-{
-#define GRID 0
- { NULL, 0, NULL, 0,
-   N_("General options"), GRID },
-      
- { "foreground", FOREGROUND_OPTION, 0, 0, N_("remain in foreground"),
-   GRID + 1 },
- { "inetd",  'i', 0, 0, N_("run in inetd mode"), GRID + 1 },
- { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
-   N_("runs in daemon mode with a maximum of NUMBER children"), GRID + 1 },
- { "url", URL_OPTION, 0, 0, N_("deliver to given URLs"), GRID + 1 },
- { "mda", MDA_OPTION, 0, 0, N_("force MDA mode even if not started as root"),
-   GRID + 1 },
- { "from", 'f', N_("EMAIL"), 0,
-   N_("specify the sender's name"), GRID + 1 },
- { NULL, 'r', NULL, OPTION_ALIAS, NULL },
- { "lmtp", LMTP_OPTION, N_("URL"), OPTION_ARG_OPTIONAL,
-   N_("operate in LMTP mode"), GRID + 1 },
- { "debug", 'x', N_("FLAGS"), 0,
-   N_("enable debugging"), GRID + 1 },
- { "stderr", STDERR_OPTION, NULL, 0,
-   N_("log to standard error"), GRID + 1 },
- { "transcript", TRANSCRIPT_OPTION, NULL, 0,
-   N_("enable session transcript"), GRID + 1 },
-#undef GRID
-
-#define GRID 2
- { NULL, 0, NULL, 0,
-   N_("Scripting options"), GRID },
- 
-  { "language", 'l', N_("STRING"), 0,
-    N_("define scripting language for the next --script option"),
-    GRID + 1 },
-  { "script", 's', N_("PATTERN"), 0,
-    N_("set name pattern for user-defined mail filter"), GRID + 1 },
-  { "message-id-header", MESSAGE_ID_HEADER_OPTION, N_("STRING"), 0,
-    N_("use this header to identify messages when logging Sieve actions"),
-    GRID + 1 },
-#undef GRID
-  { NULL,      0, NULL, 0, NULL, 0 }
-};
-
-static error_t parse_opt (int key, char *arg, struct argp_state *state);
-
-static struct argp argp = {
-  options,
-  parse_opt,
-  args_doc, 
-  doc,
-  NULL,
-  NULL, NULL
-};
-
-static const char *maidag_argp_capa[] = {
-  "mailutils",
-  "auth",
-  "common",
-  "debug",
-  "logging",
-  "mailbox",
-  "locking",
-  "mailer",
-  NULL
-};
-
+
 static void
 set_debug_flags (const char *arg)
 {
@@ -168,106 +84,196 @@ set_debug_flags (const char *arg)
 	}
     }
 }
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+
+static void
+set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
 {
-  static mu_list_t lst;
-
-  switch (key)
+  mu_m_server_set_mode (server, MODE_INTERACTIVE);
+}
+  
+static void
+set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  mu_m_server_set_mode (server, MODE_DAEMON);
+  if (arg)
     {
-    case 'd':
-      mu_argp_node_list_new (lst, "mode", "daemon");
-      if (arg)
-	mu_argp_node_list_new (lst, "max-children", arg);
-      break;
+      size_t max_children;
+      char *errmsg;
+      int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg);
+      if (rc)
+	{
+	  mu_parseopt_error (po, _("%s: bad argument"), arg);
+	  exit (po->po_exit_error);
+	}
+      mu_m_server_set_max_children (server, max_children);
+    }
+}
 
-    case 'i':
-      mu_argp_node_list_new (lst, "mode", "inetd");
-      break;
+static void
+set_foreground (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  mu_m_server_set_foreground (server, 1);
+}
 
-    case FOREGROUND_OPTION:
-      mu_argp_node_list_new (lst, "foreground", "yes");
-      break;
-      
-    case MESSAGE_ID_HEADER_OPTION:
-      mu_argp_node_list_new (lst, "message-id-header", arg);
-      break;
+static void
+set_delivery_url (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  maidag_mode = mode_url;
+  mu_log_syslog = 0;
+}
 
-    case LMTP_OPTION:
-      mu_argp_node_list_new (lst, "delivery-mode", "lmtp");
-      if (arg)
-	mu_argp_node_list_new (lst, "listen", arg);
-      break;
+static void
+set_delivery_mda (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  maidag_mode = mode_mda;
+}
 
-    case MDA_OPTION:
-      mu_argp_node_list_new (lst, "delivery-mode", "mda");
-      break;
-      
-    case TRANSCRIPT_OPTION:
-      maidag_transcript = 1;
-      break;
-      
-    case 'r':
-    case 'f':
-      if (sender_address != NULL)
-	argp_error (state, _("multiple --from options"));
-      sender_address = arg;
-      break;
-      
-    case 'l':
-      script_handler = mu_script_lang_handler (arg);
-      if (!script_handler)
-	argp_error (state, _("unknown or unsupported language: %s"),
-		    arg);
-      break;
+static void
+set_sender_address (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  if (sender_address != NULL)
+    {
+      mu_parseopt_error (po, _("multiple --from options"));
+      exit (po->po_exit_error);
+    }
+  else
+    {
+      char *errmsg;
+      int rc = mu_str_to_c (arg, opt->opt_type, opt->opt_ptr, &errmsg);
+      if (rc)
+	{
+	  mu_parseopt_error (po, _("can't set sender address: %s"),
+			     errmsg ? errmsg : mu_strerror (rc));
+	  exit (po->po_exit_error);
+	}
+    }
+}
+
+static void
+set_lmtp_mode (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  maidag_mode = mode_lmtp;
+  if (arg)
+    {
+      struct mu_sockaddr *s;
       
-    case 's':
-      switch (script_register (arg))
+      if (mu_m_server_parse_url (server, arg, &s))
 	{
-	case 0:
-	  break;
+	  mu_parseopt_error (po, _("%s: invalid URL"), arg);
+	  exit (po->po_exit_error);
+	}
+      mu_m_server_listen (server, s, MU_IP_TCP);
+    }
+}
 
-	case EINVAL:
-	  argp_error (state, _("%s has unknown file suffix"), arg);
-	  break;
+static void
+set_debug (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  set_debug_flags (arg);
+}
 
-	default:
-	  argp_error (state, _("error registering script"));
-	}
-      break;
-      
-    case 'x':
-      mu_argp_node_list_new (lst, "debug", arg);
-      break;
+static void
+set_stderr (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  mu_log_syslog = 0;
+}
 
-    case STDERR_OPTION:
-      mu_argp_node_list_new (lst, "stderr", "yes");
-      break;
+static void
+set_script_lang (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  script_handler = mu_script_lang_handler (arg);
+  if (!script_handler)
+    {
+      mu_parseopt_error (po, _("unknown or unsupported language: %s"), arg);
+      exit (po->po_exit_error);
+    }
+}
 
-    case URL_OPTION:
-      mu_argp_node_list_new (lst, "delivery-mode", "url");
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
+static void
+set_script_pattern (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  switch (script_register (arg))
+    {
+    case 0:
+      return;
+
+    case EINVAL:
+      mu_parseopt_error (po, _("%s has unknown file suffix"), arg);
       break;
-      
-    case ARGP_KEY_ERROR:
-      exit (EX_USAGE);
 
     default:
-      return ARGP_ERR_UNKNOWN;
+      mu_parseopt_error (po, _("error registering script"));
     }
-  return 0;
+  exit (po->po_exit_error);
 }
 
-
+static struct mu_option maidag_options[] = {
+  MU_OPTION_GROUP (N_("General options")),
+  { "foreground",  0, NULL, MU_OPTION_DEFAULT,
+    N_("remain in foreground"),
+    mu_c_bool, NULL, set_foreground },
+  { "inetd",  'i', NULL, MU_OPTION_DEFAULT,
+    N_("run in inetd mode"),
+    mu_c_bool, NULL, set_inetd_mode },
+  { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
+    N_("runs in daemon mode with a maximum of NUMBER children"),
+    mu_c_string, NULL, set_daemon_mode },
+  { "url", 0, NULL, MU_OPTION_DEFAULT,
+    N_("deliver to given URLs"),
+    mu_c_string, NULL, set_delivery_url },
+  { "mda", 0, NULL, MU_OPTION_DEFAULT,
+    N_("force MDA mode even if not started as root"),
+    mu_c_string, NULL, set_delivery_mda },
+  { "from", 'f', N_("EMAIL"), MU_OPTION_DEFAULT,
+    N_("specify the sender's name"),
+    mu_c_string, &sender_address, set_sender_address },
+  { NULL,   'r', NULL, MU_OPTION_ALIAS },
+  { "lmtp", 0, N_("URL"), MU_OPTION_ARG_OPTIONAL,
+    N_("operate in LMTP mode"),
+    mu_c_string, NULL, set_lmtp_mode },
+  { "debug", 'x', N_("FLAGS"), MU_OPTION_DEFAULT,
+    N_("enable debugging"),
+    mu_c_string, NULL, set_debug },
+  { "stderr", 0, NULL, MU_OPTION_DEFAULT,
+    N_("log to standard error"),
+    mu_c_string, NULL, set_stderr },
+  { "transcript", 0, NULL, MU_OPTION_DEFAULT,
+    N_("enable session transcript"),
+    mu_c_bool, &maidag_transcript },
+  
+  MU_OPTION_GROUP (N_("Scripting options")),
+  { "language", 'l', N_("STRING"), MU_OPTION_DEFAULT,
+    N_("define scripting language for the next --script option"),
+    mu_c_string, NULL, set_script_lang },
+  { "script", 's', N_("PATTERN"), MU_OPTION_DEFAULT,
+    N_("set name pattern for user-defined mail filter"),
+    mu_c_string, NULL, set_script_pattern },
+  { "message-id-header", 0, N_("STRING"), MU_OPTION_DEFAULT,
+    N_("use this header to identify messages when logging Sieve actions"),
+    mu_c_string, &message_id_header },
+  MU_OPTION_END
+}, *options[] = { maidag_options, NULL };
 
+static char *capa[] = {
+  "auth",
+  "debug",
+  "logging",
+  "mailbox",
+  "locking",
+  "mailer",
+  "sieve",
+  "tls",
+  NULL
+};
+
 static int
 cb_debug (void *data, mu_config_value_t *val)
 {
@@ -483,6 +489,20 @@ maidag_cfg_init ()
       mu_cfg_section_add_params (section, filter_cfg_param);
     }
 }
+
+struct mu_cli_setup cli = {
+  options,
+  maidag_cfg_param,
+  N_("GNU maidag -- the mail delivery agent."),
+  N_("[recipient...]"),
+  NULL,
+  N_("Debug flags are:\n\
+  g - guile stack traces\n\
+  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
+  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
+  l - sieve action logs\n\
+  0-9 - Set maidag debugging level\n")
+};
 
 /* FIXME: These are for compatibility with MU 2.0.
    Remove in 2.2 */
@@ -494,7 +514,6 @@ extern mu_record_t mu_remote_prog_record;
 int
 main (int argc, char *argv[])
 {
-  int arg_index;
   maidag_delivery_fn delivery_fun = NULL;
   
   /* Preparative work: close inherited fds, force a reasonable umask
@@ -518,18 +537,10 @@ main (int argc, char *argv[])
   mu_register_all_formats ();
   mu_registrar_record (mu_smtp_record);
   
-  mu_gocs_register ("sieve", mu_sieve_module_init);
-
   mu_tcpwrapper_cfg_init ();
   mu_acl_cfg_init ();
   maidag_cfg_init ();
   
-  /* Parse command line */
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_argp_init (NULL, NULL);
-
   mu_m_server_create (&server, program_version);
   mu_m_server_set_conn (server, lmtp_connection);
   mu_m_server_set_prefork (server, mu_tcp_wrapper_prefork);
@@ -541,9 +552,10 @@ main (int argc, char *argv[])
   mu_log_syslog = -1;
   mu_log_print_severity = 1;
   
-  if (mu_app_init (&argp, maidag_argp_capa, maidag_cfg_param, 
-		   argc, argv, 0, &arg_index, server))
-    exit (EX_CONFIG);
+  /* Parse command line */
+  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_cli_capa_register (&mu_cli_capa_sieve);
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   current_uid = getuid ();
 
@@ -554,9 +566,6 @@ main (int argc, char *argv[])
 				 MU_STRERR_SYSLOG : MU_STRERR_STDERR);
     }
   
-  argc -= arg_index;
-  argv += arg_index;
-
   switch (maidag_mode)
     {
     case mode_lmtp:
diff --git a/maidag/maidag.h b/maidag/maidag.h
index d87b401..ac216d1 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -91,8 +91,6 @@
 # define USE_MAILBOX_QUOTAS 1
 #endif
 
-#include "mailutils/libargp.h"
-
 #include "tcpwrap.h"
 #include "muscript.h"
 
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index 6018b2e..8e85438 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -16,11 +16,12 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
-#include "mailutils/libargp.h"
+#include "mailutils/opt.h"
 
 int db_list (char *input_name, char *output_name);
 int db_make (char *input_name, char *output_name);
 
+#define ACT_DEFAULT -1
 #define ACT_CREATE  0
 #define ACT_ADD     1
 #define ACT_DELETE  2
@@ -29,23 +30,19 @@ int db_make (char *input_name, char *output_name);
 
 static int permissions = 0600;
 static int compatibility_option = 0;
-
-struct action_data {
-  int action;
-  char *input_name;
-  char *output_name;
-  char *username;
-  char *passwd;
-};
-
-void check_action(int action);
-int action_create (struct action_data *ap);
-int action_add (struct action_data *ap);
-int action_delete (struct action_data *ap);
-int action_list (struct action_data *ap);
-int action_chpass (struct action_data *ap);
-
-int (*ftab[]) (struct action_data *) = {
+static int action = ACT_DEFAULT;
+static char *input_name;
+static char *output_name;
+static char *user_name;
+static char *user_password;
+
+int action_create (void);
+int action_add (void);
+int action_delete (void);
+int action_list (void);
+int action_chpass (void);
+
+int (*ftab[]) (void) = {
   action_create,
   action_add,
   action_delete,
@@ -53,178 +50,200 @@ int (*ftab[]) (struct action_data *) = {
   action_chpass
 };
 
-static char doc[] = N_("GNU popauth -- manage pop3 authentication database");
-static error_t popauth_parse_opt  (int key, char *arg,
-				   struct argp_state *astate);
-
-void popauth_version (FILE *stream, struct argp_state *state);
-
-#define COMPATIBILITY_OPTION 256
-
-static struct argp_option options[] = 
-{
-  { NULL, 0, NULL, 0, N_("Actions are:"), 1 },
-  { "add", 'a', 0, 0, N_("add user"), 1 },
-  { "modify", 'm', 0, 0, N_("modify user's record (change password)"), 1 },
-  { "delete", 'd', 0, 0, N_("delete user's record"), 1 },
-  { "list", 'l', 0, 0, N_("list the contents of DBM file"), 1 },
-  { "create", 'c', 0, 0, N_("create the DBM from a plaintext file"), 1 },
-
-  { NULL, 0, NULL, 0,
-    N_("Default action is:\n"
-    "  For root: --list\n"
-    "  For a user: --modify --user <username>\n"), 2 },
-  
-  { NULL, 0, NULL, 0, N_("Options are:"), 3 },
-  { "file", 'f', N_("FILE"), 0, N_("read input from FILE (default stdin)"), 3 },
-  { "output", 'o', N_("FILE"), 0, N_("direct output to file"), 3 },
-  { "password", 'p', N_("STRING"), 0, N_("specify user's password"), 3 },
-  { "user", 'u', N_("USERNAME"), 0, N_("specify user name"), 3 },
-  { "permissions", 'P', N_("PERM"), 0, N_("force given permissions on the database"), 3 },
-  { "compatibility", COMPATIBILITY_OPTION, NULL, 0,
-    N_("backward compatibility mode") },
-  { NULL, }
-};
-
-static struct argp argp = {
-  options,
-  popauth_parse_opt,
-  NULL,
-  doc,
-  NULL,
-  NULL, NULL
-};
-
-static const char *popauth_argp_capa[] = {
-  "mailutils",
-  "common",
-  NULL
-};
-
 static void
-set_db_perms (struct argp_state *astate, char *opt, int *pperm)
+set_action (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  int perm = 0;
-   
-  if (mu_isdigit (opt[0]))
+  if (action != -1)
     {
-      char *p;
-      perm = strtoul (opt, &p, 8);
-      if (*p)
-	{
-	  argp_error (astate, _("invalid octal number: %s"), opt);
-	  exit (EX_USAGE);
-	}
+      mu_parseopt_error (po,
+			 _("You may not specify more than one `-aldp' option"));
+      exit (po->po_exit_error);
     }
-  *pperm = perm;
-}
-
-static error_t
-popauth_parse_opt (int key, char *arg, struct argp_state *astate)
-{
-  struct action_data *ap = astate->input;
-  switch (key)
+  
+  switch (opt->opt_short)
     {
-    case ARGP_KEY_INIT:
-      memset (ap, 0, sizeof(*ap));
-      ap->action = -1;
-      break;
-      
     case 'a':
-      check_action (ap->action);
-      ap->action = ACT_ADD;
+      action = ACT_ADD;
       break;
 
     case 'c':
-      check_action (ap->action);
-      ap->action = ACT_CREATE;
+      action = ACT_CREATE;
       break;
       
     case 'l':
-      check_action (ap->action);
-      ap->action = ACT_LIST;
+      action = ACT_LIST;
       break;
 	
     case 'd':
-      check_action (ap->action);
-      ap->action = ACT_DELETE;
-      break;
-	  
-    case 'p':
-      ap->passwd = arg;
+      action = ACT_DELETE;
       break;
-      
+
     case 'm':
-      check_action (ap->action);
-      ap->action = ACT_CHPASS;
-      break;
-	
-    case 'f':
-      ap->input_name = arg;
-      break;
-	  
-    case 'o':
-      ap->output_name = arg;
-      break;
-	
-    case 'u':
-      ap->username = arg;
-      break;
-	
-    case 'P':
-      set_db_perms (astate, arg, &permissions);
+      action = ACT_CHPASS;
       break;
 
-    case COMPATIBILITY_OPTION:
-      compatibility_option = 1;
-      break;
-	
-    case ARGP_KEY_FINI:
-      if (ap->action == -1)
+    default:
+      abort ();
+    }
+}      
+
+static void
+set_permissions (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  if (mu_isdigit (arg[0]))
+    {
+      char *p;
+      permissions = strtoul (arg, &p, 8);
+      if (*p == 0)
+	return;
+    }
+
+  mu_parseopt_error (po, _("invalid octal number: %s"), arg);
+  exit (EX_USAGE);
+}
+
+static struct mu_option popauth_options[] = {
+  MU_OPTION_GROUP (N_("Actions are:")),
+  { "add", 'a', NULL, MU_OPTION_DEFAULT,
+    N_("add user"),
+    mu_c_string, NULL, set_action },
+  { "modify", 'm', NULL, MU_OPTION_DEFAULT,
+    N_("modify user's record (change password)"),
+    mu_c_string, NULL, set_action },
+  { "delete", 'd', NULL, MU_OPTION_DEFAULT,
+    N_("delete user's record"),
+    mu_c_string, NULL, set_action },
+  { "list", 'l', NULL, MU_OPTION_DEFAULT,
+    N_("list the contents of DBM file"),
+    mu_c_string, NULL, set_action },
+  { "create", 'c', NULL, MU_OPTION_DEFAULT,
+    N_("create the DBM from a plaintext file"),
+    mu_c_string, NULL, set_action },
+
+  MU_OPTION_GROUP (N_("Options are:")),
+  { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read input from FILE (default stdin)"),
+    mu_c_string, &input_name },
+  { "output", 'o', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("direct output to file"),
+    mu_c_string, &output_name },
+  { "password", 'p', N_("STRING"), MU_OPTION_DEFAULT,
+    N_("specify user's password"),
+    mu_c_string, &user_password },
+  { "user", 'u', N_("USERNAME"), MU_OPTION_DEFAULT,
+    N_("specify user name"),
+    mu_c_string, &user_name },
+  { "permissions", 'P', N_("PERM"), MU_OPTION_DEFAULT,
+    N_("force given permissions on the database"),
+    mu_c_string, NULL, set_permissions },
+  { "compatibility", 0, NULL, MU_OPTION_DEFAULT,
+    N_("compatibility mode"),
+    mu_c_bool, &compatibility_option },
+  MU_OPTION_END
+}, *options[] = { popauth_options, NULL };
+
+void
+popauth_version (struct mu_parseopt *po, mu_stream_t stream)
+{
+  mu_iterator_t itr;
+  int rc;
+
+  mu_version_func (po, stream);
+  mu_stream_printf (stream, _("Database formats: "));
+
+  rc = mu_dbm_impl_iterator (&itr);
+  if (rc)
+    {
+      mu_stream_printf (stream, "%s\n", _("unknown"));
+      mu_error ("%s", mu_strerror (rc));
+    }
+  else
+    {
+      int i;
+      for (mu_iterator_first (itr), i = 0; !mu_iterator_is_done (itr);
+	   mu_iterator_next (itr), i++)
 	{
-	  /* Deduce the default action */
-	  if (getuid () == 0)
-	    ap->action = ACT_LIST;
-	  else
-	    ap->action = ACT_CHPASS;
-	}
-      break;
+	  struct mu_dbm_impl *impl;
 
-    default:
-      return ARGP_ERR_UNKNOWN;
+	  mu_iterator_current (itr, (void**)&impl);
+	  if (i)
+	    mu_stream_printf (stream, ", ");
+	  mu_stream_printf (stream, "%s", impl->_dbm_name);
+	}
+      mu_stream_printf (stream, "\n");
+      mu_iterator_destroy (&itr);
     }
-  return 0;
+  mu_stream_printf (stream, _("Default database location: %s\n"),
+		    APOP_PASSFILE);
+  exit (EX_OK);
 }
 
+void
+popauth_help_hook (struct mu_parseopt *po, mu_stream_t stream)
+{
+  unsigned margin = 2;
+  
+  mu_stream_printf (stream, "%s", _("Default action is:\n"));
+  mu_stream_ioctl (stream, MU_IOCTL_WORDWRAPSTREAM,
+		   MU_IOCTL_WORDWRAP_SET_MARGIN, &margin);
+  mu_stream_printf (stream, "%s\n", _("For root: --list"));
+  mu_stream_printf (stream, "%s\n",
+		    _("For a user: --modify --user <username>"));
+}
+
 int
 main (int argc, char **argv)
 {
-  struct action_data adata;
-
+  struct mu_parseopt po;
+  int flags;
+  
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mu_argp_init (NULL, NULL);
-  argp_program_version_hook = popauth_version;
-  if (mu_app_init (&argp, popauth_argp_capa, NULL,
-		   argc, argv, 0, NULL, &adata))
-    exit (EX_USAGE);
+  mu_set_program_name (argv[0]);
 
-  return (*ftab[adata.action]) (&adata);
-}
+  po.po_prog_doc = N_("GNU popauth -- manage pop3 authentication database");
+  po.po_package_name = PACKAGE_NAME;
+  po.po_package_url = PACKAGE_URL;
+  po.po_bug_address = PACKAGE_BUGREPORT;
+  po.po_extra_info =
+    N_("General help using GNU software: <http://www.gnu.org/gethelp/>");
+  po.po_version_hook = popauth_version;
+  po.po_help_hook = popauth_help_hook;
+  
+  flags = MU_PARSEOPT_IMMEDIATE
+    | MU_PARSEOPT_DATA
+    | MU_PARSEOPT_PROG_DOC
+    | MU_PARSEOPT_PACKAGE_NAME
+    | MU_PARSEOPT_PACKAGE_URL
+    | MU_PARSEOPT_BUG_ADDRESS
+    | MU_PARSEOPT_EXTRA_INFO
+    | MU_PARSEOPT_VERSION_HOOK
+    | MU_PARSEOPT_HELP_HOOK;
+
+  if (mu_parseopt (&po, argc, argv, options, flags))
+    exit (po.po_exit_error);
+
+  if (argc > po.po_arg_start)
+    {
+      mu_parseopt_error (&po, _("too many arguments"));
+      exit (po.po_exit_error);
+    }
+  mu_parseopt_free (&po);
 
-void
-check_action (int action)
-{
-  if (action != -1)
+  if (action == ACT_DEFAULT)
     {
-      mu_error (_("You may not specify more than one `-aldp' option"));
-      exit (EX_USAGE);
+      if (getuid () == 0)
+	action = ACT_LIST;
+      else
+	action = ACT_CHPASS;
     }
+  return (*ftab[action]) ();
 }
 
 mu_dbm_file_t
-open_db_file (int action, struct action_data *ap, int *my_file)
+open_db_file (int action, int *my_file)
 {
   mu_dbm_file_t db;
   struct passwd *pw;
@@ -241,30 +260,30 @@ open_db_file (int action, struct action_data *ap, int *my_file)
     case ACT_CREATE:
       flags = MU_STREAM_CREAT;
       safety_flags = MU_FILE_SAFETY_NONE;
-      db_name = ap->output_name;
+      db_name = output_name;
       break;
 
     case ACT_ADD:
     case ACT_DELETE:
-      if (!ap->input_name)
-	ap->input_name = APOP_PASSFILE;
+      if (!input_name)
+	input_name = APOP_PASSFILE;
       flags = MU_STREAM_RDWR;
-      db_name = ap->input_name;
+      db_name = input_name;
       break;
       
     case ACT_LIST:
-      if (!ap->input_name)
-	ap->input_name = APOP_PASSFILE;
+      if (!input_name)
+	input_name = APOP_PASSFILE;
       flags = MU_STREAM_READ;
       safety_flags = MU_FILE_SAFETY_NONE;
-      db_name = ap->input_name;
+      db_name = input_name;
       break;
 
     case ACT_CHPASS:
-      if (!ap->input_name)
-	ap->input_name = APOP_PASSFILE;
+      if (!input_name)
+	input_name = APOP_PASSFILE;
       flags = MU_STREAM_RDWR;
-      db_name = ap->input_name;
+      db_name = input_name;
       break;
       
     default:
@@ -336,7 +355,7 @@ open_db_file (int action, struct action_data *ap, int *my_file)
   if (my_file)
     *my_file = 0;
     
-  if (ap->username)
+  if (user_name)
     {
       mu_error (_("Only the file owner can use --username"));
       exit (EX_USAGE);
@@ -350,7 +369,7 @@ open_db_file (int action, struct action_data *ap, int *my_file)
   pw = getpwuid (uid);
   if (!pw)
     exit (EX_OSERR);
-  ap->username = pw->pw_name;
+  user_name = pw->pw_name;
   return db;
 }
 
@@ -373,23 +392,23 @@ print_entry (mu_stream_t str, struct mu_dbm_datum const *key,
 }
 
 int
-action_list (struct action_data *ap)
+action_list (void)
 {
   mu_stream_t str;
   mu_dbm_file_t db;
   struct mu_dbm_datum key, contents;
   int rc;
   
-  db = open_db_file (ACT_LIST, ap, NULL);
+  db = open_db_file (ACT_LIST, NULL);
   
-  if (ap->output_name)
+  if (output_name)
     {
-      int rc = mu_file_stream_create (&str, ap->output_name,
+      int rc = mu_file_stream_create (&str, output_name,
 				      MU_STREAM_WRITE|MU_STREAM_CREAT);
       if (rc)
 	{
 	  mu_error (_("cannot create file %s: %s"),
-		    ap->output_name, mu_strerror (rc));
+		    output_name, mu_strerror (rc));
 	  return 1;
 	}
       mu_stream_truncate (str, 0);
@@ -400,16 +419,16 @@ action_list (struct action_data *ap)
       mu_stream_ref (str);
     }
 
-  if (ap->username)
+  if (user_name)
     {
       memset (&key, 0, sizeof key);
       memset (&contents, 0, sizeof contents);
-      key.mu_dptr = ap->username;
-      key.mu_dsize = strlen (ap->username);
+      key.mu_dptr = user_name;
+      key.mu_dsize = strlen (user_name);
       rc = mu_dbm_fetch (db, &key, &contents);
       if (rc == MU_ERR_NOENT)
 	{
-	  mu_error (_("no such user: %s"), ap->username);
+	  mu_error (_("no such user: %s"), user_name);
 	}
       else if (rc)
 	{
@@ -449,7 +468,7 @@ action_list (struct action_data *ap)
 }
 
 int
-action_create (struct action_data *ap)
+action_create (void)
 {
   int rc;
   mu_stream_t in;
@@ -462,19 +481,19 @@ action_create (struct action_data *ap)
   /* Make sure we have proper privileges if popauth is setuid */
   setuid (getuid ());
   
-  if (ap->input_name)
+  if (input_name)
     {
-      rc = mu_file_stream_create (&in, ap->input_name, MU_STREAM_READ);
+      rc = mu_file_stream_create (&in, input_name, MU_STREAM_READ);
       if (rc)
 	{
 	  mu_error (_("cannot open file %s: %s"),
-		    ap->input_name, mu_strerror (rc));
+		    input_name, mu_strerror (rc));
 	  return 1;
 	}
     }
   else
     {
-      ap->input_name = "";
+      input_name = "";
       rc = mu_stdio_stream_create (&in, MU_STDIN_FD, MU_STREAM_READ);
       if (rc)
 	{
@@ -484,10 +503,10 @@ action_create (struct action_data *ap)
 	}
     }
   
-  if (!ap->output_name)
-    ap->output_name = APOP_PASSFILE;
+  if (!output_name)
+    output_name = APOP_PASSFILE;
 
-  db = open_db_file (ACT_CREATE, ap, NULL);
+  db = open_db_file (ACT_CREATE, NULL);
 
   line = 0;
   while ((rc = mu_stream_getline (in, &buf, &size, &len)) == 0
@@ -502,7 +521,7 @@ action_create (struct action_data *ap)
       pass = mu_str_skip_class_comp (str, MU_CTYPE_SPACE);
       if (*pass == 0)
 	{
-	  mu_error (_("%s:%d: malformed line"), ap->input_name, line);
+	  mu_error (_("%s:%d: malformed line"), input_name, line);
 	  continue;
 	}
       /* Strip trailing semicolon, when in compatibility mode. */
@@ -512,7 +531,7 @@ action_create (struct action_data *ap)
       pass = mu_str_skip_class (pass, MU_CTYPE_SPACE);
       if (*pass == 0)
 	{
-	  mu_error (_("%s:%d: malformed line"), ap->input_name, line);
+	  mu_error (_("%s:%d: malformed line"), input_name, line);
 	  continue;
 	}
       
@@ -526,7 +545,7 @@ action_create (struct action_data *ap)
       rc = mu_dbm_store (db, &key, &contents, 1);
       if (rc)
 	mu_error (_("%s:%d: cannot store datum: %s"),
-		  ap->input_name, line,
+		  input_name, line,
 		  rc == MU_ERR_FAILURE ?
 		     mu_dbm_strerror (db) : mu_strerror (rc));
     }
@@ -543,10 +562,10 @@ open_io (int action, struct action_data *ap, DBM_FILE *db, int *not_owner)
   int rc = check_user_perm (action, ap);
   if (not_owner)
     *not_owner = rc;
-  if (mu_dbm_open (ap->input_name, db, MU_STREAM_RDWR, permissions))
+  if (mu_dbm_open (input_name, db, MU_STREAM_RDWR, permissions))
     {
       mu_error (_("cannot open file %s: %s"),
-		ap->input_name, mu_strerror (errno));
+		input_name, mu_strerror (errno));
       return 1;
     }
   return 0;
@@ -554,9 +573,9 @@ open_io (int action, struct action_data *ap, DBM_FILE *db, int *not_owner)
 */
 
 void
-fill_pass (struct action_data *ap)
+fill_pass (void)
 {
-  if (!ap->passwd)
+  if (!user_password)
     {
       char *p;
       mu_stream_t in, out;
@@ -580,8 +599,8 @@ fill_pass (struct action_data *ap)
 
       while (1)
 	{
-	  if (ap->passwd)
-	    free (ap->passwd);
+	  if (user_password)
+	    free (user_password);
 	  rc = mu_getpass (in, out, _("Password:"), &p);
 	  if (rc)
 	    {
@@ -592,7 +611,7 @@ fill_pass (struct action_data *ap)
 	  if (!p)
 	    exit (EX_DATAERR);
 	  
-	  ap->passwd = mu_strdup (p);
+	  user_password = mu_strdup (p);
 	  /* TRANSLATORS: Please try to format this string so that it has
 	     the same length as the translation of 'Password:' above */
 	  rc = mu_getpass (in, out, _("Confirm :"), &p);
@@ -604,7 +623,7 @@ fill_pass (struct action_data *ap)
 	  
 	  if (!p)
 	    exit (EX_DATAERR);
-	  if (strcmp (ap->passwd, p) == 0)
+	  if (strcmp (user_password, p) == 0)
 	    break;
 	  mu_error (_("Passwords differ. Please retry."));
 	}
@@ -614,28 +633,28 @@ fill_pass (struct action_data *ap)
 }
 
 int
-action_add (struct action_data *ap)
+action_add (void)
 {
   mu_dbm_file_t db;
   struct mu_dbm_datum key, contents;
   int rc;
   
-  if (!ap->username)
+  if (!user_name)
     {
-      mu_error (_("missing username to add"));
+      mu_error (_("missing user name to add"));
       return 1;
     }
 
-  db = open_db_file (ACT_ADD, ap, NULL);
+  db = open_db_file (ACT_ADD, NULL);
 
-  fill_pass (ap);
+  fill_pass ();
   
   memset (&key, 0, sizeof key);
   memset (&contents, 0, sizeof contents);
-  key.mu_dptr = ap->username;
-  key.mu_dsize = strlen (ap->username);
-  contents.mu_dptr = ap->passwd;
-  contents.mu_dsize = strlen (ap->passwd);
+  key.mu_dptr = user_name;
+  key.mu_dsize = strlen (user_name);
+  contents.mu_dptr = user_password;
+  contents.mu_dsize = strlen (user_password);
 
   rc = mu_dbm_store (db, &key, &contents, 1);
   if (rc)
@@ -648,28 +667,28 @@ action_add (struct action_data *ap)
 }
 
 int
-action_delete (struct action_data *ap)
+action_delete (void)
 {
   mu_dbm_file_t db;
   struct mu_dbm_datum key;
   int rc;
   
-  if (!ap->username)
+  if (!user_name)
     {
       mu_error (_("missing username to delete"));
       return 1;
     }
 
-  db = open_db_file (ACT_DELETE, ap, NULL);
+  db = open_db_file (ACT_DELETE, NULL);
 
   memset (&key, 0, sizeof key);
-  key.mu_dptr = ap->username;
-  key.mu_dsize = strlen (ap->username);
+  key.mu_dptr = user_name;
+  key.mu_dsize = strlen (user_name);
 
   rc = mu_dbm_delete (db, &key);
   if (rc)
     mu_error (_("cannot remove record for %s: %s"),
-	      ap->username,
+	      user_name,
 	      rc == MU_ERR_FAILURE ?
 		     mu_dbm_strerror (db) : mu_strerror (rc));
 
@@ -678,31 +697,31 @@ action_delete (struct action_data *ap)
 }
 
 int
-action_chpass (struct action_data *ap)
+action_chpass (void)
 {
   mu_dbm_file_t db;
   struct mu_dbm_datum key, contents;
   int rc;
   int my_file;
   
-  db = open_db_file (ACT_CHPASS, ap, &my_file);
+  db = open_db_file (ACT_CHPASS, &my_file);
 
-  if (!ap->username)
+  if (!user_name)
     {
       struct passwd *pw = getpwuid (getuid ());
-      ap->username = pw->pw_name;
-      printf ("Changing password for %s\n", ap->username);
+      user_name = pw->pw_name;
+      printf ("Changing password for %s\n", user_name);
     }
 
   memset (&key, 0, sizeof key);
   memset (&contents, 0, sizeof contents);
 
-  key.mu_dptr = ap->username;
-  key.mu_dsize = strlen (ap->username);
+  key.mu_dptr = user_name;
+  key.mu_dsize = strlen (user_name);
   rc = mu_dbm_fetch (db, &key, &contents);
   if (rc == MU_ERR_NOENT)
     {
-      mu_error (_("no such user: %s"), ap->username);
+      mu_error (_("no such user: %s"), user_name);
       return 1;
     }
   else if (rc)
@@ -728,11 +747,11 @@ action_chpass (struct action_data *ap)
 	}
     }
 
-  fill_pass (ap);
+  fill_pass ();
   
   mu_dbm_datum_free (&contents);
-  contents.mu_dptr = ap->passwd;
-  contents.mu_dsize = strlen (ap->passwd);
+  contents.mu_dptr = user_password;
+  contents.mu_dsize = strlen (user_password);
   rc = mu_dbm_store (db, &key, &contents, 1);
   if (rc)
     mu_error (_("cannot replace datum: %s"),
@@ -743,37 +762,3 @@ action_chpass (struct action_data *ap)
   return rc;
 }
 
-void
-popauth_version (FILE *stream, struct argp_state *state)
-{
-  mu_iterator_t itr;
-  int rc;
-
-  mu_program_version_hook (stream, state);
-  fprintf (stream, _("Database formats: "));
-
-  rc = mu_dbm_impl_iterator (&itr);
-  if (rc)
-    {
-      fprintf (stream, "%s\n", _("unknown"));
-      mu_error ("%s", mu_strerror (rc));
-    }
-  else
-    {
-      int i;
-      for (mu_iterator_first (itr), i = 0; !mu_iterator_is_done (itr);
-	   mu_iterator_next (itr), i++)
-	{
-	  struct mu_dbm_impl *impl;
-
-	  mu_iterator_current (itr, (void**)&impl);
-	  if (i)
-	    fprintf (stream, ", ");
-	  fprintf (stream, "%s", impl->_dbm_name);
-	}
-      fputc ('\n', stream);
-      mu_iterator_destroy (&itr);
-    }
-  fprintf (stream, _("Default database location: %s\n"), APOP_PASSFILE);
-  exit (EX_OK);
-}


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 17 01:20:32 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bw0Lg-0004Fd-5E
	for mharc-commit-mailutils@gnu.org; Mon, 17 Oct 2016 01:20:32 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49794)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bw0Ld-0004FW-Lt
	for commit-mailutils@gnu.org; Mon, 17 Oct 2016 01:20:31 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bw0Lc-0004Wi-4o
	for commit-mailutils@gnu.org; Mon, 17 Oct 2016 01:20:29 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:60595)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bw0Lc-0004We-0e
	for commit-mailutils@gnu.org; Mon, 17 Oct 2016 01:20:28 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id DB78322016F; Mon, 17 Oct 2016 05:20:27 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-781-gd1339b3
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 07d50280d3a8493c9cc988a541373ba4a5aec81d
X-Git-Newrev: d1339b3ffaa3d82e21c3a36e5bdfccee3246904d
Message-Id: <20161017052027.DB78322016F@vcs.savannah.gnu.org>
Date: Mon, 17 Oct 2016 05:20:27 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 17 Oct 2016 05:20:31 -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=d1339b3ffaa3d82e21c3a36e5bdfccee3246904d

The branch, master has been updated
       via  d1339b3ffaa3d82e21c3a36e5bdfccee3246904d (commit)
      from  07d50280d3a8493c9cc988a541373ba4a5aec81d (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 d1339b3ffaa3d82e21c3a36e5bdfccee3246904d
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Mon Oct 17 08:05:49 2016 +0300

    Convert pop3d to mu_cli

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

Summary of changes:
 pop3d/Makefile.am |    2 +-
 pop3d/pop3d.c     |  131 +++++++++++++++++++++++++----------------------------
 2 files changed, 62 insertions(+), 71 deletions(-)

diff --git a/pop3d/Makefile.am b/pop3d/Makefile.am
index 792acd4..7fea649 100644
--- a/pop3d/Makefile.am
+++ b/pop3d/Makefile.am
@@ -51,7 +51,7 @@ if MU_COND_DBM
 endif
 
 pop3d_LDADD = \
- ${MU_APP_LIBRARIES}\
+ ${MU_APP_NEW_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_MH}\
  ${MU_LIB_MAILDIR}\
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index ca1a1af..9329725 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -17,7 +17,7 @@
 
 #include "pop3d.h"
 #include "mailutils/pam.h"
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 #include "mailutils/pop3.h"
 #include "mailutils/kwd.h"
 #include "tcpwrap.h"
@@ -59,24 +59,55 @@ char *login_stat_file = LOGIN_STAT_FILE;
 unsigned expire = EXPIRE_NEVER; /* Expire messages after this number of days */
 int expire_on_exit = 0;         /* Delete expired messages on exit */
 
-static error_t pop3d_parse_opt  (int key, char *arg, struct argp_state *astate);
-
 const char *program_version = "pop3d (" PACKAGE_STRING ")";
-static char doc[] = N_("GNU pop3d -- the POP3 daemon.");
+
+static void
+set_foreground (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  mu_m_server_set_foreground (server, 1);
+}
 
-#define OPT_FOREGROUND      256
+static void
+set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  mu_m_server_set_mode (server, MODE_INTERACTIVE);
+}
+  
+static void
+set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  mu_m_server_set_mode (server, MODE_DAEMON);
+  if (arg)
+    {
+      size_t max_children;
+      char *errmsg;
+      int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg);
+      if (rc)
+	{
+	  mu_parseopt_error (po, _("%s: bad argument"), arg);
+	  exit (po->po_exit_error);
+	}
+      mu_m_server_set_max_children (server, max_children);
+    }
+}
 
-static struct argp_option options[] = {
-#define GRP 0
-  { "foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), GRP+1},
-  { "inetd",  'i', 0, 0, N_("run in inetd mode"), GRP+1},
-  { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
-    N_("runs in daemon mode with a maximum of NUMBER children"), GRP+1 },
-#undef GRP
+static struct mu_option pop3d_options[] = {
+  { "foreground",  0, NULL, MU_OPTION_DEFAULT,
+    N_("remain in foreground"),
+    mu_c_bool, NULL, set_foreground },
+  { "inetd",  'i', NULL, MU_OPTION_DEFAULT,
+    N_("run in inetd mode"),
+    mu_c_bool, NULL, set_inetd_mode },
+  { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
+    N_("runs in daemon mode with a maximum of NUMBER children"),
+    mu_c_string, NULL, set_daemon_mode },
 
   {NULL, 0, NULL, 0, NULL, 0}
-};
-
+}, *options[] = { pop3d_options, NULL };
+
 static int
 cb_bulletin_source (void *data, mu_config_value_t *val)
 {
@@ -271,61 +302,22 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
   { NULL }
 };
     
-static struct argp argp = {
-  options,
-  pop3d_parse_opt,
-  NULL,
-  doc,
-  NULL,
-  NULL, NULL
-};
-
-static const char *pop3d_argp_capa[] = {
-  "mailutils",
+static char *capa[] = {
   "auth",
-  "common",
   "debug",
   "mailbox",
   "locking",
   "logging",
+  "tls",
   NULL
 };
 
-static error_t
-pop3d_parse_opt (int key, char *arg, struct argp_state *astate)
-{
-  static mu_list_t lst;
-  
-  switch (key)
-    {
-    case 'd':
-      mu_argp_node_list_new (lst, "mode", "daemon");
-      if (arg)
-	mu_argp_node_list_new (lst, "max-children", arg);
-      break;
-
-    case 'i':
-      mu_argp_node_list_new (lst, "mode", "inetd");
-      break;
-
-    case OPT_FOREGROUND:
-      mu_argp_node_list_new (lst, "foreground", "yes");
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+struct mu_cli_setup cli = {
+  options,
+  pop3d_cfg_param,
+  N_("GNU pop3d -- the POP3 daemon."),
+};
+
 int
 pop3d_get_client_address (int fd, struct sockaddr_in *pcs)
 {
@@ -569,15 +561,10 @@ main (int argc, char **argv)
   /* Register the desired formats.  */
   mu_register_local_mbox_formats ();
 
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif /* WITH_TLS */
   mu_tcpwrapper_cfg_init ();
   manlock_cfg_init ();
   mu_acl_cfg_init ();
   
-  mu_argp_init (NULL, NULL);
-  	
   mu_m_server_create (&server, program_version);
   mu_m_server_set_config_size (server, sizeof (struct pop3d_srv_config));
   mu_m_server_set_conn (server, pop3d_connection);
@@ -598,10 +585,14 @@ main (int argc, char **argv)
 #ifdef ENABLE_DBM
   set_dbm_safety ();
 #endif
-  
-  if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, 
-		   argc, argv, 0, NULL, server))
-    exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
+  mu_cli_capa_register (&mu_cli_capa_tls);
+
+  mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
+  if (argc)
+    {
+      mu_error (_("too many arguments"));
+      exit (EX_USAGE);
+    }
 
   if (expire == 0)
     expire_on_exit = 1;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Oct 19 12:26:28 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bwthE-000068-G4
	for mharc-commit-mailutils@gnu.org; Wed, 19 Oct 2016 12:26:28 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:60587)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bwtgr-0008LK-CM
	for commit-mailutils@gnu.org; Wed, 19 Oct 2016 12:26:26 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bwtgX-0001Br-54
	for commit-mailutils@gnu.org; Wed, 19 Oct 2016 12:26:05 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:38328)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bwtgW-0001Av-Fs
	for commit-mailutils@gnu.org; Wed, 19 Oct 2016 12:25:44 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 5914D22014E; Wed, 19 Oct 2016 16:25:44 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-783-g3dc3771
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d1339b3ffaa3d82e21c3a36e5bdfccee3246904d
X-Git-Newrev: 3dc377159eb6afba231bcbdaf6a2d4331c0c337d
Message-Id: <20161019162544.5914D22014E@vcs.savannah.gnu.org>
Date: Wed, 19 Oct 2016 16:25:44 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 19 Oct 2016 16:26:26 -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=3dc377159eb6afba231bcbdaf6a2d4331c0c337d

The branch, master has been updated
       via  3dc377159eb6afba231bcbdaf6a2d4331c0c337d (commit)
       via  dc78d43ff77a65e3400af0401142aca2ebb6cd1e (commit)
      from  d1339b3ffaa3d82e21c3a36e5bdfccee3246904d (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 3dc377159eb6afba231bcbdaf6a2d4331c0c337d
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Oct 19 19:20:58 2016 +0300

    Rename MU_APP_NEW_LIBRARIES back to MU_APP_LIBRARIES. Version 2.99.991.

commit dc78d43ff77a65e3400af0401142aca2ebb6cd1e
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Wed Oct 19 17:20:42 2016 +0300

    Convert remaining utilities (except mh) to mu_cli.
    
    * Makefile.am: Remove libmu_argp and libmu_cfg
    * configure.ac: Likewise.
    * libmu_argp/: Remove.
    * libmu_cfg/: Remove.
    * include/mailutils/Makefile.am (pkginclude_HEADERS): Remove gocs.h,
    libargp.h, libcfg.h
    
    * frm/frm.c: Register tls auth module
    * frm/from.c: Likewise.
    * maidag/maidag.c: Likewise.
    * mail/mail.c: Likewise.
    * messages/messages.c: Likewise.
    * movemail/movemail.c: Likewise.
    * readmsg/readmsg.c: Likewise.
    * sieve/sieve.c: Likewise.
    * frm/frm.h: Remove obsolete includes
    
    * imap4d/Makefile.am: Update.
    * imap4d/imap4d.c: Use mu_cli for command line and configuration
    parsing.
    * imap4d/imap4d.h: Update.
    
    * include/mailutils/gocs.h: Remove.
    * libmailutils/cfg/gocs.c: Remove.
    * libmailutils/cfg/Makefile.am: Remove gocs.c
    
    * include/mailutils/cli.h (mu_cli_capa_apply): Rename to
    mu_cli_capa_extend_settings
    (mu_cli_setup) <inorder, prog_doc_hook>: New fields.
    * include/mailutils/daemon.h: Remove obsolete includes.
    * include/mailutils/gsasl.h: Likewise.
    * include/mailutils/mailutils.h: Update.
    * include/mailutils/mu_auth.h (mu_auth_mode): New enum
    (mu_auth_module): Redo structure.
    * include/mailutils/opt.h (mu_parseopt) <po_prog_doc_hook>: New field.
    * include/mailutils/sql.h (mu_sql_module_config): New extern.
    (mu_sql_interface_index): Change proto.
    * libmailutils/auth/mu_auth.c: Rewrite.
    * libmailutils/auth/system.c (mu_auth_system_module): Update structure
    * libmailutils/cli/capa.c (mu_cli_capa_apply): Rename to
    mu_cli_capa_extend_settings
    * libmailutils/cli/cli.c: Extend settings from auth modules as well.
    * libmailutils/opt/help.c (mu_program_help): Invoke po_prog_doc_hook
    if defined.
    * libmailutils/opt/opt.c (parseopt_init): Check the
    MU_PARSEOPT_PROG_DOC_HOOK flag.
    (find_long_option): Fix recognition of ambiguous options in case
    of exact match.
    * libmu_auth/gsasl.c: Add configuration.
    * libmu_auth/ldap.c: Likewise.
    * libmu_auth/pam.c: Likewise.
    * libmu_auth/radius.c: Likewise.
    * libmu_auth/sql.c: Likewise.
    * libmu_auth/tls.c: Likewise.
    * libmu_auth/virtual.c: Likewise.
    
    * mu/Makefile.am: Update.
    * mu/mu.c: Rewrite using mu_cli
    * mu/mu.h: Likewise.
    * mu/acl.c: Likewise.
    * mu/cflags.c: Likewise.
    * mu/dbm.c: Likewise.
    * mu/dispatch.c: Likewise.
    * mu/filter.c: Likewise.
    * mu/flt2047.c: Likewise.
    * mu/getans.c: Likewise.
    * mu/getarg.c: Likewise.
    * mu/getyn.c: Likewise.
    * mu/help.c: Likewise.
    * mu/imap.c: Likewise.
    * mu/info.c: Likewise.
    * mu/ldflags.c: Likewise.
    * mu/logger.c: Likewise.
    * mu/pop.c: Likewise.
    * mu/query.c: Likewise.
    * mu/send.c: Likewise.
    * mu/shell.c: Likewise.
    * mu/smtp.c: Likewise.
    * mu/util.c: Likewise.
    * mu/verbose.c: Likewise.
    * mu/wicket.c: Likewise.
    
    * pop3d/Makefile.am: Update.
    * pop3d/pop3d.c: Convert to mu_cli interface.
    * pop3d/pop3d.h: Likewise.
    
    * sql/sql.c (mu_sql_interface_index): Change argument qualifiers.

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

Summary of changes:
 Makefile.am                   |    2 -
 NEWS                          |    4 +-
 comsat/Makefile.am            |    2 +-
 configure.ac                  |    7 +-
 dotlock/Makefile.am           |    2 +-
 examples/Makefile.am          |    4 +-
 frm/Makefile.am               |    2 +-
 frm/frm.c                     |    3 +-
 frm/frm.h                     |    1 +
 frm/from.c                    |    3 +-
 gnulib.modules                |    1 -
 imap4d/imap4d.c               |  166 +++++++++---------
 imap4d/imap4d.h               |    1 +
 include/mailutils/Makefile.am |    3 -
 include/mailutils/cli.h       |    5 +-
 include/mailutils/daemon.h    |    3 -
 include/mailutils/gocs.h      |   98 -----------
 include/mailutils/gsasl.h     |    6 +-
 include/mailutils/libargp.h   |   97 -----------
 include/mailutils/libcfg.h    |  101 -----------
 include/mailutils/mailutils.h |    2 +-
 include/mailutils/mu_auth.h   |   42 +++--
 include/mailutils/opt.h       |    2 +
 include/mailutils/radius.h    |    2 -
 include/mailutils/sieve.h     |   11 --
 include/mailutils/sql.h       |   22 +--
 include/mailutils/tls.h       |    2 -
 include/mailutils/types.hin   |    6 -
 lib/Makefile.am               |    1 -
 lib/argp_base.c               |   31 ----
 libmailutils/auth/mu_auth.c   |  191 ++++++++++----------
 libmailutils/auth/system.c    |   26 ++-
 libmailutils/cfg/Makefile.am  |    3 +-
 libmailutils/cfg/gocs.c       |  387 -----------------------------------------
 libmailutils/cli/capa.c       |    7 +-
 libmailutils/cli/cli.c        |   37 +++-
 libmailutils/opt/help.c       |    6 +
 libmailutils/opt/opt.c        |    4 +
 libmu_argp/.gitignore         |    7 -
 libmu_argp/Makefile.am        |   39 -----
 libmu_argp/cmdline.c          |  111 ------------
 libmu_argp/cmdline.h          |   22 ---
 libmu_argp/common.c           |  306 --------------------------------
 libmu_argp/mailutils.c        |  146 ----------------
 libmu_argp/mu_argp.c          |  227 ------------------------
 libmu_argp/muinit.c           |  213 -----------------------
 libmu_argp/sieve.c            |  103 -----------
 libmu_auth/gsasl.c            |   37 +++-
 libmu_auth/ldap.c             |  101 +++++++++--
 libmu_auth/pam.c              |   48 ++---
 libmu_auth/radius.c           |  147 ++++++++--------
 libmu_auth/sql.c              |  136 ++++++++++-----
 libmu_auth/tls.c              |   30 +---
 libmu_auth/virtual.c          |   51 ++----
 libmu_cfg/.gitignore          |    7 -
 libmu_cfg/Makefile.am         |   38 ----
 libmu_cfg/acl.c               |  265 ----------------------------
 libmu_cfg/auth.c              |  131 --------------
 libmu_cfg/common.c            |  213 -----------------------
 libmu_cfg/gsasl.c             |   52 ------
 libmu_cfg/init.c              |  197 ---------------------
 libmu_cfg/ldap.c              |  101 -----------
 libmu_cfg/pam.c               |   35 ----
 libmu_cfg/radius.c            |   43 -----
 libmu_cfg/sieve.c             |  121 -------------
 libmu_cfg/sql.c               |  100 -----------
 libmu_cfg/tls.c               |  126 --------------
 libmu_cfg/virtdomain.c        |   36 ----
 libmu_sieve/conf.c            |   62 +++----
 maidag/Makefile.am            |    2 +-
 maidag/maidag.c               |    3 +-
 mail/Makefile.am              |    2 +-
 mail/mail.c                   |    5 +-
 messages/Makefile.am          |    2 +-
 messages/messages.c           |    3 +-
 mimeview/Makefile.am          |    2 +-
 movemail/Makefile.am          |    2 +-
 movemail/movemail.c           |    7 +-
 mu/acl.c                      |   77 ++------
 mu/cflags.c                   |   29 +--
 mu/dbm.c                      |  297 ++++++++++++++++---------------
 mu/dispatch.c                 |   41 ++---
 mu/filter.c                   |   77 +++-----
 mu/flt2047.c                  |   87 +++------
 mu/getans.c                   |    4 -
 mu/getarg.c                   |   10 +-
 mu/getyn.c                    |    4 -
 mu/help.c                     |   25 +--
 mu/imap.c                     |   36 +---
 mu/info.c                     |   49 +-----
 mu/ldflags.c                  |   27 +--
 mu/logger.c                   |  197 ++++++++++-----------
 mu/mu.c                       |  141 +++++++--------
 mu/mu.h                       |   17 +-
 mu/pop.c                      |   47 +----
 mu/query.c                    |  113 ++++--------
 mu/send.c                     |   81 +++------
 mu/shell.c                    |   10 +-
 mu/smtp.c                     |   35 +---
 mu/util.c                     |    8 -
 mu/verbose.c                  |    6 -
 mu/wicket.c                   |   69 ++------
 po/POTFILES.in                |   22 ---
 pop3d/Makefile.am             |    2 +-
 pop3d/pop3d.c                 |    5 +-
 pop3d/pop3d.h                 |    1 +
 readmsg/Makefile.am           |    2 +-
 readmsg/readmsg.c             |    4 +-
 sieve/Makefile.am             |    2 +-
 sieve/sieve.c                 |    4 +-
 sql/sql.c                     |    2 +-
 111 files changed, 1161 insertions(+), 4942 deletions(-)
 delete mode 100644 include/mailutils/gocs.h
 delete mode 100644 include/mailutils/libargp.h
 delete mode 100644 include/mailutils/libcfg.h
 delete mode 100644 lib/argp_base.c
 delete mode 100644 libmailutils/cfg/gocs.c
 delete mode 100644 libmu_argp/.gitignore
 delete mode 100644 libmu_argp/Makefile.am
 delete mode 100644 libmu_argp/cmdline.c
 delete mode 100644 libmu_argp/cmdline.h
 delete mode 100644 libmu_argp/common.c
 delete mode 100644 libmu_argp/mailutils.c
 delete mode 100644 libmu_argp/mu_argp.c
 delete mode 100644 libmu_argp/muinit.c
 delete mode 100644 libmu_argp/sieve.c
 delete mode 100644 libmu_cfg/.gitignore
 delete mode 100644 libmu_cfg/Makefile.am
 delete mode 100644 libmu_cfg/acl.c
 delete mode 100644 libmu_cfg/auth.c
 delete mode 100644 libmu_cfg/common.c
 delete mode 100644 libmu_cfg/gsasl.c
 delete mode 100644 libmu_cfg/init.c
 delete mode 100644 libmu_cfg/ldap.c
 delete mode 100644 libmu_cfg/pam.c
 delete mode 100644 libmu_cfg/radius.c
 delete mode 100644 libmu_cfg/sieve.c
 delete mode 100644 libmu_cfg/sql.c
 delete mode 100644 libmu_cfg/tls.c
 delete mode 100644 libmu_cfg/virtdomain.c

diff --git a/Makefile.am b/Makefile.am
index 941eb3a..3f1b6d5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,8 +97,6 @@ SUBDIRS = . \
  libmu_compat\
  testsuite\
  lib\
- libmu_argp\
- libmu_cfg\
  $(LIBMU_CPP_DIR)\
  $(GINT_DIR)\
  $(LIBMU_SCM_DIR)\
diff --git a/NEWS b/NEWS
index 4614802..7ebc72a 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,11 @@
-GNU mailutils NEWS -- history of user-visible changes. 2016-01-22
+GNU mailutils NEWS -- history of user-visible changes. 2016-10-19
 Copyright (C) 2002-2016 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
 Please send mailutils bug reports to <bug-mailutils@gnu.org>.
 
 
-Version 2.99.99 (Git)
+Version 2.99.991 (Git)
 
 This version is a major rewrite of GNU Mailutils.  Quite a few parts
 of the basic framework were rewritten from scratch, while some others
diff --git a/comsat/Makefile.am b/comsat/Makefile.am
index a661ffe..e67b218 100644
--- a/comsat/Makefile.am
+++ b/comsat/Makefile.am
@@ -31,7 +31,7 @@ biff.rc.h: $(top_srcdir)/comsat/biff.rc
 	  $(top_srcdir)/comsat/biff.rc > biff.rc.h
 
 comsatd_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/configure.ac b/configure.ac
index d9f1b58..5fd7d85 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU General Public License along
 dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AC_PREREQ(2.63)
-AC_INIT([GNU Mailutils], [2.99.99], [bug-mailutils@gnu.org], [mailutils],
+AC_INIT([GNU Mailutils], [2.99.991], [bug-mailutils@gnu.org], [mailutils],
         [http://mailutils.org])
 AC_CONFIG_SRCDIR([libmailutils/mailbox/mailbox.c])
 AC_CONFIG_AUX_DIR([build-aux])
@@ -57,8 +57,7 @@ AC_SUBST(mu_aux_dir,'$(top_srcdir)/mu-aux')
 AC_SUBST(MU_SIEVE_MODDIR,'$(libdir)/$(PACKAGE)')
 
 AC_SUBST(MU_COMMON_LIBRARIES,'$(LTLIBINTL) $(LTLIBICONV)')
-AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/libmu_argp/libmu_argp.la ${top_builddir}/libmu_cfg/libmu_cfg.la ${top_builddir}/lib/libmuaux.la')
-AC_SUBST(MU_APP_NEW_LIBRARIES,'${top_builddir}/lib/libmuaux.la')
+AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/lib/libmuaux.la')
 
 # There are two sets of include directories: MU_LIB_COMMON_INCLUDES, used
 # by the libraries, and MU_APP_COMMON_INCLUDES, which is used by applications.
@@ -1480,9 +1479,7 @@ AC_CONFIG_FILES([
  include/mailutils/cpp/Makefile
  lib/Makefile
  lib/gnu/Makefile
- libmu_argp/Makefile
  libmu_auth/Makefile
- libmu_cfg/Makefile
  libmu_cpp/Makefile
  libmu_scm/Makefile
  libmu_scm/mailutils/Makefile
diff --git a/dotlock/Makefile.am b/dotlock/Makefile.am
index 0ab3f34..3425b0f 100644
--- a/dotlock/Makefile.am
+++ b/dotlock/Makefile.am
@@ -20,7 +20,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
 bin_PROGRAMS = dotlock
 
 dotlock_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MAILUTILS}\
  @MU_COMMON_LIBRARIES@
 
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 5ffabeb..55b53df 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -113,14 +113,14 @@ lsf_LDADD = \
 
 muauth_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
 muauth_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_AUTH}\
  @MU_AUTHLIBS@ \
  ${MU_LIB_MAILUTILS}
 
 muemail_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
 muemail_LDADD = \
- ${MU_APP_NEW_LIBRARIES} \
+ ${MU_APP_LIBRARIES} \
  ${MU_LIB_MAILUTILS}
 
 mboxidx_CPPFLAGS = @MU_APP_COMMON_INCLUDES@
diff --git a/frm/Makefile.am b/frm/Makefile.am
index 8678e2f..7861b51 100644
--- a/frm/Makefile.am
+++ b/frm/Makefile.am
@@ -27,7 +27,7 @@ frm_LDADD =  $(common_ldadd)
 from_LDADD = $(common_ldadd)
 
 common_ldadd = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/frm/frm.c b/frm/frm.c
index 99db191..192521c 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -181,7 +181,6 @@ static char *frm_argp_capa[] = {
   "debug",
   "mailbox",
   "locking",
-  "tls",
   NULL
 };
 
@@ -328,7 +327,7 @@ main (int argc, char **argv)
   /* register the formats.  */
   mu_register_all_mbox_formats ();
 
-  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_auth_register_module (&mu_auth_tls_module);
   mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
 
   if (align && (s = util_getcols ()))
diff --git a/frm/frm.h b/frm/frm.h
index 60b10a0..b6d3237 100644
--- a/frm/frm.h
+++ b/frm/frm.h
@@ -63,6 +63,7 @@
 #include <mailutils/error.h>
 #include <mailutils/util.h>
 #include <mailutils/mime.h>
+#include <mailutils/mu_auth.h>
 
 #include "mailutils/cli.h"
 
diff --git a/frm/from.c b/frm/from.c
index 7995bb4..588f766 100644
--- a/frm/from.c
+++ b/frm/from.c
@@ -48,7 +48,6 @@ static char *capa[] = {
   "debug",
   "mailbox",
   "locking",
-  "tls",
   NULL
 };
 
@@ -89,7 +88,7 @@ main (int argc, char **argv)
   /* register the formats.  */
   mu_register_all_mbox_formats ();
 
-  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_auth_register_module (&mu_auth_tls_module);
   mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   if (argc > 1)
diff --git a/gnulib.modules b/gnulib.modules
index a552282..b672acc 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -4,7 +4,6 @@
 # FIXME: fnmatch, regex and glob are used by libmailutils...
 
 autobuild
-argp
 crypto/des
 gettext
 gitlog-to-changelog
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index a256dd4..2c97505 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -17,7 +17,7 @@
 
 #include "imap4d.h"
 #include <mailutils/gsasl.h>
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 #include "mailutils/kwd.h"
 #include "tcpwrap.h"
 
@@ -56,93 +56,79 @@ int ident_encrypt_only;
 int test_mode;
 
 const char *program_version = "imap4d (" PACKAGE_STRING ")";
-static char doc[] = N_("GNU imap4d -- the IMAP4D daemon.");
-
-#define OPT_PREAUTH         259
-#define OPT_FOREGROUND      260
-#define OPT_TEST_MODE       261
-
-static struct argp_option options[] = {
-  { "foreground", OPT_FOREGROUND, 0, 0, N_("remain in foreground"), 0},
-  { "inetd",  'i', 0, 0, N_("run in inetd mode"), 0},
-  { "daemon", 'd', N_("NUMBER"), OPTION_ARG_OPTIONAL,
-    N_("runs in daemon mode with a maximum of NUMBER children"), 0 },
-  { "test", OPT_TEST_MODE, 0, 0,
-    N_("run in test mode"), 0 },
-  { "preauth", OPT_PREAUTH, NULL, 0,
-    N_("start in preauth mode") },
+
+
+static void
+set_foreground (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  mu_m_server_set_foreground (server, 1);
+}
+
+static void
+set_inetd_mode (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  mu_m_server_set_mode (server, MODE_INTERACTIVE);
+}
   
-  {NULL, 0, NULL, 0, NULL, 0}
-};
+static void
+set_daemon_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  mu_m_server_set_mode (server, MODE_DAEMON);
+  if (arg)
+    {
+      size_t max_children;
+      char *errmsg;
+      int rc = mu_str_to_c (arg, mu_c_size, &max_children, &errmsg);
+      if (rc)
+	{
+	  mu_parseopt_error (po, _("%s: bad argument"), arg);
+	  exit (po->po_exit_error);
+	}
+      mu_m_server_set_max_children (server, max_children);
+    }
+}
 
+static void
+set_preauth (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  preauth_mode = preauth_stdio;
+}
 
-static error_t imap4d_parse_opt (int key, char *arg,
-				 struct argp_state *state);
+static struct mu_option imap4d_options[] = {
+  { "foreground",  0, NULL, MU_OPTION_DEFAULT,
+    N_("remain in foreground"),
+    mu_c_bool, NULL, set_foreground },
+  { "inetd",  'i', NULL, MU_OPTION_DEFAULT,
+    N_("run in inetd mode"),
+    mu_c_bool, NULL, set_inetd_mode },
+  { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
+    N_("runs in daemon mode with a maximum of NUMBER children"),
+    mu_c_string, NULL, set_daemon_mode },
 
-static struct argp argp = {
-  options,
-  imap4d_parse_opt,
-  NULL,
-  doc,
-  NULL,
-  NULL, NULL
-};
+  { "test", 0, NULL, MU_OPTION_DEFAULT,
+    N_("run in test mode"),
+    mu_c_bool, &test_mode },
 
-static const char *imap4d_capa[] = {
-  "mailutils",
+  { "preauth", 0, NULL, MU_OPTION_DEFAULT,
+    N_("start in preauth mode"),
+    mu_c_string, NULL, set_preauth },
+
+  MU_OPTION_END
+}, *options[] = { imap4d_options, NULL };
+
+
+static char *capa[] = {
   "auth",
-  "common",
   "debug",
   "mailbox",
   "locking",
   "logging",
   NULL
 };
-
-static error_t
-imap4d_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case 'd':
-      mu_argp_node_list_new (lst, "mode", "daemon");
-      if (arg)
-	mu_argp_node_list_new (lst, "max-children", arg);
-      break;
-
-    case 'i':
-      mu_argp_node_list_new (lst, "mode", "inetd");
-      break;
-
-    case OPT_FOREGROUND:
-      mu_argp_node_list_new (lst, "foreground", "yes");
-      break;
-      
-    case OPT_PREAUTH:
-      preauth_mode = preauth_stdio;
-      break;
-
-    case OPT_TEST_MODE:
-      mu_argp_node_list_new (lst, "mode", "inetd");
-      test_mode = 1;
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, NULL, NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+
 static int
 cb_mode (void *data, mu_config_value_t *val)
 {
@@ -455,6 +441,12 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
   { NULL }
 };
 
+struct mu_cli_setup cli = {
+  options,
+  imap4d_cfg_param,
+  N_("GNU imap4d -- the IMAP4D daemon.")
+};
+
 int
 mu_get_user_groups (const char *user, mu_list_t retain, mu_list_t *pgrouplist)
 {
@@ -933,18 +925,10 @@ main (int argc, char **argv)
   mu_register_local_mbox_formats ();
   
   imap4d_capability_init ();
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif /* WITH_TLS */
-#ifdef WITH_GSASL
-  mu_gocs_register ("gsasl", mu_gsasl_module_init);
-#endif
   mu_tcpwrapper_cfg_init ();
   manlock_cfg_init ();
   mu_acl_cfg_init ();
   
-  mu_argp_init (NULL, NULL);
-
   mu_m_server_create (&server, program_version);
   mu_m_server_set_config_size (server, sizeof (struct imap4d_srv_config));
   mu_m_server_set_conn (server, imap4d_connection);
@@ -961,10 +945,16 @@ main (int argc, char **argv)
 
   mu_log_syslog = 1;
 
-  if (mu_app_init (&argp, imap4d_capa, imap4d_cfg_param, 
-		   argc, argv, 0, NULL, server))
-    exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
-
+  mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
+  if (argc)
+    {
+      mu_error (_("too many arguments"));
+      exit (EX_USAGE);
+    }
+  
+  if (test_mode)
+    mu_m_server_set_mode (server, MODE_INTERACTIVE);
+  
   if (login_disabled)
     imap4d_capability_add (IMAP_CAPA_LOGINDISABLED);
 
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index c1182f4..d547287 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -106,6 +106,7 @@
 #include <mailutils/imapio.h>
 #include <mailutils/imaputil.h>
 #include <mailutils/msgset.h>
+#include <mailutils/syslog.h>
 
 #include <mu_umaxtostr.h>
 #include <muaux.h>
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 9ae3929..d1e0019 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -48,7 +48,6 @@ pkginclude_HEADERS = \
  error.h\
  filter.h\
  folder.h\
- gocs.h\
  gsasl.h\
  guile.h\
  header.h\
@@ -59,8 +58,6 @@ pkginclude_HEADERS = \
  iterator.h\
  kwd.h\
  ldap.h\
- libargp.h\
- libcfg.h\
  list.h\
  locker.h\
  log.h\
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index 7067f21..d2964ff 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -35,7 +35,8 @@ struct mu_cli_capa
 
 void mu_cli_capa_init (void);
 void mu_cli_capa_register (struct mu_cli_capa *capa);
-void mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits);
+void mu_cli_capa_extend_settings (char const *name, mu_list_t opts,
+				  mu_list_t commits);
 
 struct mu_cli_setup
 {
@@ -49,6 +50,8 @@ struct mu_cli_setup
   int ex_usage;                /* If not 0, exit code on usage errors */
   int ex_config;               /* If not 0, exit code on configuration
 				  errors */
+  int inorder;
+  void (*prog_doc_hook) (mu_stream_t);
 };
 
 void mu_version_func (struct mu_parseopt *po, mu_stream_t stream);
diff --git a/include/mailutils/daemon.h b/include/mailutils/daemon.h
index fa29b41..2fa699e 100644
--- a/include/mailutils/daemon.h
+++ b/include/mailutils/daemon.h
@@ -20,7 +20,6 @@
 #define _MAILUTILS_DAEMON_H
 
 #include <mailutils/types.h>
-#include <mailutils/gocs.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -33,8 +32,6 @@ extern "C" {
 extern int  mu_daemon_create_pidfile  (const char *);
 extern void mu_daemon_remove_pidfile  (void);
 
-extern struct mu_gocs_daemon mu_gocs_daemon;  
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/mailutils/gocs.h b/include/mailutils/gocs.h
deleted file mode 100644
index be3de55..0000000
--- a/include/mailutils/gocs.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
-   Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifndef _MAILUTILS_GOCS_H
-#define _MAILUTILS_GOCS_H
-
-#include <mailutils/types.h>
-#include <mailutils/list.h>
-#include <mailutils/syslog.h>
-
-#ifdef __cplusplus
-extern "C" { 
-#endif
-
-struct mu_gocs_debug
-{
-  char *string;
-  int line_info;
-};
-
-struct mu_gocs_mailbox
-{
-  char *mail_spool;
-  char *mailbox_pattern;
-  char *mailbox_type;
-};
-
-struct mu_gocs_locking
-{
-  char *lock_flags;
-  unsigned long lock_retry_timeout;
-  unsigned long lock_retry_count;
-  unsigned long lock_expire_timeout;
-  char *external_locker;
-};
-
-struct mu_gocs_source_email
-{
-  char *address;
-  char *domain;
-};
-
-struct mu_gocs_mailer
-{
-  char *mailer;
-};
-
-struct mu_gocs_pam
-{
-  char *service;
-};
-
-struct mu_gocs_virtual
-{
-  char *pwddir;
-};
-
-/* Auxiliary variables for use by libargp/libcfg */
-extern char *mu_site_rcfile;
-extern int mu_load_user_rcfile;
-extern int mu_load_site_rcfile;
-extern char *mu_load_rcfile;
-
-typedef int (*mu_gocs_init_fp) (enum mu_gocs_op op, void *data);
-
-void mu_gocs_register (const char *capa, mu_gocs_init_fp init);
-void mu_gocs_register_std (const char *name);
-void mu_gocs_store (char *capa, void *data);
-void mu_gocs_flush (void);
-int mu_gocs_enumerate (mu_list_action_t action, void *data);
-
-int mu_gocs_mailbox_init (enum mu_gocs_op, void *data);
-int mu_gocs_locking_init (enum mu_gocs_op, void *data);
-int mu_gocs_source_email_init (enum mu_gocs_op, void *data);
-int mu_gocs_mailer_init (enum mu_gocs_op, void *data);
-int mu_gocs_logging_init (enum mu_gocs_op, void *data);
-int mu_gocs_debug_init (enum mu_gocs_op, void *data);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/mailutils/gsasl.h b/include/mailutils/gsasl.h
index ba61370..c9e3a6a 100644
--- a/include/mailutils/gsasl.h
+++ b/include/mailutils/gsasl.h
@@ -18,6 +18,7 @@
 
 #ifndef _MAILUTILS_GSASL_H
 #define _MAILUTILS_GSASL_H
+#include <mailutils/cli.h>
 
 struct mu_gsasl_module_data
 {
@@ -28,16 +29,13 @@ struct mu_gsasl_module_data
   char *anon_user;
   char *cram_md5_pwd;
 };
+extern struct mu_gsasl_module_data mu_gsasl_module_data;
 
 int mu_gsasl_enabled (void);
 
 #ifdef WITH_GSASL
 #include <gsasl.h>
 
-int mu_gsasl_module_init (enum mu_gocs_op, void *);
-extern struct mu_gsasl_module_data mu_gsasl_module_data;
-
-
 int gsasl_encoder_stream (mu_stream_t *pstr, mu_stream_t transport,
 			  Gsasl_session *ctx, int flags);
 int gsasl_decoder_stream (mu_stream_t *pstr, mu_stream_t transport,
diff --git a/include/mailutils/libargp.h b/include/mailutils/libargp.h
deleted file mode 100644
index c2ef992..0000000
--- a/include/mailutils/libargp.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999-2001, 2004-2005, 2007-2008, 2010-2012, 2014-2016
-   Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifndef _MAILUTILS_LIBARGP_H
-#define _MAILUTILS_LIBARGP_H
-
-#include "mailutils/types.h"
-#include "mailutils/gocs.h"
-#include "mailutils/nls.h"
-#include "mailutils/error.h"
-#include "mailutils/errno.h"
-#include "mailutils/version.h"
-#include "argp.h"
-#include "errno.h" 
-#include "strings.h"
-
-#include "mailutils/libcfg.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct mu_cmdline_capa
-{
-  char *name;
-  struct argp_child *child;
-  void (*modflags) (int *);
-};
-
-extern int mu_help_config_mode;
-extern int mu_rcfile_lint;
-extern int (*mu_app_cfg_verifier) (void);
-
-extern struct mu_cmdline_capa mu_mailutils_cmdline;
-extern struct mu_cmdline_capa mu_common_cmdline;
-extern struct mu_cmdline_capa mu_logging_cmdline;
-extern struct mu_cmdline_capa mu_mailbox_cmdline;
-extern struct mu_cmdline_capa mu_locking_cmdline;
-extern struct mu_cmdline_capa mu_address_cmdline;
-extern struct mu_cmdline_capa mu_mailer_cmdline;
-extern struct mu_cmdline_capa mu_sieve_cmdline;
-extern struct mu_cmdline_capa mu_debug_cmdline;
-  
-extern struct mu_cmdline_capa mu_pam_cmdline;
-extern struct mu_cmdline_capa mu_gsasl_cmdline;
-extern struct mu_cmdline_capa mu_radius_cmdline;
-extern struct mu_cmdline_capa mu_sql_cmdline;
-extern struct mu_cmdline_capa mu_virtdomain_cmdline;
-
-extern void mu_libargp_init (void);
-  
-extern struct argp *mu_argp_build (const struct argp *argp, char ***pcapa,
-				   int *flags);
-extern void mu_argp_done (struct argp *argp);
-  
-extern int mu_register_argp_capa (const char *name, struct argp_child *child,
-				  void (*modflags) (int*));
-
-void mu_argp_init (const char *vers, const char *bugaddr);
-int mu_app_init (struct argp *myargp, const char **capa,
-		 struct mu_cfg_param *cfg_param, 
-		 int argc, char **argv, int flags, int *pindex, void *data);
-extern void mu_program_version_hook (FILE *stream, struct argp_state *state);
-
-error_t mu_argp_parse (const struct argp *myargp, 
-		       int *pargc, char **pargv[],  
-		       unsigned flags,
-		       const char *capa[],
-		       int *arg_index,     
-		       void *input) MU_DEPRECATED;
-
-void mu_argp_node_list_init (mu_list_t *);
-void mu_argp_node_list_add (mu_list_t, mu_cfg_node_t *);
-void mu_argp_node_list_new (mu_list_t, const char *, const char *);
-void mu_argp_node_list_finish (mu_list_t, char *, char *);
-  
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/include/mailutils/libcfg.h b/include/mailutils/libcfg.h
deleted file mode 100644
index c7730ad..0000000
--- a/include/mailutils/libcfg.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifndef _MAILUTILS_LIBCFG_H
-#define _MAILUTILS_LIBCFG_H
-
-#include <mailutils/cfg.h>
-#include <mailutils/gocs.h>
-#include <mailutils/nls.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-
-#ifndef MU_USER_CONFIG_FILE
-# define MU_USER_CONFIG_FILE "~/.mailutils"
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct mu_cfg_capa
-{
-  char *name;
-  struct mu_cfg_param *cfgparam;
-  mu_cfg_section_fp parser;
-};
-
-extern int mu_libcfg_register_capa (struct mu_cfg_capa *capa);
-extern void mu_libcfg_init (char **cnames);
-extern int mu_parse_config_files (struct mu_cfg_param *param,
-				  void *target_ptr) MU_CFG_DEPRECATED;
-int mu_libcfg_parse_config (mu_cfg_tree_t **ptree);
-  
-extern void mu_acl_cfg_init (void);
-
-#define __mu_common_cat2__(a,b) a ## b
-#define __mu_common_cat3__(a,b,c) a ## b ## c
-#define DCL_PARSER(capa)						      \
-int									      \
-__mu_common_cat3__(mu_,capa,_section_parser)				      \
-     (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,	      \
-      const char *section_label, void **section_data,                         \
-      void *call_data, mu_cfg_tree_t *tree)	                              \
-{									      \
-  switch (stage)							      \
-    {									      \
-    case mu_cfg_section_start:						      \
-      break;								      \
-      									      \
-    case mu_cfg_section_end:						      \
-      mu_gocs_store (#capa, &__mu_common_cat2__(capa, _settings));	      \
-    }									      \
-  return 0;								      \
-}
-
-#define DCL_DEFAULT_CFG_CAPA(capa)                                            \
- struct mu_cfg_capa __mu_common_cat3__(mu_,capa,_cfg_capa) = {                \
-      #capa,                                                                  \
-      __mu_common_cat3__(mu_,capa,_param),                                    \
-      __mu_common_cat3__(mu_,capa,_section_parser)                            \
- }
-
-#define DCL_CFG_CAPA(capa)                                                    \
-  DCL_PARSER (capa)                                                           \
-  DCL_DEFAULT_CFG_CAPA (capa) 
-
-extern struct mu_cfg_capa mu_mailbox_cfg_capa;
-extern struct mu_cfg_capa mu_locking_cfg_capa;
-extern struct mu_cfg_capa mu_address_cfg_capa;
-extern struct mu_cfg_capa mu_mailer_cfg_capa;
-extern struct mu_cfg_capa mu_logging_cfg_capa;
-extern struct mu_cfg_capa mu_debug_cfg_capa;
-extern struct mu_cfg_capa mu_gsasl_cfg_capa;
-extern struct mu_cfg_capa mu_pam_cfg_capa;
-extern struct mu_cfg_capa mu_radius_cfg_capa;
-extern struct mu_cfg_capa mu_sql_cfg_capa;
-extern struct mu_cfg_capa mu_tls_cfg_capa;
-extern struct mu_cfg_capa mu_virtdomain_cfg_capa;
-extern struct mu_cfg_capa mu_sieve_cfg_capa;
-extern struct mu_cfg_capa mu_auth_cfg_capa;
-extern struct mu_cfg_capa mu_ldap_cfg_capa;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/include/mailutils/mailutils.h b/include/mailutils/mailutils.h
index 5ed71d2..cc14889 100644
--- a/include/mailutils/mailutils.h
+++ b/include/mailutils/mailutils.h
@@ -58,7 +58,6 @@
 #include <mailutils/stream.h>
 #include <mailutils/tls.h>
 #include <mailutils/url.h>
-#include <mailutils/gocs.h>
 #include <mailutils/version.h>
 #include <mailutils/io.h>
 #include <mailutils/secret.h>
@@ -66,6 +65,7 @@
 #include <mailutils/cstr.h>
 #include <mailutils/wordsplit.h>
 #include <mailutils/log.h>
+#include <mailutils/syslog.h>
 #include <mailutils/stdstream.h>
 #include <mailutils/prog.h>
 #include <mailutils/sockaddr.h>
diff --git a/include/mailutils/mu_auth.h b/include/mailutils/mu_auth.h
index 4355d93..a67cc61 100644
--- a/include/mailutils/mu_auth.h
+++ b/include/mailutils/mu_auth.h
@@ -20,8 +20,8 @@
 #define _MAILUTILS_MU_AUTH_H
 
 #include <mailutils/types.h>
-#include <mailutils/gocs.h>
 #include <mailutils/debug.h>
+#include <mailutils/cli.h>
 
 #define MU_AUTH_NAME    "name"
 #define MU_AUTH_PASSWD  "passwd"
@@ -64,30 +64,41 @@ typedef int (*mu_auth_fp) (struct mu_auth_data **data,
 			   void *func_data,
 			   void *call_data);
 
+enum mu_auth_mode
+  {
+    mu_auth_authenticate,
+    mu_auth_getpwnam,
+    mu_auth_getpwuid
+  };
+
+#define MU_AUTH_MODE_COUNT 3
+
 struct mu_auth_module
 {
   char            *name;
-  mu_gocs_init_fp init;
-  mu_auth_fp      authenticate;
-  void            *authenticate_data;
-  mu_auth_fp      auth_by_name;
-  void            *auth_by_name_data;
-  mu_auth_fp      auth_by_uid;
-  void            *auth_by_uid_data;
+  mu_auth_fp      handler[MU_AUTH_MODE_COUNT];
+  void            *data[MU_AUTH_MODE_COUNT];
+
+  struct mu_option *opt;
+  struct mu_cfg_param *cfg;
+  mu_cfg_section_fp parser;
+  mu_cli_capa_commit_fp commit;
 };
 
 enum mu_auth_key_type
   {
-    mu_auth_key_name,
-    mu_auth_key_uid
+    mu_auth_key_name = mu_auth_getpwnam,
+    mu_auth_key_uid = mu_auth_getpwuid
   };
 
 void mu_auth_begin_setup (void);
 void mu_auth_finish_setup (void);
+void mu_auth_extend_settings (mu_list_t opts, mu_list_t commits);
 
-extern int mu_auth_runlist (mu_list_t flist,
-			    struct mu_auth_data **return_data,
-			    const void *key, void *data);
+int mu_auth_runlist (mu_list_t flist,
+		     enum mu_auth_mode mode,
+		     const void *key, void *data,
+		     struct mu_auth_data **return_data);
 
 extern int mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
 			const void *key);
@@ -116,7 +127,6 @@ extern void mu_authentication_add_module_list (const char *modlist);
 extern void mu_authentication_clear_list (void);
 extern void mu_authorization_clear_list (void);
 
-extern void mu_auth_init (void);
 extern int mu_auth_data_alloc (struct mu_auth_data **ptr,
 			       const char *name,
 			       const char *passwd,
@@ -138,6 +148,8 @@ extern struct mu_auth_module mu_auth_sql_module;
 extern struct mu_auth_module mu_auth_virtual_module;
 extern struct mu_auth_module mu_auth_radius_module;
 extern struct mu_auth_module mu_auth_ldap_module;
+extern struct mu_auth_module mu_auth_gsasl_module;
+extern struct mu_auth_module mu_auth_tls_module;
 
 #define MU_AUTH_REGISTER_ALL_MODULES() do {\
   mu_auth_register_module (&mu_auth_generic_module); \
@@ -147,6 +159,8 @@ extern struct mu_auth_module mu_auth_ldap_module;
   mu_auth_register_module (&mu_auth_virtual_module);\
   mu_auth_register_module (&mu_auth_radius_module);\
   mu_auth_register_module (&mu_auth_ldap_module);\
+  mu_auth_register_module (&mu_auth_gsasl_module);\
+  mu_auth_register_module (&mu_auth_tls_module);\
   } while (0)
 
 #endif
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 87a9839..fc40824 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -102,6 +102,7 @@ struct mu_option_cache
 #define MU_PARSEOPT_HELP_HOOK      0x00200000
 #define MU_PARSEOPT_DATA           0x00400000
 #define MU_PARSEOPT_VERSION_HOOK   0x00800000
+#define MU_PARSEOPT_PROG_DOC_HOOK  0x01000000
 
 /* Reuse mu_parseopt struct initialized previously */
 #define MU_PARSEOPT_REUSE          0x80000000
@@ -131,6 +132,7 @@ struct mu_parseopt
   char const *po_package_url;
   char const *po_extra_info;
 
+  void (*po_prog_doc_hook) (struct mu_parseopt *po, mu_stream_t stream);
   void (*po_help_hook) (struct mu_parseopt *po, mu_stream_t stream); 
   void (*po_version_hook) (struct mu_parseopt *po, mu_stream_t stream);
   
diff --git a/include/mailutils/radius.h b/include/mailutils/radius.h
index 2fe70b2..67d39ff 100644
--- a/include/mailutils/radius.h
+++ b/include/mailutils/radius.h
@@ -28,6 +28,4 @@ struct mu_radius_module_data
   char *getpwuid_request;
 };
 
-extern int mu_radius_module_init (enum mu_gocs_op, void *data);
-
 #endif
diff --git a/include/mailutils/sieve.h b/include/mailutils/sieve.h
index 1ba1a72..9aab6c6 100644
--- a/include/mailutils/sieve.h
+++ b/include/mailutils/sieve.h
@@ -272,17 +272,6 @@ int mu_sieve_disass (mu_sieve_machine_t mach);
 #define MU_SIEVE_CLEAR_INCLUDE_PATH 0x1
 #define MU_SIEVE_CLEAR_LIBRARY_PATH 0x2
 
-struct mu_gocs_sieve
-{
-  int clearflags;
-  /*  mu_list_t include_path_prefix;*/
-  mu_list_t include_path;
-  mu_list_t library_path_prefix;
-  mu_list_t library_path;
-};
-
-int mu_sieve_module_init (enum mu_gocs_op, void *);
-
 extern struct mu_cli_capa mu_cli_capa_sieve;
   
 #ifdef __cplusplus
diff --git a/include/mailutils/sql.h b/include/mailutils/sql.h
index e08f49b..ff3a16e 100644
--- a/include/mailutils/sql.h
+++ b/include/mailutils/sql.h
@@ -29,24 +29,6 @@ enum mu_password_type
 
 struct mu_sql_module_config
 {
-  char *interface;
-  char *getpwnam_query;
-  char *getpass_query;
-  char *getpwuid_query;
-  char *host;
-  char *user;
-  char *passwd;
-  char *db;
-  int port;
-  enum mu_password_type password_type;
-  int positional;
-  mu_assoc_t field_map;
-};
-
-/* FIXME: Should not be here, but needed for several other sources
-   (imap4d/auth_gsasl.c, for instance) */
-struct mu_internal_sql_config
-{
   int interface;
   char *getpwnam_query;
   char *getpass_query;
@@ -61,7 +43,7 @@ struct mu_internal_sql_config
   mu_assoc_t field_map;
 };
 
-extern struct mu_internal_sql_config mu_sql_module_config;
+extern struct mu_sql_module_config mu_sql_module_config;
 
 /* Loadable Modules Support */
 #define __s_cat2__(a,b) a ## b
@@ -131,7 +113,7 @@ struct mu_sql_dispatch
 };
 
 /* Public interfaces */
-int mu_sql_interface_index (char *name);
+int mu_sql_interface_index (char const *name);
 
 int mu_sql_connection_init (mu_sql_connection_t *conn, int interface,
 			    char *server, int  port, char *login,
diff --git a/include/mailutils/tls.h b/include/mailutils/tls.h
index db6e420..16b1ecb 100644
--- a/include/mailutils/tls.h
+++ b/include/mailutils/tls.h
@@ -42,8 +42,6 @@ struct mu_tls_module_config
   char *priorities;
 };
 
-extern int mu_tls_module_init (enum mu_gocs_op, void *);
-
 extern int mu_tls_server_stream_create (mu_stream_t *stream, 
 			 	        mu_stream_t strin, mu_stream_t strout,
 				        int flags);
diff --git a/include/mailutils/types.hin b/include/mailutils/types.hin
index 770b989..1057239 100644
--- a/include/mailutils/types.hin
+++ b/include/mailutils/types.hin
@@ -151,12 +151,6 @@ struct mu_locus
   unsigned mu_col;
 };
   
-enum mu_gocs_op
-  {
-    mu_gocs_op_set,
-    mu_gocs_op_flush
-  };
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 0cc9731..2cdff6f 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -28,7 +28,6 @@ lib_LTLIBRARIES = libmuaux.la
 noinst_LIBRARIES = libmuscript.a libmutcpwrap.a
 
 libmuaux_la_SOURCES = \
- argp_base.c\
  daemon.c\
  mailcap.c\
  manlock.c\
diff --git a/lib/argp_base.c b/lib/argp_base.c
deleted file mode 100644
index 06e7e49..0000000
--- a/lib/argp_base.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007, 2009-2012, 2014-2016 Free Software Foundation,
-   Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <unistd.h>
-#include <string.h>
-
-char *
-__argp_base_name (const char *arg)
-{
-  char *p = strrchr (arg, '/');
-  return (char *)(p ? p + 1 : arg);
-}
-
diff --git a/libmailutils/auth/mu_auth.c b/libmailutils/auth/mu_auth.c
index 2d4f14d..54896e1 100644
--- a/libmailutils/auth/mu_auth.c
+++ b/libmailutils/auth/mu_auth.c
@@ -161,23 +161,19 @@ mu_auth_data_destroy (struct mu_auth_data **pptr)
 
 /* Generic functions */
 
-struct auth_stack_entry {
-  char *name;        /* for diagnostics purposes */
-  mu_auth_fp fun;
-  void *func_data;
-};
-
-void
-mu_insert_stack_entry (mu_list_t *pflist, struct auth_stack_entry *entry)
+static void
+append_auth_module (mu_list_t *pflist, struct mu_auth_module *mod)
 {
   if (!*pflist && mu_list_create (pflist))
     return;
-  mu_list_append (*pflist, entry);
+  mu_list_append (*pflist, mod);
 }
 
 int
-mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
-                 const void *key, void *data)
+mu_auth_runlist (mu_list_t flist,
+		 enum mu_auth_mode mode,
+                 const void *key, void *data,
+		 struct mu_auth_data **return_data)
 {
   int status = MU_ERR_AUTH_FAILURE;
   int rc;
@@ -185,15 +181,17 @@ mu_auth_runlist (mu_list_t flist, struct mu_auth_data **return_data,
 
   if (mu_list_get_iterator (flist, &itr) == 0)
     {
-      struct auth_stack_entry *ep;
+      struct mu_auth_module *ep;
       
       for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
            mu_iterator_next (itr))
         {
           mu_iterator_current (itr, (void **)&ep);
+	  if (!ep->handler[mode])
+	    continue;
           mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2,
 		    ("Trying %s...", ep->name));
-          rc = ep->fun (return_data, key, ep->func_data, data);
+          rc = ep->handler[mode] (return_data, key, ep->data[mode], data);
 	  mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE2, 
 		    ("%s yields %d=%s", ep->name, rc, mu_strerror (rc)));
           if (rc == 0)
@@ -230,30 +228,25 @@ mu_auth_nosupport (struct mu_auth_data **return_data MU_ARG_UNUSED,
 
 /* II. Authorization: retrieving information about user */
 
-static mu_list_t mu_auth_by_name_list, _tmp_auth_by_name_list;
-static mu_list_t mu_auth_by_uid_list, _tmp_auth_by_uid_list;
+static mu_list_t mu_getpw_modules, selected_getpw_modules;
 
 int
 mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
              const void *key)
 {
-  mu_list_t list;
-  
-  if (!mu_auth_by_name_list)
+  if (!mu_getpw_modules)
     mu_auth_begin_setup ();
   switch (type)
     {
     case mu_auth_key_name:
       mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
                 ("Getting auth info for user %s", (char*) key));
-      list = mu_auth_by_name_list;
       break;
 
     case mu_auth_key_uid:
       mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1, 
                 ("Getting auth info for UID %lu",
 		 (unsigned long) *(uid_t*) key));
-      list = mu_auth_by_uid_list;
       break;
 
     default:
@@ -261,7 +254,7 @@ mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
                 ("Unknown mu_auth_key_type: %d", type));
       return EINVAL;
     }
-  return mu_auth_runlist (list, auth, key, NULL);
+  return mu_auth_runlist (mu_getpw_modules, type, key, NULL, auth);
 }
 
 struct mu_auth_data *
@@ -282,7 +275,7 @@ mu_get_auth_by_uid (uid_t uid)
 
 /* III. Authentication: determining the authenticity of a user */
 
-static mu_list_t mu_authenticate_list, _tmp_authenticate_list;
+static mu_list_t mu_auth_modules, selected_auth_modules;
 
 int
 mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
@@ -292,68 +285,52 @@ mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
   mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1, 
             ("mu_authenticate, user %s, source %s", 
              auth_data->name, auth_data->source));
-  if (!mu_authenticate_list)
+  if (!mu_auth_modules)
     mu_auth_begin_setup ();
-  return mu_auth_runlist (mu_authenticate_list, NULL, auth_data, (void*) pass);
+  return mu_auth_runlist (mu_auth_modules,
+			  mu_auth_authenticate,
+			  auth_data, pass, NULL);
 }
 
 
 /* ************************************************************************* */
 
-struct _module_handler {
-  struct auth_stack_entry authenticate;
-  struct auth_stack_entry auth_by_name;
-  struct auth_stack_entry auth_by_uid;
-};
+static mu_list_t module_list;
 
-static mu_list_t module_handler_list;
+static void
+module_list_init (void)
+{
+  if (!module_list)
+    {
+      if (mu_list_create (&module_list))
+	abort ();
+      mu_list_append (module_list, &mu_auth_generic_module); 
+      mu_list_append (module_list, &mu_auth_system_module);
+    }
+}
 
 void
 mu_auth_register_module (struct mu_auth_module *mod)
 {
-  struct _module_handler *entry;
-  
-  if (mod->init)
-    mu_gocs_register (mod->name, mod->init);
-  
-  if (!module_handler_list && mu_list_create (&module_handler_list))
-    abort ();
-
-  entry = malloc (sizeof (*entry));
-  if (!entry)
-    {
-      mu_error ("not enough memory");
-      exit (1);
-    }
-  entry->authenticate.name = mod->name;
-  entry->authenticate.fun  = mod->authenticate;
-  entry->authenticate.func_data = mod->authenticate_data;
-  entry->auth_by_name.name = mod->name;
-  entry->auth_by_name.fun = mod->auth_by_name;
-  entry->auth_by_name.func_data = mod->auth_by_name_data;
-  entry->auth_by_uid.name = mod->name;
-  entry->auth_by_uid.fun = mod->auth_by_uid;
-  entry->auth_by_uid.func_data = mod->auth_by_uid_data;
-    
-  mu_list_append (module_handler_list, entry);
-  
+  module_list_init ();
+  mu_list_append (module_list, mod);  
 }
 
-static struct _module_handler *
+static struct mu_auth_module *
 _locate (const char *name)
 {
-  struct _module_handler *rp = NULL;
+  struct mu_auth_module *rp = NULL;
   mu_iterator_t itr;
 
-  if (mu_list_get_iterator (module_handler_list, &itr) == 0)
+  if (mu_list_get_iterator (module_list, &itr) == 0)
     {
-      struct _module_handler *p;
+      struct mu_auth_module *p;
       
       for (mu_iterator_first (itr); !rp && !mu_iterator_is_done (itr);
            mu_iterator_next (itr))
         {
           mu_iterator_current (itr, (void **)&p);
-          if (strcmp (p->authenticate.name, name) == 0)
+          if (strcmp (p->name, name) == 0)
             rp = p;
         }
 
@@ -397,15 +374,14 @@ _add_module_list (const char *modlist, int (*fun)(const char *name))
 int
 mu_authorization_add_module (const char *name)
 {
-  struct _module_handler *mod = _locate (name);
+  struct mu_auth_module *mod = _locate (name);
   
   if (!mod)
     {
       errno = MU_ERR_NOENT;
       return 1;
     }
-  mu_insert_stack_entry (&_tmp_auth_by_name_list, &mod->auth_by_name);
-  mu_insert_stack_entry (&_tmp_auth_by_uid_list, &mod->auth_by_uid);
+  append_auth_module (&selected_getpw_modules, mod);
   return 0;
 }
 
@@ -418,22 +394,21 @@ mu_authorization_add_module_list (const char *modlist)
 void
 mu_authorization_clear_list ()
 {
-  mu_list_destroy (&_tmp_auth_by_name_list);
-  mu_list_destroy (&_tmp_auth_by_uid_list);
+  mu_list_destroy (&selected_getpw_modules);
 }
 
 
 int
 mu_authentication_add_module (const char *name)
 {
-  struct _module_handler *mod = _locate (name);
+  struct mu_auth_module *mod = _locate (name);
 
   if (!mod)
     {
       errno = MU_ERR_NOENT;
       return 1;
     }
-  mu_insert_stack_entry (&_tmp_authenticate_list, &mod->authenticate);
+  append_auth_module (&selected_auth_modules, mod);
   return 0;
 }
 
@@ -446,7 +421,7 @@ mu_authentication_add_module_list (const char *modlist)
 void
 mu_authentication_clear_list ()
 {
-  mu_list_destroy (&_tmp_authenticate_list);
+  mu_list_destroy (&selected_auth_modules);
 }
 
 
@@ -462,45 +437,39 @@ mu_authentication_clear_list ()
       argp_parse() exits. */
    
 void
-mu_auth_begin_setup ()
+mu_auth_begin_setup (void)
 {
   mu_iterator_t itr;
 
-  if (!module_handler_list)
-    {
-      mu_auth_register_module (&mu_auth_generic_module); 
-      mu_auth_register_module (&mu_auth_system_module);
-    }
-  
-  if (!mu_authenticate_list)
+  module_list_init ();
+
+  if (!mu_auth_modules)
     {
-      if (mu_list_get_iterator (module_handler_list, &itr) == 0)
+      if (mu_list_get_iterator (module_list, &itr) == 0)
         {
-          struct _module_handler *mod;
+          struct mu_auth_module *mod;
           
           for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
                mu_iterator_next (itr))
             {
               mu_iterator_current (itr, (void **)&mod);
-              mu_insert_stack_entry (&mu_authenticate_list,
-                                     &mod->authenticate);
+	      append_auth_module (&mu_auth_modules, mod);
             }
           mu_iterator_destroy (&itr);
         }
     }
 
-  if (!mu_auth_by_name_list)
+  if (!mu_getpw_modules)
     {
-      if (mu_list_get_iterator (module_handler_list, &itr) == 0)
+      if (mu_list_get_iterator (module_list, &itr) == 0)
         {
-          struct _module_handler *mod;
+          struct mu_auth_module *mod;
           
           for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
                mu_iterator_next (itr))
             {
               mu_iterator_current (itr, (void **)&mod);
-              mu_insert_stack_entry (&mu_auth_by_name_list, &mod->auth_by_name);
-              mu_insert_stack_entry (&mu_auth_by_uid_list, &mod->auth_by_uid);
+              append_auth_module (&mu_getpw_modules, mod);
             }
           mu_iterator_destroy (&itr);
         }
@@ -508,20 +477,48 @@ mu_auth_begin_setup ()
 }
 
 void
-mu_auth_finish_setup ()
+mu_auth_finish_setup (void)
 {
-  mu_list_destroy (&mu_authenticate_list);
-  mu_list_destroy (&mu_auth_by_name_list);
-  mu_list_destroy (&mu_auth_by_uid_list);
-  
-  mu_authenticate_list = _tmp_authenticate_list;
-  _tmp_authenticate_list = NULL;
-  mu_auth_by_name_list = _tmp_auth_by_name_list;
-  _tmp_auth_by_name_list = NULL;
-  mu_auth_by_uid_list = _tmp_auth_by_uid_list;
-  _tmp_auth_by_uid_list = NULL;
+  mu_list_destroy (&mu_auth_modules);
+  mu_auth_modules = selected_auth_modules;
+  selected_auth_modules = NULL;
+
+  mu_list_destroy (&mu_getpw_modules);
+  mu_getpw_modules = selected_getpw_modules;
+  selected_getpw_modules = NULL;
   
   mu_auth_begin_setup ();
 }
+
+struct settings
+{
+  mu_list_t opts;
+  mu_list_t commits;
+};
+  
+static int
+do_extend (void *item, void *data)
+{
+  struct mu_auth_module *mod = item;
+  struct settings *set = data;
+  
+  if (mod->opt)
+    mu_list_append (set->opts, mod->opt);
+  if (mod->commit)
+    mu_list_append (set->commits, mod->commit);
+  if (mod->parser || mod->cfg)
+    mu_config_root_register_section (NULL, mod->name, NULL,
+				     mod->parser, mod->cfg);
+  return 0;
+}
+
+void
+mu_auth_extend_settings (mu_list_t opts, mu_list_t commits)
+{
+  struct settings s;
+  s.opts = opts;
+  s.commits = commits;
+  mu_list_foreach (module_list, do_extend, &s);
+}
 
 
diff --git a/libmailutils/auth/system.c b/libmailutils/auth/system.c
index ac6455e..1094232 100644
--- a/libmailutils/auth/system.c
+++ b/libmailutils/auth/system.c
@@ -141,25 +141,19 @@ mu_authenticate_system (struct mu_auth_data **return_data MU_ARG_UNUSED,
 
 
 struct mu_auth_module mu_auth_system_module = {
-  "system",
-  NULL,
-  mu_authenticate_system,
-  NULL,
-  mu_auth_system_by_name,
-  NULL,
-  mu_auth_system_by_uid,
-  NULL
+  .name = "system",
+  .handler = {
+    [mu_auth_authenticate] = mu_authenticate_system,
+    [mu_auth_getpwnam]     = mu_auth_system_by_name,
+    [mu_auth_getpwuid]     = mu_auth_system_by_uid
+  }
 };
 
 
 struct mu_auth_module mu_auth_generic_module = {
-  "generic",
-  NULL,
-  mu_authenticate_generic,
-  NULL,
-  mu_auth_nosupport,
-  NULL,
-  mu_auth_nosupport,
-  NULL
+  .name = "generic",
+  .handler = {
+    [mu_auth_authenticate] = mu_authenticate_generic
+  }
 };
 
diff --git a/libmailutils/cfg/Makefile.am b/libmailutils/cfg/Makefile.am
index 89ab1de..9530303 100644
--- a/libmailutils/cfg/Makefile.am
+++ b/libmailutils/cfg/Makefile.am
@@ -21,8 +21,7 @@ libcfg_la_SOURCES = \
  driver.c\
  format.c\
  lexer.c\
- parser.c\
- gocs.c
+ parser.c
 
 localedir = $(datadir)/locale
 AM_CPPFLAGS = \
diff --git a/libmailutils/cfg/gocs.c b/libmailutils/cfg/gocs.c
deleted file mode 100644
index ec2dd92..0000000
--- a/libmailutils/cfg/gocs.c
+++ /dev/null
@@ -1,387 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/types.h>
-#include <mailutils/gocs.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/locker.h>
-#include <mailutils/util.h>
-#include <mailutils/mailer.h>
-#include <mailutils/error.h>
-#include <mailutils/errno.h>
-#include <mailutils/nls.h>
-#include <mailutils/debug.h>
-#include <mailutils/syslog.h>
-#include <mailutils/registrar.h>
-#include <mailutils/stdstream.h>
-#include <mailutils/stream.h>
-#include <mailutils/log.h>
-#include <syslog.h>
-
-#ifndef MU_CONFIG_FILE
-# define MU_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
-#endif
-
-char *mu_site_rcfile = MU_CONFIG_FILE;
-int mu_load_user_rcfile = 1;
-int mu_load_site_rcfile = 1;
-char *mu_load_rcfile = NULL;
-
-
-int
-mu_gocs_dummy (enum mu_gocs_op op, void *data)
-{
-  return 0;
-}
-
-int
-mu_gocs_mailbox_init (enum mu_gocs_op op, void *data)
-{
-  int rc;
-  struct mu_gocs_mailbox *p = data;
-
-  if (op == mu_gocs_op_set && p)
-    {
-      if (p->mail_spool)
-	{
-	  rc = mu_set_mail_directory (p->mail_spool);
-	  if (rc)
-	    mu_error (_("cannot set mail directory name to `%s': %s"),
-		      p->mail_spool, mu_strerror (rc));
-	  free (p->mail_spool);
-	  p->mail_spool = NULL;
-	}
-      if (p->mailbox_pattern)
-	{
-	  rc = mu_set_mailbox_pattern (p->mailbox_pattern);
-	  if (rc)
-	    mu_error (_("cannot set mailbox pattern to `%s': %s"),
-		      p->mailbox_pattern, mu_strerror (rc));
-	  free (p->mailbox_pattern);
-	  p->mailbox_pattern = NULL;
-	}
-      if (p->mailbox_type)
-	{
-	  if (mu_registrar_set_default_scheme (p->mailbox_type))
-	    mu_error (_("invalid mailbox type: %s"), p->mailbox_type);
-	  free (p->mailbox_type);
-	  p->mailbox_type = NULL;
-	}
-    }
-  return 0;
-}
-
-int
-mu_gocs_locking_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_locking *p = data;
-  
-  if (!(op == mu_gocs_op_set && p))
-    return 0;
-
-  if (p->lock_flags)
-    {
-      int flags = 0;
-      char *s;
-      
-      for (s = p->lock_flags; *s; s++)
-	{
-	  switch (*s)
-	    {
-	    case 'E':
-	      flags |= MU_LOCKER_EXTERNAL;
-	      break;
-	      
-	    case 'R':
-	      flags |= MU_LOCKER_RETRY;
-	      break;
-	      
-	    case 'T':
-	      flags |= MU_LOCKER_TIME;
-	      break;
-	      
-	    case 'P':
-	      flags |= MU_LOCKER_PID;
-	      break;
-	      
-	    default:
-	      mu_error (_("invalid lock flag `%c'"), *s);
-	    }
-	}
-      mu_locker_set_default_flags (flags, mu_locker_assign);
-      free (p->lock_flags);
-      p->lock_flags = NULL;
-    }
-
-  if (p->lock_retry_count)
-    {
-      mu_locker_set_default_retry_count (p->lock_retry_count);
-      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
-      p->lock_retry_count = 0;
-    }
-
-  if (p->lock_retry_timeout)
-    {
-      mu_locker_set_default_retry_timeout (p->lock_retry_timeout);
-      mu_locker_set_default_flags (MU_LOCKER_RETRY, mu_locker_set_bit);
-      p->lock_retry_timeout = 0;
-    }
-
-  if (p->lock_expire_timeout)
-    {
-      mu_locker_set_default_expire_timeout (p->lock_expire_timeout);
-      mu_locker_set_default_flags (MU_LOCKER_EXTERNAL, mu_locker_set_bit);
-      p->lock_expire_timeout = 0;
-    }
-
-  if (p->external_locker)
-    {
-      mu_locker_set_default_external_program (p->external_locker);
-      mu_locker_set_default_flags (MU_LOCKER_TIME, mu_locker_set_bit);
-      free (p->external_locker);
-      p->external_locker = NULL;
-    }
-  return 0;
-}
-
-int
-mu_gocs_source_email_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_source_email *p = data;
-  int rc;
-
-  if (!(op == mu_gocs_op_set && p))
-    return 0;
-  
-  if (p->address)
-    {
-      if ((rc = mu_set_user_email (p->address)) != 0)
-	mu_error (_("invalid email address `%s': %s"),
-		  p->address, mu_strerror (rc));
-      free (p->address);
-      p->address = NULL;
-    }
-
-  if (p->domain)
-    {
-      if ((rc = mu_set_user_email_domain (p->domain)) != 0)
-	mu_error (_("invalid email domain `%s': %s"),
-		  p->domain, mu_strerror (rc));
-
-      free (p->domain);
-      p->domain = NULL;
-    }
-  return 0;
-}
-
-int
-mu_gocs_mailer_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_mailer *p = data;
-  int rc;
-
-  if (!(op == mu_gocs_op_set && p))
-    return 0;
-  
-  if (p->mailer)
-    {
-      if ((rc = mu_mailer_set_url_default (p->mailer)) != 0)
-	mu_error (_("invalid mailer URL `%s': %s"),
-		  p->mailer, mu_strerror (rc));
-      free (p->mailer);
-      p->mailer = NULL;
-    }
-  return 0;
-}
-
-int
-mu_gocs_logging_init (enum mu_gocs_op op, void *data)
-{
-  if (mu_log_syslog >= 0)
-    mu_stdstream_strerr_setup (mu_log_syslog ?
-			       MU_STRERR_SYSLOG : MU_STRERR_STDERR);
-  return 0;
-}
-
-int
-mu_gocs_debug_init (enum mu_gocs_op op, void *data)
-{
-  if (op == mu_gocs_op_set && data)
-    {
-      struct mu_gocs_debug *p = data;
-      if (p->string)
-	mu_debug_parse_spec (p->string);
-      if (p->line_info >= 0)
-	mu_debug_line_info = p->line_info;
-    }
-  return 0;
-}
-
-
-struct mu_gocs_entry
-{
-  const char *name;
-  mu_gocs_init_fp init;
-};
-
-#define MAX_GOCS 512
-
-static struct mu_gocs_entry _gocs_table[MAX_GOCS];
-
-void
-mu_gocs_register (const char *capa, mu_gocs_init_fp init)
-{
-  int i;
-  for (i = 0; _gocs_table[i].name; i++)
-    {
-      if (i == MAX_GOCS-1)
-	{
-	  mu_error (_("gocs table overflow"));
-	  abort ();
-	}
-      else if (strcmp (_gocs_table[i].name, capa) == 0)
-	return;
-    }
-  _gocs_table[i].name = capa;
-  _gocs_table[i].init = init;
-}
-
-int
-mu_gocs_enumerate (mu_list_action_t action, void *data)
-{
-  int i;
-  
-  for (i = 0; _gocs_table[i].name; i++)
-    {
-      int rc = action ((void*) _gocs_table[i].name, data);
-      if (rc)
-	return rc;
-    }
-  return 0;
-}
-
-static mu_gocs_init_fp
-find_init_function (struct mu_gocs_entry *tab, const char *capa)
-{
-  for (; tab->name; tab++)
-    if (strcmp (tab->name, capa) == 0)
-      return tab->init;
-  return NULL;
-}
-
-static struct mu_gocs_entry std_gocs_table[] = {
-  { "mailutils", mu_gocs_dummy },
-  { "common", mu_gocs_dummy },
-  { "mailbox", mu_gocs_mailbox_init },
-  { "locking", mu_gocs_locking_init },
-  { "address", mu_gocs_source_email_init },
-  { "mailer", mu_gocs_mailer_init },
-  { "logging", mu_gocs_logging_init },
-  { "debug", mu_gocs_debug_init },
-  { "auth", mu_gocs_dummy },
-  { NULL }
-};
-
-void
-mu_gocs_register_std (const char *name)
-{
-  mu_gocs_init_fp init = find_init_function (std_gocs_table, name);
-  if (!init)
-    {
-      mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
-		__FILE__, __LINE__, name);
-      abort ();
-    }
-  mu_gocs_register (name, init);
-}
-
-
-struct mu_gocs_data
-{
-  char *capa;
-  void *data;
-};
-
-static mu_list_t /* of struct mu_gocs_data */ data_list;
-
-static int
-_gocs_comp (const void *a, const void *b)
-{
-  const struct mu_gocs_data *da = a, *db = b;
-  return !(strcmp (da->capa, db->capa) == 0 && da->data == db->data);
-}
-
-void
-mu_gocs_store (char *capa, void *data)
-{
-  struct mu_gocs_data *s;
-  if (!data_list)
-    {
-      mu_list_create (&data_list);
-      mu_list_set_destroy_item (data_list, mu_list_free_item);
-      mu_list_set_comparator (data_list, _gocs_comp);
-    }
-  s = malloc (sizeof *s);
-  if (!s)
-    {
-      mu_error ("%s", mu_strerror (ENOMEM));
-      exit (1);
-    }
-  s->capa = capa;
-  s->data = data;
-  if (mu_list_locate (data_list, s, NULL) == 0)
-    free (s);
-  else
-    mu_list_prepend (data_list, s);
-}
-
-int
-_gocs_flush (void *item, void *data)
-{
-  struct mu_gocs_data *s = item;
-  mu_gocs_init_fp initfun = find_init_function (_gocs_table, s->capa);
-
-  if (!initfun)
-    {
-      mu_error (_("INTERNAL ERROR at %s:%d: unknown capability `%s'"),
-		__FILE__, __LINE__, s->capa);
-      abort ();
-    }
-
-  if (initfun (mu_gocs_op_set, s->data))
-    {
-      mu_error (_("initialization of GOCS `%s' failed"), s->capa);
-      return 1;
-    }
-  
-  return 0;
-}
-
-void
-mu_gocs_flush ()
-{
-  int i;
-  mu_list_foreach (data_list, _gocs_flush, NULL);
-
-  for (i = 0; _gocs_table[i].name; i++)
-    _gocs_table[i].init (mu_gocs_op_flush, NULL);
-}
diff --git a/libmailutils/cli/capa.c b/libmailutils/cli/capa.c
index bd5c557..a3523e2 100644
--- a/libmailutils/cli/capa.c
+++ b/libmailutils/cli/capa.c
@@ -60,7 +60,7 @@ struct capa_apply
 };
 
 static int
-capa_apply (void *item, void *data)
+capa_extend (void *item, void *data)
 {
   struct mu_cli_capa *cp = item;
   struct capa_apply *ap = data;
@@ -80,14 +80,15 @@ capa_apply (void *item, void *data)
 }
 
 void
-mu_cli_capa_apply (char const *name, mu_list_t opts, mu_list_t commits)
+mu_cli_capa_extend_settings (char const *name, mu_list_t opts,
+			     mu_list_t commits)
 {
   struct capa_apply app;
   app.name = name;
   app.opts = opts;
   app.commits = commits;
   app.found = 0;
-  mu_list_foreach (capa_list, capa_apply, &app);
+  mu_list_foreach (capa_list, capa_extend, &app);
   if (!app.found)
     mu_error (_("INTERNAL ERROR at %s:%d: unknown standard capability `%s'"),
 	      __FILE__, __LINE__, name);
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 2dd142a..0a608ba 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -31,6 +31,7 @@
 #include <mailutils/stdstream.h>
 #include <mailutils/io.h>
 #include <mailutils/syslog.h>
+#include <mailutils/mu_auth.h>
 
 #ifndef MU_SITE_CONFIG_FILE
 # define MU_SITE_CONFIG_FILE SYSCONFDIR "/mailutils.rc"
@@ -85,6 +86,14 @@ extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
   struct mu_cli_setup *setup = hints->data;
   mu_stream_printf (stream, "%s\n", _(setup->prog_extra_doc));
 }
+
+static void
+prog_doc_hook (struct mu_parseopt *po, mu_stream_t stream)
+{
+  struct mu_cfg_parse_hints *hints = po->po_data;
+  struct mu_cli_setup *setup = hints->data;
+  setup->prog_doc_hook (stream);
+}
 
 static void
 change_progname (struct mu_parseopt *po, struct mu_option *opt,
@@ -283,6 +292,7 @@ init_options (char **capa, struct mu_cli_setup *setup,
 {
   size_t i, s;
   mu_list_t oplist;
+  mu_list_t comlist;
   struct mu_parseopt po;
   
   mu_list_create (&oplist);
@@ -291,16 +301,16 @@ init_options (char **capa, struct mu_cli_setup *setup,
       for (i = 0; setup->optv[i]; i++)
 	mu_list_append (oplist, setup->optv[i]);
     }
+
+  mu_list_create (&comlist);
+  mu_auth_extend_settings (oplist, comlist);
   if (capa)
     {
-      mu_list_t comlist;
-      mu_list_create (&comlist);
       for (i = 0; capa[i]; i++)
-	mu_cli_capa_apply (capa[i], oplist, comlist);
-      *ret_comlist = comlist;
+	mu_cli_capa_extend_settings (capa[i], oplist, comlist);
     }
-  else
-    *ret_comlist = NULL;
+
+  *ret_comlist = comlist;
   
   mu_list_append (oplist, mu_common_options);
   mu_list_append (oplist, mu_extra_help_options);
@@ -346,7 +356,9 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
     setup->ex_usage = EX_USAGE;
   if (setup->ex_config == 0)
     setup->ex_config = EX_CONFIG;
-  
+  if (setup->inorder)
+    flags |= MU_PARSEOPT_IN_ORDER;
+    
   /* Set program name */
   mu_set_program_name (argv[0]);
 
@@ -358,7 +370,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 
   /* Initialize standard capabilities */
   mu_cli_capa_init ();
-  
+
   /* Initialize hints */
   memset (&hints, 0, sizeof (hints));
   hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
@@ -370,6 +382,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   hints.data = setup;
   
   /* Initialize po */
+  
   if (setup->prog_doc)
     {
       po.po_prog_doc = setup->prog_doc;
@@ -423,6 +436,12 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
       po.po_help_hook = extra_help_hook;
       flags |= MU_PARSEOPT_HELP_HOOK;
     }
+
+  if (setup->prog_doc_hook)
+    {
+      po.po_prog_doc_hook = prog_doc_hook;
+      flags |= MU_PARSEOPT_PROG_DOC_HOOK;
+    }
   
   po.po_data = &hints;
   flags |= MU_PARSEOPT_DATA;
@@ -458,7 +477,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 
   mu_list_foreach (com_list, run_commit, NULL);
   mu_list_destroy (&com_list);
-  
+
   if (hints.flags & MU_PARSE_CONFIG_LINT)
     exit (0);
 
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index b1a81ea..8e54578 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -352,6 +352,12 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
     }
   mu_stream_printf (str, "\n");
   
+  if (po->po_prog_doc_hook)
+    {
+      po->po_prog_doc_hook (po, str);
+      mu_stream_printf (str, "\n");
+    }
+  
   mu_option_describe_options (str, po->po_optv, po->po_optc);
 
   if (po->po_help_hook)
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 7dd28a1..967cf89 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -213,6 +213,8 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
 	    case 0:
 	      ind = i;
 	      found++;
+	      if (optlen == strlen (po->po_optv[i]->opt_long))
+		i = po->po_optc - 1; /* exact match: break the loop */
 	      break;
 
 	    case 1:
@@ -511,6 +513,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
     po->po_exit_error = EXIT_ERROR;
   if (!(flags & MU_PARSEOPT_VERSION_HOOK))
     po->po_version_hook = NULL;
+  if (!(flags & MU_PARSEOPT_PROG_DOC_HOOK))
+    po->po_prog_doc_hook = NULL;
   
   /* Count the options */
   po->po_optc = 0;
diff --git a/libmu_argp/.gitignore b/libmu_argp/.gitignore
deleted file mode 100644
index 2248e8c..0000000
--- a/libmu_argp/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-*.la
-*.lo
-.deps
-.libs
-Makefile
-Makefile.in
-.gdbinit
diff --git a/libmu_argp/Makefile.am b/libmu_argp/Makefile.am
deleted file mode 100644
index 675ee62..0000000
--- a/libmu_argp/Makefile.am
+++ /dev/null
@@ -1,39 +0,0 @@
-# This file is part of GNU Mailutils
-# Copyright (C) 2007, 2009-2012, 2014-2016 Free Software Foundation,
-# Inc.
-#
-# GNU Mailutils is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3, or (at
-# your option) any later version.
-#
-# GNU Mailutils is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. 
-
-# This library uses gnulib calls and is always linked with gnulib, therefore
-# we use application includes here.
-AM_CPPFLAGS = \
- @MU_APP_COMMON_INCLUDES@\
- -DSYSCONFDIR=\"$(sysconfdir)\"\
- -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\
- -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
-
-lib_LTLIBRARIES = libmu_argp.la
-
-libmu_argp_la_SOURCES =\
- cmdline.c\
- cmdline.h\
- common.c\
- mailutils.c\
- mu_argp.c\
- muinit.c\
- sieve.c
-
-libmu_argp_la_LIBADD=../lib/libmuaux.la
-
-libmu_argp_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
diff --git a/libmu_argp/cmdline.c b/libmu_argp/cmdline.c
deleted file mode 100644
index 55dabed..0000000
--- a/libmu_argp/cmdline.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "cmdline.h"
-
-static struct mu_cmdline_capa *all_cmdline_capa[] = {
-  &mu_mailutils_cmdline,
-  &mu_common_cmdline,
-  &mu_logging_cmdline,
-  &mu_mailer_cmdline,
-  &mu_debug_cmdline,
-  &mu_sieve_cmdline,
-  NULL
-};
-
-static int libargp_init_passed = 0;
-
-void
-mu_libargp_init ()
-{
-  struct mu_cmdline_capa **cpp;
-  if (libargp_init_passed)
-    return;
-  libargp_init_passed = 1;
-  for (cpp = all_cmdline_capa; *cpp; cpp++)
-    {
-      struct mu_cmdline_capa *cp = *cpp;
-      if (mu_register_argp_capa (cp->name, cp->child, cp->modflags))
-	{
-	  mu_error (_("INTERNAL ERROR: cannot register argp capability `%s'"),
-		    cp->name);
-	  abort ();
-	}
-    }
-}
-
-void
-mu_argp_node_list_init (mu_list_t *plist)
-{
-  int rc = mu_cfg_create_node_list (plist);
-  if (rc)
-    {
-      mu_diag_funcall (MU_DIAG_ERROR, "mu_cfg_create_node_list", NULL, rc);
-      abort ();
-    }
-}
-
-void
-mu_argp_node_list_add (mu_list_t lst, mu_cfg_node_t *node)
-{
-  int rc = mu_list_append (lst, node);
-  if (rc)
-    {
-      mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", NULL, rc);
-      abort ();
-    }
-}
-		   
-void
-mu_argp_node_list_new (mu_list_t lst, const char *tag, const char *label)
-{
-  mu_cfg_node_t *node;
-  size_t n;
-  struct mu_locus loc = { "command line", 0 };
-
-  mu_list_count (lst, &n);
-  loc.mu_line = n;
-  node = mu_cfg_tree_create_node (mu_argp_tree, mu_cfg_node_param,
-				  &loc, tag, label, NULL);
-  mu_argp_node_list_add (lst, node);
-}
-
-void
-mu_argp_node_list_finish (mu_list_t lst, char *tag, char *label)
-{
-  if (mu_list_is_empty (lst))
-    return;
-  if (tag)
-    {
-      mu_cfg_node_t *node = mu_cfg_tree_create_node (mu_argp_tree,
-						     mu_cfg_node_statement,
-						     NULL,
-						     tag, label,
-						     lst);
-      mu_cfg_tree_add_node (mu_argp_tree, node);
-    }
-  else
-    {
-      mu_cfg_tree_add_nodelist (mu_argp_tree, lst);
-      mu_list_destroy (&lst);
-    }
-}
-
diff --git a/libmu_argp/cmdline.h b/libmu_argp/cmdline.h
deleted file mode 100644
index 46d5463..0000000
--- a/libmu_argp/cmdline.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
-   Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see 
-   <http://www.gnu.org/licenses/>. */
-
-#include "mailutils/libcfg.h"
-#include "mailutils/libargp.h"
-
-extern struct mu_cfg_tree *mu_argp_tree;
diff --git a/libmu_argp/common.c b/libmu_argp/common.c
deleted file mode 100644
index 3f245c8..0000000
--- a/libmu_argp/common.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "cmdline.h"
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/syslog.h>
-#include <mailutils/mailbox.h>
-
-
-/* ************************************************************************* */
-/* Common                                                                    */
-/* ************************************************************************* */
-
-enum {
-  OPT_SHOW_OPTIONS=256,          
-  OPT_NO_USER_RCFILE,
-  OPT_NO_SITE_RCFILE,
-  OPT_RCFILE,
-  OPT_RCFILE_LINT,
-  OPT_RCFILE_VERBOSE,
-  OPT_LOG_FACILITY,          
-  OPT_LICENSE,
-  OPT_DEBUG_LEVEL,
-  OPT_LINE_INFO,
-  OPT_HELP_CONFIG,
-  OPT_SET
-};
-
-static struct argp_option mu_common_argp_options[] = 
-{
-  { NULL, 0, NULL, 0, N_("Common options"), 0},
-  { "show-config-options", OPT_SHOW_OPTIONS, NULL, 0,
-    N_("show compilation options"), 0 },
-  { "config-help", OPT_HELP_CONFIG, NULL, 0,
-    N_("show configuration file summary"), 0 },
-  { "no-user-config", OPT_NO_USER_RCFILE, NULL, 0,
-    N_("do not load user configuration file"), 0 },
-  { "no-user-rcfile", 0, NULL, OPTION_ALIAS, NULL },
-  { "no-site-config", OPT_NO_SITE_RCFILE, NULL, 0,
-    N_("do not load site configuration file"), 0 },
-  { "no-site-rcfile", 0, NULL, OPTION_ALIAS, NULL },
-  { "config-file", OPT_RCFILE, N_("FILE"), 0,
-    N_("load this configuration file"), 0, },
-  { "rcfile", 0, NULL, OPTION_ALIAS, NULL },
-  { "config-verbose", OPT_RCFILE_VERBOSE, NULL, 0,
-    N_("verbosely log parsing of the configuration files"), 0 },
-  { "rcfile-verbose", 0, NULL, OPTION_ALIAS, NULL },
-  { "config-lint", OPT_RCFILE_LINT, NULL, 0,
-    N_("check configuration file syntax and exit"), 0 },
-  { "rcfile-lint", 0, NULL, OPTION_ALIAS, NULL },
-  { "set", OPT_SET, N_("PARAM=VALUE"), 0,
-    N_("set configuration parameter"), 0 },
-  { NULL, 0, NULL, 0, NULL, 0 }
-};
-
-static void
-set_config_param (const char *path, struct argp_state *state)
-{
-  mu_cfg_node_t *node;
-  int rc = mu_cfg_create_subtree (path, &node);
-  if (rc)
-    argp_error (state, "cannot create node: %s", mu_strerror (rc));
-  mu_cfg_tree_add_node (mu_argp_tree, node);
-}
-
-static error_t
-mu_common_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case OPT_SHOW_OPTIONS:
-      mu_print_options ();
-      exit (0);
-
-    case OPT_NO_USER_RCFILE:
-      mu_load_user_rcfile = 0;
-      break;
-      
-    case OPT_NO_SITE_RCFILE:
-      mu_load_site_rcfile = 0;
-      break;
-      
-    case OPT_RCFILE:
-      mu_load_rcfile = arg;
-      break;
-
-    case OPT_RCFILE_LINT:
-      mu_cfg_parser_verbose++;
-      mu_rcfile_lint = 1;
-      break;
-      
-    case OPT_RCFILE_VERBOSE:
-      mu_cfg_parser_verbose++;
-      break;
-
-    case OPT_HELP_CONFIG:
-      mu_help_config_mode = 1;
-      break;
-
-    case OPT_SET:
-      set_config_param (arg, state);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_common_argp = {
-  mu_common_argp_options,
-  mu_common_argp_parser,
-};
-
-struct argp_child mu_common_argp_child = {
-  &mu_common_argp,
-  0,
-  NULL,
-  0,
-};
-
-struct mu_cmdline_capa mu_common_cmdline = {
-  "common", &mu_common_argp_child
-};
-
-
-/* ************************************************************************* */
-/* Logging                                                                   */
-/* ************************************************************************* */
-
-static struct argp_option mu_logging_argp_option[] = {
-  {"log-facility", OPT_LOG_FACILITY, N_("FACILITY"), 0,
-   N_("output logs to syslog FACILITY"), 0},
-  { NULL,      0, NULL, 0, NULL, 0 }
-};
-
-static error_t
-mu_logging_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-  
-  switch (key)
-    {
-      /* log */
-    case OPT_LOG_FACILITY:
-      mu_argp_node_list_new (lst, "facility", arg);
-      break;
-	  
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, "logging", NULL);
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_logging_argp = {
-  mu_logging_argp_option,
-  mu_logging_argp_parser,
-};
-
-struct argp_child mu_logging_argp_child = {
-  &mu_logging_argp,
-  0,
-  NULL,
-  0
-};
-
-struct mu_cmdline_capa mu_logging_cmdline = {
-  "logging", &mu_logging_argp_child
-};
-
-
-/* ************************************************************************* */
-/* Mailer                                                                    */
-/* ************************************************************************* */
-
-/* Options used by programs that send mail. */
-static struct argp_option mu_mailer_argp_option[] = {
-  {"mailer", 'M', N_("MAILER"), 0,
-   N_("use specified URL as the default mailer"), 0},
-  { NULL,      0, NULL, 0, NULL, 0 }
-};
-
-static error_t
-mu_mailer_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-
-  switch (key)
-    {
-      /* mailer */
-    case 'M':
-      mu_argp_node_list_new (lst, "url", arg);
-      break;
-
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, "mailer", NULL);
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_mailer_argp = {
-  mu_mailer_argp_option,
-  mu_mailer_argp_parser,
-};
-
-struct argp_child mu_mailer_argp_child = {
-  &mu_mailer_argp,
-  0,
-  NULL,
-  0
-};
-
-struct mu_cmdline_capa mu_mailer_cmdline = {
-  "mailer", &mu_mailer_argp_child
-};
-
-
-static struct argp_option mu_debug_argp_options[] = 
-{
-  { "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
-    N_("set Mailutils debugging level"), 0 },
-  { "debug-line-info", OPT_LINE_INFO, NULL, 0,
-    N_("show source info with debugging messages"), 0 },
-  { NULL }
-};
-
-static error_t
-mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-
-  switch (key)
-    {
-    case OPT_DEBUG_LEVEL:
-      mu_debug_parse_spec (arg);
-      /*mu_argp_node_list_new (lst, "level", arg);*/
-      break;
-
-    case OPT_LINE_INFO:
-      mu_argp_node_list_new (lst, "line-info", "yes");
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, "debug", NULL);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_debug_argp = {
-  mu_debug_argp_options,
-  mu_debug_argp_parser,
-};
-
-struct argp_child mu_debug_argp_child = {
-  &mu_debug_argp,
-  0,
-  N_("Global debugging settings"),
-  0
-};
-
-struct mu_cmdline_capa mu_debug_cmdline = {
-  "debug", &mu_debug_argp_child
-};
diff --git a/libmu_argp/mailutils.c b/libmu_argp/mailutils.c
deleted file mode 100644
index 83ed9a8..0000000
--- a/libmu_argp/mailutils.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "cmdline.h"
-#include <unistd.h>
-#include <stdlib.h>
-/* Provide declaration of __argp_base_name: */
-#include <argp-namefrob.h> 
-
-
-/* ************************************************************************* */
-/* GNU Mailutils help and version output                                     */
-/* ************************************************************************* */
-
-#define OPT_PROGNAME    -2
-#define OPT_USAGE       -3
-#define OPT_HANG        -4
-
-static struct argp_option mu_mailutils_argp_options[] = 
-{
-  {"help",        '?',          0, 0,  N_("give this help list"), -1},
-  {"usage",       OPT_USAGE,    0, 0,  N_("give a short usage message"), 0},
-  {"version",     'V',          0, 0,  N_("print program version"), -1},
-  {"program-name",OPT_PROGNAME,N_("NAME"), OPTION_HIDDEN, N_("set the program name"), 0},
-  {"HANG",        OPT_HANG,    N_("SECS"), OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
-     N_("hang for SECS seconds (default 3600)"), 0},
-  { NULL }
-};
-
-static error_t
-mu_mailutils_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case '?':
-      argp_state_help (state, state->out_stream,
-		       ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_DOC);
-      /* TRANSLATORS: The placeholder indicates the bug-reporting address
-	 for this package.  Please add _another line_ saying
-	 "Report translation bugs to <...>\n" with the address for translation
-	 bugs (typically your translation team's web or email address).  */
-      printf (_("\nReport bugs to: %s\n"), "<" PACKAGE_BUGREPORT ">");
-      
-#ifdef PACKAGE_PACKAGER_BUG_REPORTS
-      printf (_("Report %s bugs to: %s\n"), PACKAGE_PACKAGER,
-	      PACKAGE_PACKAGER_BUG_REPORTS);
-#endif
-      
-#ifdef PACKAGE_URL
-      printf (_("%s home page: <%s>\n"), PACKAGE_NAME, PACKAGE_URL);
-#endif
-      fputs (_("General help using GNU software: <http://www.gnu.org/gethelp/>\n"),
-	stdout);
-      exit (0);
-
-    case OPT_USAGE:
-      argp_state_help (state, state->out_stream,
-		       ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
-      break;
-
-    case 'V':
-      if (argp_program_version_hook)
-        (*argp_program_version_hook) (state->out_stream, state);
-      else if (argp_program_version)
-        fprintf (state->out_stream, "%s\n", argp_program_version);
-      else
-        argp_error (state, "%s",
-		    dgettext (state->root_argp->argp_domain,
-			      "(PROGRAM ERROR) No version known!?"));
-      exit(0);
-      
-    case OPT_PROGNAME:          /* Set the program name.  */
-#if HAVE_DECL_PROGRAM_INVOCATION_NAME
-      program_invocation_name = arg;
-#endif
-      /* Update what we use for messages.  */
-      state->name = __argp_base_name (arg);
-
-#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
-      program_invocation_short_name = state->name;
-#endif
-
-      if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
-	  == ARGP_PARSE_ARGV0)
-        /* Update what getopt uses too.  */
-        state->argv[0] = arg;
-      break;
-
-    case OPT_HANG:
-      {
-	int hang = atoi (arg ? arg : "3600");
-	while (hang-- > 0)
-	  sleep (1);
-	break;      
-      }
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_mailutils_argp = {
-  mu_mailutils_argp_options,
-  mu_mailutils_argp_parser,
-};
-
-struct argp_child mu_mailutils_argp_child = {
-  &mu_mailutils_argp,
-  0,
-  NULL,
-  -1,
-};
-
-static void
-mu_mailutils_modflags(int *flags)
-{
-  *flags |= ARGP_NO_HELP;
-}
-
-struct mu_cmdline_capa mu_mailutils_cmdline = {
-  "mailutils", &mu_mailutils_argp_child, mu_mailutils_modflags
-};
-
-
-    
-
-
-  
diff --git a/libmu_argp/mu_argp.c b/libmu_argp/mu_argp.c
deleted file mode 100644
index 74b0b30..0000000
--- a/libmu_argp/mu_argp.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2001-2007, 2009-2012, 2014-2016 Free Software
-   Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see 
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <syslog.h>
-#include <unistd.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "mailutils/libargp.h"
-
-
-/* ************************************************************************* */
-/* Capability array and auxiliary functions.                                 */
-/* ************************************************************************* */
-
-#define MU_MAX_CAPA 24
-
-struct argp_capa {
-  char *capability;
-  struct argp_child *child;
-  void (*modflags)(int*);
-} mu_argp_capa[MU_MAX_CAPA] = {
-  {NULL,}
-};
-
-int
-mu_register_argp_capa (const char *name, struct argp_child *child,
-		       void (*modflags)(int*))
-{
-  int i;
-  
-  for (i = 0; i < MU_MAX_CAPA; i++)
-    if (mu_argp_capa[i].capability == NULL)
-      {
-        if ((mu_argp_capa[i].capability = strdup (name)) == NULL)
-          return ENOMEM;
-	mu_argp_capa[i].child = child;
-	mu_argp_capa[i].modflags = modflags;
-	return 0;
-      }
-  return 1;
-}
-
-static struct argp_capa *
-find_capa (const char *name)
-{
-  int i;
-  for (i = 0; mu_argp_capa[i].capability; i++)
-    if (strcmp (mu_argp_capa[i].capability, name) == 0)
-      return &mu_argp_capa[i];
-  return NULL;
-}
-
-static struct argp *
-mu_build_argp (const struct argp *template, char **capa, int *flags)
-{
-  int n;
-  int nchild;
-  struct argp_child *ap;
-  const struct argp_option *opt;
-  struct argp *argp;
-  int group = 0;
-
-  /* Count the capabilities. */
-  for (n = 0; capa && capa[n]; n++)
-    ;
-  if (template->children)
-    for (; template->children[n].argp; n++)
-      ;
-
-  ap = calloc (n + 1, sizeof (*ap));
-  if (!ap)
-    {
-      mu_error (_("not enough memory"));
-      abort ();
-    }
-
-  /* Copy the template's children. */
-  nchild = 0;
-  if (template->children)
-    for (n = 0; template->children[n].argp; n++, nchild++)
-      ap[nchild] = template->children[n];
-
-  /* Find next group number */
-  for (opt = template->options;
-       opt && ((opt->name && opt->key) || opt->doc); opt++)
-    if (opt->group > group)
-      group = opt->group;
-
-  group++;
-    
-  /* Append any capabilities to the children or options, as appropriate. */
-  for (n = 0; capa && capa[n]; n++)
-    {
-      struct argp_capa *cp = find_capa (capa[n]);
-      if (cp)
-	{
-	  if (cp->modflags)
-	    cp->modflags (flags);
-	  if (cp->child)
-	    {
-	      ap[nchild] = *cp->child;
-	      if (ap[nchild].group < 0)
-		ap[nchild].group = 0;
-	      else
-		ap[nchild].group = group++;
-	      nchild++;
-	    }
-	}
-    }
-  ap[nchild].argp = NULL;
-
-  /* Copy the template, and give it the expanded children. */
-  argp = malloc (sizeof (*argp));
-  if (!argp)
-    {
-      mu_error (_("not enough memory"));
-      abort ();
-    }
-
-  memcpy (argp, template, sizeof (*argp));
-
-  argp->children = ap;
-
-  return argp;
-}
-
-struct cap_buf
-{
-  char **capa;
-  size_t numcapa;
-  size_t maxcapa;
-};
-
-static void
-cap_buf_init (struct cap_buf *bp)
-{
-  bp->numcapa = 0;
-  bp->maxcapa = 2;
-  bp->capa = calloc (bp->maxcapa, sizeof bp->capa[0]);
-  if (!bp->capa)
-    {
-      mu_error ("%s", mu_strerror (errno));
-      abort ();
-    }
-  bp->capa[0] = NULL;
-}
-
-static void
-cap_buf_add (struct cap_buf *bp, char *str)
-{
-  if (bp->numcapa == bp->maxcapa)
-    {
-      bp->maxcapa *= 2;
-      bp->capa = realloc (bp->capa, bp->maxcapa * sizeof bp->capa[0]);
-      if (!bp->capa)
-	{
-	  mu_error ("%s", mu_strerror (errno));
-	  abort ();
-	}
-    }
-  bp->capa[bp->numcapa] = str;
-  if (str)
-    bp->numcapa++;
-}
-
-static void
-cap_buf_free (struct cap_buf *bp)
-{
-  free (bp->capa);
-}
-
-static int
-argp_reg_action (void *item, void *data)
-{
-  struct cap_buf *bp = data;
-  cap_buf_add (bp, item);
-  return 0;
-}
-
-struct argp *
-mu_argp_build (const struct argp *init_argp, char ***pcapa, int *flags)
-{
-  struct cap_buf cb;
-  struct argp *argp;
-
-  cap_buf_init (&cb);
-  mu_gocs_enumerate (argp_reg_action, &cb);
-  cap_buf_add (&cb, NULL);
-  mu_libargp_init ();
-  argp = mu_build_argp (init_argp, cb.capa, flags);
-  if (pcapa)
-    *pcapa = cb.capa;
-  else
-    cap_buf_free (&cb);
-  return argp;
-}
-
-void
-mu_argp_done (struct argp *argp)
-{
-  free ((void*) argp->children);
-  free ((void*) argp);
-}
diff --git a/libmu_argp/muinit.c b/libmu_argp/muinit.c
deleted file mode 100644
index 50a4a9b..0000000
--- a/libmu_argp/muinit.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "cmdline.h"
-#include <unistd.h>
-#include <stdlib.h>
-#include <mailutils/alloc.h>
-#include <mailutils/stream.h>
-#include <mailutils/io.h>
-#include <mailutils/stdstream.h>
-#include <string.h>
-#ifdef MU_ALPHA_RELEASE
-# include <git-describe.h>
-#endif
-struct mu_cfg_tree *mu_argp_tree;
-
-const char version_etc_copyright[] =
-  /* Do *not* mark this string for translation.  %s is a copyright
-     symbol suitable for this locale, and %d is the copyright
-     year.  */
-  "Copyright %s 2007-2015 Free Software Foundation, inc.";
-
-void
-mu_program_version_hook (FILE *stream, struct argp_state *state)
-{
-#ifdef GIT_DESCRIBE
-  fprintf (stream, "%s (%s) %s [%s]\n",
-	   mu_program_name, PACKAGE_NAME, PACKAGE_VERSION, GIT_DESCRIBE);
-#else
-  fprintf (stream, "%s (%s) %s\n", mu_program_name,
-	   PACKAGE_NAME, PACKAGE_VERSION);
-#endif
-  /* TRANSLATORS: Translate "(C)" to the copyright symbol
-     (C-in-a-circle), if this symbol is available in the user's
-     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
-  fprintf (stream, version_etc_copyright, _("(C)"));
-
-  fputs (_("\
-\n\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
-There is NO WARRANTY, to the extent permitted by law.\n\
-\n\
-"),
-	 stream);
-}
-
-void
-mu_argp_init (const char *vers, const char *bugaddr)
-{
-  if (vers)
-    argp_program_version = vers;
-  else
-    argp_program_version_hook = mu_program_version_hook;
-  argp_program_bug_address = bugaddr ? bugaddr : "<" PACKAGE_BUGREPORT ">";
-}
-
-static char *
-get_canonical_name ()
-{
-  char *name;
-  size_t len;
-  char *p;
-
-  if (!argp_program_version ||
-      !(p = strchr (argp_program_version, ' ')))
-    return strdup (mu_program_name);
-  len = p - argp_program_version;
-  name = mu_alloc (len + 1);
-  memcpy (name, argp_program_version, len);
-  name[len] = 0;
-  return name;
-}
-
-int mu_help_config_mode;
-int mu_rcfile_lint;
-
-int (*mu_app_cfg_verifier) (void) = NULL;
-
-int
-mu_app_init (struct argp *myargp, const char **capa,
-	     struct mu_cfg_param *cfg_param,
-	     int argc, char **argv, int flags, int *pindex, void *data)
-{
-  int rc, i;
-  struct argp *argp;
-  struct argp argpnull = { 0 };
-  char **excapa;
-  struct mu_cfg_tree *parse_tree = NULL;
-  
-  if (!mu_program_name)
-    mu_set_program_name (argv[0]);
-  if (!mu_log_tag)
-    mu_log_tag = (char*)mu_program_name;
-  mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
-  
-  mu_libargp_init ();
-  if (capa)
-    for (i = 0; capa[i]; i++)
-      mu_gocs_register_std (capa[i]); /*FIXME*/
-  if (!myargp)
-    myargp = &argpnull;
-  argp = mu_argp_build (myargp, &excapa, &flags);
-
-  mu_cfg_tree_create (&mu_argp_tree);
-  rc = argp_parse (argp, argc, argv, flags, pindex, data);
-  mu_argp_done (argp);
-  if (rc)
-    return rc;
-
-  /* Reset program name, it may have been changed using the `--program-name'
-     option. */
-  mu_set_program_name (program_invocation_name);
-  
-  mu_libcfg_init (excapa);
-  free (excapa);
-
-  if (mu_help_config_mode)
-    {
-      char *comment;
-      char *canonical_name = get_canonical_name ();
-      mu_stream_t stream;
-      struct mu_cfg_cont *cont;
-      static struct mu_cfg_param dummy_include_param[] = {
-	{ "include", mu_c_string, NULL, 0, NULL,
-	  N_("Include contents of the given file.  If a directory is given, "
-	     "include contents of the file <file>/<program>, where "
-	     "<program> is the name of the program.  This latter form is "
-	     "allowed only in the site-wide configuration file."),
-	  N_("file-or-directory") },
-	{ NULL }
-      };
-
-      mu_stdio_stream_create (&stream, MU_STDOUT_FD, 0);
-
-      mu_asprintf (&comment,
-		   "Configuration file structure for %s utility.",
-		   mu_program_name);
-      mu_cfg_format_docstring (stream, comment, 0);
-      free (comment);
-      mu_asprintf (&comment,
-		   "For use in global configuration file (%s), enclose it "
-		   "in `program %s { ... };",
-		   mu_site_rcfile,
-		   mu_program_name);		   
-      mu_cfg_format_docstring (stream, comment, 0);
-      free (comment);
-      mu_asprintf (&comment, "For more information, use `info %s'.",
-		   canonical_name);
-      mu_cfg_format_docstring (stream, comment, 0);
-      free (comment);
-
-      cont = mu_config_clone_root_container ();
-      mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
-					    dummy_include_param, NULL);
-      mu_config_container_register_section (&cont, NULL, NULL, NULL, NULL,
-					    cfg_param, NULL);
-      mu_cfg_format_container (stream, cont);
-      mu_config_destroy_container (&cont);
-      
-      mu_stream_destroy (&stream);
-      exit (0);
-    }
-
-  rc = mu_libcfg_parse_config (&parse_tree);
-  if (rc == 0)
-    {
-      struct mu_cfg_parse_hints hints = { MU_PARSE_CONFIG_PLAIN };
-
-      hints.flags |= MU_CFG_PARSE_PROGRAM;
-      hints.program = (char*)mu_program_name;
-
-      if (mu_cfg_parser_verbose)
-	hints.flags |= MU_PARSE_CONFIG_VERBOSE;
-      if (mu_cfg_parser_verbose > 1)
-	hints.flags |= MU_PARSE_CONFIG_DUMP;
-      mu_cfg_tree_postprocess (mu_argp_tree, &hints);
-      mu_cfg_tree_union (&parse_tree, &mu_argp_tree);
-      rc = mu_cfg_tree_reduce (parse_tree, &hints, cfg_param, data);
-    }
-  
-  if (mu_rcfile_lint)
-    {
-      if (rc || mu_cfg_error_count)
-	exit (1);
-      if (mu_app_cfg_verifier)
-	rc = mu_app_cfg_verifier ();
-      exit (rc ? 1 : 0);
-    }
-  
-  mu_gocs_flush ();
-  mu_cfg_destroy_tree (&mu_argp_tree);
-  mu_cfg_destroy_tree (&parse_tree);
-
-  return !!(rc || mu_cfg_error_count);
-}
-
diff --git a/libmu_argp/sieve.c b/libmu_argp/sieve.c
deleted file mode 100644
index efed372..0000000
--- a/libmu_argp/sieve.c
+++ /dev/null
@@ -1,103 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999-2002, 2005, 2007, 2009-2012, 2014-2016 Free
-   Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif  
-#include "cmdline.h"
-#include "mailutils/sieve.h"
-
-enum {
-  OPT_CLEAR_INCLUDE_PATH = 256,
-  OPT_CLEAR_LIBRARY_PATH,
-  OPT_PREFIX_LIBRARY_PATH
-};  
-
-static struct argp_option sieve_argp_option[] = {
-  { "includedir", 'I', N_("DIR"), 0,
-    N_("append DIR to the list of directories searched for include files"), 0 },
-  { "libdir", 'L', N_("DIR"), 0,
-    N_("append DIR to the list of directories searched for library files"), 0 },
-  { "libdir-prefix", OPT_PREFIX_LIBRARY_PATH, N_("DIR"), 0,
-    N_("add DIR to the beginning of the list of directories searched for "
-       "library files"), 0 },
-  { "clear-include-path", OPT_CLEAR_INCLUDE_PATH, NULL, 0,
-    N_("clear Sieve include path"), 0 },
-  { "clear-library-path", OPT_CLEAR_LIBRARY_PATH, NULL, 0,
-    N_("clear Sieve library path"), 0 },
-  { "clearpath", 0, NULL, OPTION_ALIAS, NULL },
-  { NULL,      0, NULL, 0, NULL, 0 }
-};
-
-static error_t
-sieve_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  static mu_list_t lst;
-  
-  switch (key)
-    {
-    case 'I':
-      mu_argp_node_list_new (lst, "include-path", arg);
-      break;
-
-    case 'L':
-      mu_argp_node_list_new (lst, "library-path", arg);
-      break;
-
-    case OPT_PREFIX_LIBRARY_PATH:
-      mu_argp_node_list_new (lst, "library-path-prefix", arg);
-      break;
-      
-    case OPT_CLEAR_INCLUDE_PATH:
-      mu_argp_node_list_new (lst, "clear-include-path", "yes");
-      break;
-
-    case OPT_CLEAR_LIBRARY_PATH:
-      mu_argp_node_list_new (lst, "clear-library-path", "yes");
-      break;
-      
-    case ARGP_KEY_INIT:
-      mu_argp_node_list_init (&lst);
-      break;
-      
-    case ARGP_KEY_FINI:
-      mu_argp_node_list_finish (lst, "sieve", NULL);
-      break;
-			   
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp sieve_argp = {
-  sieve_argp_option,
-  sieve_argp_parser,
-};
-
-static struct argp_child sieve_argp_child = {
-  &sieve_argp,
-  0,
-  N_("Sieve options"),
-  0
-};
-
-struct mu_cmdline_capa mu_sieve_cmdline = {
-  "sieve", &sieve_argp_child
-};
-
diff --git a/libmu_auth/gsasl.c b/libmu_auth/gsasl.c
index 5ffd0fe..e8c50dc 100644
--- a/libmu_auth/gsasl.c
+++ b/libmu_auth/gsasl.c
@@ -19,6 +19,7 @@
 #if HAVE_CONFIG_H
 # include <config.h>
 #endif
+#include <mailutils/cli.h>
 
 #ifdef WITH_GSASL
 
@@ -45,14 +46,28 @@ struct mu_gsasl_module_data mu_gsasl_module_data = {
   NULL,
   SITE_CRAM_MD5_PWD
 };
-
-int
-mu_gsasl_module_init (enum mu_gocs_op op, void *data)
-{
-  if (op == mu_gocs_op_set && data)
-    memcpy (&mu_gsasl_module_data, data, sizeof (mu_gsasl_module_data));
-  return 0;
-}
+
+static struct mu_cfg_param mu_gsasl_param[] = {
+  { "enable", mu_c_bool, &mu_gsasl_module_data.enable, 0, NULL,
+    N_("Enable GSASL (default)") },
+  { "cram-passwd", mu_c_string, &mu_gsasl_module_data.cram_md5_pwd, 0, NULL,
+    N_("Name of GSASL password file."),
+    N_("file") },
+  { "service", mu_c_string, &mu_gsasl_module_data.service, 0, NULL,
+    N_("SASL service name."),
+    N_("name") },
+  { "realm", mu_c_string, &mu_gsasl_module_data.realm, 0, NULL,
+    N_("SASL realm name."),
+    N_("name") },
+  { "hostname", mu_c_string, &mu_gsasl_module_data.hostname, 0, NULL,
+    N_("SASL host name."),
+    N_("name") },
+  { "anonymous-user", mu_c_string, &mu_gsasl_module_data.anon_user, 0, NULL,
+    N_("Anonymous user name."),
+    N_("name") },
+
+  { NULL }
+};
 
 int
 mu_gsasl_enabled (void)
@@ -231,4 +246,10 @@ mu_gsasl_enabled (void)
 {
   return 0;
 }
+#define mu_gsasl_param NULL
 #endif
+
+struct mu_auth_module mu_auth_gsasl_module = {
+  .name = "gsasl",
+  .cfg = mu_gsasl_param
+};
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 7c321f2..246f802 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -61,17 +61,82 @@ const char *default_field_map =
 
 static struct mu_ldap_module_config ldap_param;
 
-int
-mu_ldap_module_init (enum mu_gocs_op op, void *data)
+
+
+static int
+_cb2_field_map (const char *arg, void *data)
+{
+  int err;
+  int rc = mutil_parse_field_map (arg, &ldap_param.field_map, &err);
+  if (rc)
+    /* FIXME: this message can be misleading */
+    mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
+  return 0;
+}
+
+static int
+cb_field_map (void *data, mu_config_value_t *val)
 {
-  struct mu_ldap_module_config *cfg = data;
+  return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
+}
 
-  if (op != mu_gocs_op_set)
-    return 0;
-  
-  if (cfg)
-    ldap_param = *cfg;
+static struct mu_cfg_param mu_ldap_param[] = {
+  { "enable", mu_c_bool, &ldap_param.enable, 0, NULL,
+    N_("Enable LDAP lookups.") },
+  { "url", mu_c_string, &ldap_param.url, 0, NULL,
+    N_("Set URL of the LDAP server."),
+    N_("url") },
+  { "base", mu_c_string, &ldap_param.base, 0, NULL,
+    N_("Base DN for LDAP lookups."),
+    N_("dn") },
+  { "binddn", mu_c_string, &ldap_param.binddn, 0, NULL,
+    N_("DN for accessing LDAP database."),
+    N_("dn") },
+  { "passwd", mu_c_string, &ldap_param.passwd, 0, NULL,
+    N_("Password for use with binddn.") },
+  { "tls", mu_c_bool, &ldap_param.tls, 0, NULL,
+    N_("Use TLS encryption.") },
+  { "debug", mu_c_int, &ldap_param.debug, 0, NULL,
+    N_("Set LDAP debugging level.") },
+  { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
+    N_("Set a field-map for parsing LDAP replies.  The map is a "
+       "column-separated list of definitions.  Each definition has the "
+       "following form:\n"
+       "   <name: string>=<attr: string>\n"
+       "where <name> is one of the following: name, passwd, uid, gid, "
+       "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
+       "the corresponding LDAP attribute."),
+    N_("map") },
+  { "getpwnam", mu_c_string, &ldap_param.getpwnam_filter, 0, NULL,
+    N_("LDAP filter to use for getpwnam requests."),
+    N_("filter") },
+  { "getpwuid", mu_c_string, &ldap_param.getpwuid_filter, 0, NULL,
+    N_("LDAP filter to use for getpwuid requests."),
+    N_("filter") },
+  { NULL }
+};
+
+int									      
+mu_ldap_section_parser
+   (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,	      
+    const char *section_label, void **section_data,
+    void *call_data, mu_cfg_tree_t *tree)
+{									      
+  switch (stage)							      
+    {									      
+    case mu_cfg_section_start:
+      ldap_param.enable = 1;
+      break;
+    default:
+      break;
+    }									      
+  return 0;								      
+}
 
+
+static void
+module_init (void *ptr)
+{
   if (ldap_param.enable)
     {
       if (!ldap_param.getpwnam_filter)
@@ -85,7 +150,6 @@ mu_ldap_module_init (enum mu_gocs_op op, void *data)
 	  mutil_parse_field_map (default_field_map, &ldap_param.field_map, &d);
 	}
     }
-  return 0;
 }
 
 static int
@@ -271,8 +335,6 @@ _mu_conn_setup (LDAP **pld)
   *pld = ld;
   return 0;
 }
-  
-     
 
 static int
 _mu_ldap_bind (LDAP *ld)
@@ -862,15 +924,16 @@ mu_auth_ldap_user_by_uid (struct mu_auth_data **return_data,
 # define mu_ldap_authenticate mu_auth_nosupport
 # define mu_auth_ldap_user_by_name mu_auth_nosupport 
 # define mu_auth_ldap_user_by_uid mu_auth_nosupport
+
 #endif
 
 struct mu_auth_module mu_auth_ldap_module = {
-  "ldap",
-  mu_ldap_module_init,
-  mu_ldap_authenticate,
-  NULL,
-  mu_auth_ldap_user_by_name,
-  NULL,
-  mu_auth_ldap_user_by_uid,
-  NULL
+  .name = "ldap",
+  .commit = module_init,
+  .handler = {
+    [mu_auth_authenticate] = mu_ldap_authenticate,
+    [mu_auth_getpwnam]     = mu_auth_ldap_user_by_name,
+    [mu_auth_getpwuid]     = mu_auth_ldap_user_by_uid
+  },
+  .cfg = mu_ldap_param
 };
diff --git a/libmu_auth/pam.c b/libmu_auth/pam.c
index 2bf3683..fbc3e3e 100644
--- a/libmu_auth/pam.c
+++ b/libmu_auth/pam.c
@@ -49,6 +49,14 @@
 char *mu_pam_service = PACKAGE;
 
 #ifdef USE_LIBPAM
+static struct mu_cfg_param mu_pam_param[] = {
+  { "service", mu_c_string, &mu_pam_service, 0, NULL,
+    N_("Set PAM service name."),
+    N_("name") },
+  { NULL }
+};
+
+
 #define COPY_STRING(s) (s) ? strdup(s) : NULL
 
 static char *_pwd;
@@ -175,43 +183,13 @@ mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
 }
 
 #else
-
-int
-mu_authenticate_pam (struct mu_auth_data **return_data MU_ARG_UNUSED,
-		     const void *key MU_ARG_UNUSED,
-		     void *func_data MU_ARG_UNUSED,
-		     void *call_data MU_ARG_UNUSED)
-{
-  return ENOSYS;
-}
-
+# define mu_pam_param NULL
+# define mu_authenticate_pam NULL
 #endif
 
-int
-mu_pam_module_init (enum mu_gocs_op op, void *data)
-{
-  if (op == mu_gocs_op_set && data)
-    {
-      struct mu_gocs_pam *p = data;
-      if (p->service)
-        {
-          if ((mu_pam_service = strdup (p->service)) == NULL)
-            return ENOMEM;
-        }
-      else
-        mu_pam_service = NULL;
-    }
-  return 0;
-}
-
 struct mu_auth_module mu_auth_pam_module = {
-  "pam",
-  mu_pam_module_init,
-  mu_authenticate_pam,
-  NULL,
-  mu_auth_nosupport,
-  NULL,
-  mu_auth_nosupport,
-  NULL
+  .name = "pam",
+  .handler = { [mu_auth_authenticate] = mu_authenticate_pam },
+  .cfg = mu_pam_param
 };
 
diff --git a/libmu_auth/radius.c b/libmu_auth/radius.c
index f6e7e28..4d6c380 100644
--- a/libmu_auth/radius.c
+++ b/libmu_auth/radius.c
@@ -42,6 +42,9 @@
 #include <mailutils/nls.h>
 #include <mailutils/io.h>
 #include <mailutils/cctype.h>
+#include <mailutils/cli.h>
+#include <mailutils/stream.h>
+#include <mailutils/stdstream.h>
 
 #ifdef ENABLE_RADIUS
 
@@ -62,7 +65,6 @@ static grad_avp_t *auth_request;
 static grad_avp_t *getpwnam_request;
 static grad_avp_t *getpwuid_request;
 
-
 int
 get_attribute (int *pattr, char *name)
 {
@@ -84,30 +86,41 @@ enum parse_state
     state_delim
   };
 
-int
-parse_pairlist (grad_avp_t **plist, char *input)
+static int
+cb_request (void *data, mu_config_value_t *val)
 {
+  grad_avp_t **plist = data;
   size_t i;
   struct mu_wordsplit ws;
   enum parse_state state;
   grad_locus_t loc;
   char *name;
-  char *op; /* FIXME: It is actually ignored. Should it be? */
-
-  if (!input)
+  struct mu_locus locus;
+  
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
     return 1;
 
   ws.ws_delim = ",";
-  if (mu_wordsplit (input, &ws,
+  if (mu_wordsplit (val->v.string, &ws,
 		    MU_WRDSF_DEFFLAGS|MU_WRDSF_DELIM|MU_WRDSF_RETURN_DELIMS))
     {
-      mu_error (_("cannot parse input `%s': %s"), input,
+      mu_error (_("cannot parse input `%s': %s"), val->v.string,
 		mu_wordsplit_strerror (&ws));
       return 1;
     }
 
-  loc.file = "<configuration>"; /*FIXME*/
-  loc.line = 0;
+  if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, 
+		       MU_IOCTL_LOGSTREAM_GET_LOCUS,
+		       &locus) == 0)
+    {
+      loc.file = locus.mu_file;
+      loc.line = locus.mu_line;
+    }
+  else
+    {
+      loc.file = "<unknown>";
+      loc.line = 0;
+    }
 
   for (i = 0, state = state_lhs; i < ws.ws_wordc; i++)
     {
@@ -121,7 +134,7 @@ parse_pairlist (grad_avp_t **plist, char *input)
 	  break;
 
 	case state_op:
-	  op = ws.ws_wordv[i];
+	  //op = ws.ws_wordv[i];
 	  state = state_rhs;
 	  break;
 
@@ -155,16 +168,45 @@ parse_pairlist (grad_avp_t **plist, char *input)
       return 1;
     }
 
+  return 0;  
+}
+
+static int
+cb_config_dir (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  grad_config_dir = grad_estrdup (val->v.string);
   return 0;
 }
 
+static struct mu_cfg_param mu_radius_param[] = {
+  { "auth", mu_cfg_callback, &auth_request, 0, cb_request,
+    N_("Radius request for authorization."),
+    N_("request: string") },
+  { "getpwnam", mu_cfg_callback, &getpwnam_request, 0, cb_request,
+    N_("Radius request for getpwnam."),
+    N_("request: string") },
+  { "getpwuid", mu_cfg_callback, &getpwuid_request, 0, cb_request,
+    N_("Radius request for getpwuid."),
+    N_("request: string") },
+  { "directory", mu_cfg_callback, NULL, 0, cb_config_dir,
+    N_("Set radius configuration directory.") },
+  { NULL }
+};
+
+struct mu_cli_capa mu_cli_capa_radius = {
+  "radius",
+  NULL,
+  mu_radius_param
+};
+
 /* Assume radius support is needed if any of the above requests is
    defined. Actually, all of them should be, but it is the responsibility
    of init to check for consistency of the configuration */
 
-#define NEED_RADIUS_P(cfg) \
-  ((cfg) && \
-   ((cfg)->auth_request || (cfg)->getpwnam_request || (cfg)->getpwuid_request))
+#define NEED_RADIUS_P() \
+  (auth_request || getpwnam_request || getpwuid_request)
 
 static void
 mu_grad_logger(int level,
@@ -196,21 +238,16 @@ mu_grad_logger(int level,
     }
   mu_diag_voutput (mlevel[level & GRAD_LOG_PRIMASK], pfx ? pfx : fmt, ap);
   if (pfx)
-    free(pfx);
+    free (pfx);
 }
 
-int
-mu_radius_module_init (enum mu_gocs_op op, void *data)
+static void
+module_init (void *ptr)
 {
-  struct mu_radius_module_data *cfg = data;
-
-  if (op != mu_gocs_op_set)
-    return 0;
-  if (!NEED_RADIUS_P (cfg))
-    return 0;
+  if (!NEED_RADIUS_P ())
+    return;
 
   grad_set_logger (mu_grad_logger);
-  grad_config_dir = grad_estrdup (cfg->config_dir);
 
   grad_path_init ();
   srand (time (NULL) + getpid ());
@@ -218,7 +255,7 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
   if (grad_dict_init ())
     {
       mu_error (_("cannot read radius dictionaries"));
-      return 1;
+      return;
     }
 
   /* Check whether mailutils attributes are defined */
@@ -229,16 +266,9 @@ mu_radius_module_init (enum mu_gocs_op op, void *data)
       || get_attribute (&MU_Dir, "MU-Dir")
       || get_attribute (&MU_Shell, "MU-Shell")
       || get_attribute (&MU_Mailbox, "MU-Mailbox"))
-    return 1;
-
-  /* Parse saved requests */
-  if (parse_pairlist (&auth_request, cfg->auth_request)
-      || parse_pairlist (&getpwnam_request, cfg->getpwnam_request)
-      || parse_pairlist (&getpwuid_request, cfg->getpwuid_request))
-    return 1;
+    return;
 
   radius_auth_enabled = 1;
-  return 0;
 }
 
 static char *
@@ -518,44 +548,19 @@ mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
   return rc;
 }
 
-#else
-static int
-mu_radius_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
-			const void *key,
-			void *func_data MU_ARG_UNUSED, void *call_data)
-{
-  return ENOSYS;
-}
-
-static int
-mu_auth_radius_user_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
-			     const void *key MU_ARG_UNUSED,
-			     void *func_data MU_ARG_UNUSED,
-			     void *call_data MU_ARG_UNUSED)
-{
-  return ENOSYS;
-}
-
-static int
-mu_auth_radius_user_by_uid (struct mu_auth_data **return_data,
-			    const void *key,
-			    void *func_data, void *call_data)
-{
-  return ENOSYS;
-}
-#endif
-
 struct mu_auth_module mu_auth_radius_module = {
-  "radius",
-#ifdef ENABLE_RADIUS
-  mu_radius_module_init,
+  .name = "radius",
+  .cfg  = mu_radius_param,
+  .commit = module_init,
+  .handler = {
+    [mu_auth_authenticate] = mu_radius_authenticate,
+    [mu_auth_getpwnam] = mu_auth_radius_user_by_name,
+    [mu_auth_getpwuid] = mu_auth_radius_user_by_uid
+  }
+};
 #else
-  NULL,
-#endif
-  mu_radius_authenticate,
-  NULL,
-  mu_auth_radius_user_by_name,
-  NULL,
-  mu_auth_radius_user_by_uid,
-  NULL
+struct mu_auth_module mu_auth_radius_module = {
+  .name = "radius"
 };
+#endif
+
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index f84d9b0..eeb3e3f 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -50,12 +50,97 @@
 #include <mailutils/sql.h>
 #include <mailutils/cstr.h>
 #include <mailutils/wordsplit.h>
+#include <mailutils/cli.h>
 #include "sql.h"
 
 #ifdef USE_SQL
 
-struct mu_internal_sql_config mu_sql_module_config;
+struct mu_sql_module_config mu_sql_module_config;
+/* Resource file configuration */
+static int
+cb_password_type (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  
+  if (mu_sql_decode_password_type (val->v.string, &mu_sql_module_config.password_type))
+    mu_error (_("unknown password type `%s'"), val->v.string);
+  return 0;
+}
+
+static int
+_cb2_field_map (const char *arg, void *data)
+{
+  int err;
+  int rc = mutil_parse_field_map (arg, &mu_sql_module_config.field_map, &err);
+  if (rc)
+    /* FIXME: this message may be misleading */
+    mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
+  return 0;
+}
 
+static int
+cb_field_map (void *data, mu_config_value_t *val)
+{
+  return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
+}
+
+static int
+cb_interface (void *data, mu_config_value_t *val)
+{
+  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
+    return 1;
+  mu_sql_module_config.interface = mu_sql_interface_index (val->v.string);
+  if (mu_sql_module_config.interface == 0)
+    {
+      mu_error (_("unknown SQL interface `%s'"), val->v.string);
+      return 1;
+    }
+  return 0;
+}
+  
+static struct mu_cfg_param mu_sql_param[] = {
+  { "interface", mu_cfg_callback, &mu_sql_module_config.interface, 0,
+    cb_interface,
+    N_("Set SQL interface to use."),
+    N_("iface: mysql|odbc|postgres") },
+  { "getpwnam", mu_c_string, &mu_sql_module_config.getpwnam_query, 0, NULL,
+    N_("SQL query to use for getpwnam requests."),
+    N_("query") },
+  { "getpwuid", mu_c_string, &mu_sql_module_config.getpwuid_query, 0, NULL,
+    N_("SQL query to use for getpwuid requests."),
+    N_("query") },
+  { "getpass", mu_c_string, &mu_sql_module_config.getpass_query, 0, NULL,
+    N_("SQL query returning the user's password."),
+    N_("query") },
+  { "host", mu_c_string, &mu_sql_module_config.host, 0, NULL,
+    N_("SQL server host name.") },
+  { "user", mu_c_string, &mu_sql_module_config.user, 0, NULL,
+    N_("SQL user name.") },
+  { "passwd", mu_c_string, &mu_sql_module_config.passwd, 0, NULL,
+    N_("Password for the SQL user.") },
+  { "port", mu_c_int, &mu_sql_module_config.port, 0, NULL,
+    N_("SQL server port.") },
+  { "db", mu_c_string, &mu_sql_module_config.db, 0, NULL,
+    N_("Database name.") },
+  { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
+    N_("Type of password returned by getpass query (one of: plain, hash, "
+       "scrambled).") },
+  { "positional", mu_c_bool, &mu_sql_module_config.positional, 0, NULL,
+    N_("Use positional (v1.0 compatible) field interface.") },
+  { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
+    N_("Set a field-map for parsing SQL replies.  The map is a "
+       "column-separated list of definitions.  Each definition has the "
+       "following form:\n"
+       "   <name: string>=<column: string>\n"
+       "where <name> is one of the following: name, passwd, uid, gid, "
+       "gecos, dir, shell, mailbox, quota, and <column> is the name of "
+       "the corresponding SQL column."),
+    N_("map") },
+  { NULL }
+};
+
+
 static char *
 sql_escape_string (const char *ustr)
 {
@@ -668,55 +753,22 @@ mu_sql_authenticate (struct mu_auth_data **return_data MU_ARG_UNUSED,
   return rc == 0 ? 0 : MU_ERR_AUTH_FAILURE;
 }
 
-int
-mu_sql_module_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_sql_module_config *cfg = data;
-
-  if (op != mu_gocs_op_set)
-    return 0;
-  mu_sql_module_config.interface = mu_sql_interface_index (cfg->interface);
-  if (mu_sql_module_config.interface == 0)
-    {
-      mu_error (_("unknown SQL interface `%s'"), cfg->interface);
-      return 1;
-    }
-
-  mu_sql_module_config.getpwnam_query = cfg->getpwnam_query;   
-  mu_sql_module_config.getpass_query  = cfg->getpass_query;    
-  mu_sql_module_config.getpwuid_query = cfg->getpwuid_query;   
-  mu_sql_module_config.host = cfg->host;             
-  mu_sql_module_config.user = cfg->user;             
-  mu_sql_module_config.passwd = cfg->passwd;           
-  mu_sql_module_config.db = cfg->db;               
-  mu_sql_module_config.port = cfg->port;             
-  mu_sql_module_config.password_type = cfg->password_type;    
-  mu_sql_module_config.field_map = cfg->field_map;        
-
-  return 0;
-}
-
 #else
 
 # define mu_sql_authenticate mu_auth_nosupport
 # define mu_auth_sql_by_name mu_auth_nosupport
 # define mu_auth_sql_by_uid mu_auth_nosupport
-
+# define mu_sql_param NULL
 #endif
 
 
 struct mu_auth_module mu_auth_sql_module = {
-  "sql",
-#ifdef USE_SQL
-  mu_sql_module_init,
-#else
-  NULL,
-#endif
-  mu_sql_authenticate,
-  NULL,
-  mu_auth_sql_by_name,
-  NULL,
-  mu_auth_sql_by_uid,
-  NULL
+  .name = "sql",
+  .cfg = mu_sql_param,
+  .handler = {
+    [mu_auth_authenticate] = mu_sql_authenticate,
+    [mu_auth_getpwnam]     = mu_auth_sql_by_name,
+    [mu_auth_getpwuid]     = mu_auth_sql_by_uid
+  }
 };
 
diff --git a/libmu_auth/tls.c b/libmu_auth/tls.c
index 89e3b52..656ff2c 100644
--- a/libmu_auth/tls.c
+++ b/libmu_auth/tls.c
@@ -64,22 +64,6 @@ struct mu_tls_module_config mu_tls_module_config = {
   0
 #endif
 };
-//FIXME: REMOVE  
-int
-mu_tls_module_init (enum mu_gocs_op op, void *data)
-{
-  switch (op)
-    {
-    case mu_gocs_op_set:
-      if (data)
-	memcpy (&mu_tls_module_config, data, sizeof mu_tls_module_config);
-      break;
-      
-    case mu_gocs_op_flush:
-      break;
-    }
-  return 0;
-}
 
 #ifdef WITH_TLS
 
@@ -870,16 +854,14 @@ static struct mu_cfg_param mu_tls_param[] = {
   { NULL }
 }; 
 
-struct mu_cli_capa mu_cli_capa_tls = {
-  "tls",
-  NULL,
-  mu_tls_param,
-  NULL, NULL
+struct mu_auth_module mu_auth_tls_module = {
+  .name = "tls",
+  .cfg = mu_tls_param
 };
+
 #else
-struct mu_cli_capa mu_cli_capa_tls = {
-  "tls",
-  NULL
+struct mu_auth_module mu_auth_tls_module = {
+  .name = "tls"
 };
 #endif /* WITH_TLS */
 
diff --git a/libmu_auth/virtual.c b/libmu_auth/virtual.c
index b97a96b..171b893 100644
--- a/libmu_auth/virtual.c
+++ b/libmu_auth/virtual.c
@@ -53,22 +53,20 @@
 #include <mailutils/nls.h>
 #include <mailutils/errno.h>
 #include <mailutils/util.h>
+#include <mailutils/cli.h>
 
 #ifdef ENABLE_VIRTUAL_DOMAINS
 
-struct mu_gocs_virtual mu_virtual_module_config = { SITE_VIRTUAL_PWDDIR };
-
-int
-mu_virtual_module_init (enum mu_gocs_op op, void *data)
-{
-  if (op == mu_gocs_op_set && data)
-    {
-      struct mu_gocs_virtual *p = data;
-      mu_virtual_module_config = *p;
-    }
-  return 0;
-}
+static char *pwddir = { SITE_VIRTUAL_PWDDIR };
 
+static struct mu_cfg_param mu_virtdomain_param[] = {
+  { "passwd-dir", mu_c_string, &pwddir, 0, NULL,
+    N_("Name of the directory where virtual domain password files are "
+       "located."),
+    N_("dir") },
+  { NULL }
+};
+
 #if !HAVE_FGETPWENT
 /* FIXME: A temporary solution. Need proper declaration in .h */
 extern struct passwd *mu_fgetpwent (FILE *fp);
@@ -90,7 +88,7 @@ getpwnam_virtual (const char *u)
   if (delim == 0)
     return NULL;
 
-  filename = mu_make_file_name (mu_virtual_module_config.pwddir, &u[delim + 1]);
+  filename = mu_make_file_name (pwddir, &u[delim + 1]);
   if (filename == NULL)
     return NULL;
 
@@ -191,28 +189,15 @@ mu_auth_virt_domain_by_name (struct mu_auth_data **return_data,
 }
 
 #else
-static int
-mu_auth_virt_domain_by_name (struct mu_auth_data **return_data MU_ARG_UNUSED,
-			     const void *key MU_ARG_UNUSED,
-			     void *func_data MU_ARG_UNUSED,
-			     void *call_data MU_ARG_UNUSED)
-{
-  return ENOSYS;
-}
+# define mu_virtdomain_param NULL
+# define mu_auth_virt_domain_by_name NULL
 #endif
 
 struct mu_auth_module mu_auth_virtual_module = {
-  "virtdomain",
-#ifdef ENABLE_VIRTUAL_DOMAINS
-  mu_virtual_module_init,
-#else
-  NULL,
-#endif
-  mu_auth_nosupport,
-  NULL,
-  mu_auth_virt_domain_by_name,
-  NULL,
-  mu_auth_nosupport,
-  NULL
+  .name = "virtdomain",
+  .cfg = mu_virtdomain_param,
+  .handler = {
+    [mu_auth_getpwnam] = mu_auth_virt_domain_by_name,
+  }
 };
     
diff --git a/libmu_cfg/.gitignore b/libmu_cfg/.gitignore
deleted file mode 100644
index 2248e8c..0000000
--- a/libmu_cfg/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-*.la
-*.lo
-.deps
-.libs
-Makefile
-Makefile.in
-.gdbinit
diff --git a/libmu_cfg/Makefile.am b/libmu_cfg/Makefile.am
deleted file mode 100644
index 800cf37..0000000
--- a/libmu_cfg/Makefile.am
+++ /dev/null
@@ -1,38 +0,0 @@
-# This file is part of GNU Mailutils
-# Copyright (C) 2007, 2009-2012, 2014-2016 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/>.
-
-AM_CPPFLAGS = \
- @MU_LIB_COMMON_INCLUDES@\
- -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\" \
- -DSITE_CRAM_MD5_PWD=\"@SITE_CRAM_MD5_PWD@\"
-
-lib_LTLIBRARIES = libmu_cfg.la
-libmu_cfg_la_SOURCES=\
- acl.c\
- auth.c\
- common.c\
- init.c\
- gsasl.c\
- ldap.c\
- pam.c\
- radius.c\
- sieve.c\
- sql.c\
- tls.c\
- virtdomain.c
-
-libmu_cfg_la_LDFLAGS=-version-info @VI_CURRENT@:@VI_REVISION@:@VI_AGE@
diff --git a/libmu_cfg/acl.c b/libmu_cfg/acl.c
deleted file mode 100644
index b4bfded..0000000
--- a/libmu_cfg/acl.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "mailutils/libcfg.h"
-#include "mailutils/acl.h"
-#include "mailutils/argcv.h"
-#include "mailutils/cidr.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#define ISSPACE(c) ((c)==' '||(c)=='\t')
-
-#define SKIPWS(p) while (*(p) && ISSPACE (*(p))) (p)++;
-
-static const char *
-getword (mu_config_value_t *val, int *pn)
-{
-  int n = (*pn)++;
-  mu_config_value_t *v;
-
-  if (n >= val->v.arg.c)
-    {
-      mu_error (_("not enough arguments"));
-      return NULL;
-    }
-  v = &val->v.arg.v[n];
-  if (mu_cfg_assert_value_type (v, MU_CFG_STRING))
-    return NULL;
-  return v->v.string;
-}
-
-static int
-parsearg (mu_config_value_t *val, struct mu_cidr *cidr, char **prest) 
-{
-  const char *w;
-  int n = 0;
-  int rc;
-  
-  if (mu_cfg_assert_value_type (val, MU_CFG_ARRAY))
-    return 1;
-  
-  w = getword (val, &n);
-  if (!w)
-    return 1;
-  if (strcmp (w, "from") == 0) {
-    w = getword (val, &n);
-    if (!w)
-      return 1;
-  }
-
-  if (strcmp (w, "any") == 0)
-    cidr->len = 0;
-  else
-    {
-      rc = mu_cidr_from_string (cidr, w);
-      if (rc)
-	{
-	  mu_error (_("invalid source CIDR: %s"), mu_strerror (rc));
-	  return 1;
-	}
-    }
-  
-  if (prest)
-    {
-      if (n == val->v.arg.c)
-	*prest = NULL;
-      else
-	{
-	  size_t size = 0;
-	  int i;
-	  char *buf;
-	  
-	  for (i = n; i < val->v.arg.c; i++)
-	    {
-	      if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
-		return 1;
-	      size += strlen (val->v.arg.v[i].v.string) + 1;
-	    }
-
-	  buf = malloc (size);
-	  if (!buf)
-	    {
-	      mu_error ("%s", mu_strerror (errno));
-	      return 1;
-	    }	    
-
-	  *prest = buf;
-	  for (i = n; i < val->v.arg.c; i++)
-	    {
-	      if (i > n)
-		*buf++ = ' ';
-	      strcpy (buf, val->v.arg.v[i].v.string);
-	      buf += strlen (buf);
-	    }
-	  *buf = 0;
-	}
-    }
-  else if (n != val->v.arg.c)
-    {
-      mu_error (_("junk after IP address"));
-      return 1;
-    }
-  return 0;
-}
-
-static int
-cb_allow (void *data, mu_config_value_t *val)
-{
-  int rc;
-  mu_acl_t acl = *(mu_acl_t*)data;
-  struct mu_cidr cidr;
-  
-  if (parsearg (val, &cidr, NULL))
-    return 1;
-  rc = mu_acl_append (acl, mu_acl_accept, NULL, &cidr);
-  if (rc)
-    mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
-  return rc;
-}
-
-static int
-cb_deny (void *data, mu_config_value_t *val)
-{
-  int rc;
-  mu_acl_t acl = *(mu_acl_t*)data;
-  struct mu_cidr cidr;
-  
-  if (parsearg (val, &cidr, NULL))
-    return 1;
-  rc = mu_acl_append (acl, mu_acl_deny, NULL, &cidr);
-  if (rc)
-    mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
-  return rc;
-}
-
-static int
-cb_log (void *data, mu_config_value_t *val)
-{
-  int rc;
-  mu_acl_t acl = *(mu_acl_t*)data;
-  struct mu_cidr cidr;
-  char *rest;
-  
-  if (parsearg (val, &cidr, &rest))
-    return 1;
-  rc = mu_acl_append (acl, mu_acl_log, rest, &cidr);
-  if (rc)
-    mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
-  return rc;
-}
-
-static int
-cb_exec (void *data, mu_config_value_t *val)
-{
-  int rc;
-  mu_acl_t acl = *(mu_acl_t*)data;
-  struct mu_cidr cidr;
-  char *rest;
-  
-  if (parsearg (val, &cidr, &rest))
-    return 1;
-  rc = mu_acl_append (acl, mu_acl_exec, rest, &cidr);
-  if (rc)
-    mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
-  return rc;
-}
-
-static int
-cb_ifexec (void *data, mu_config_value_t *val)
-{
-  int rc;
-  mu_acl_t acl = *(mu_acl_t*)data;
-  struct mu_cidr cidr;
-  char *rest;
-  
-  if (parsearg (val, &cidr, &rest))
-    return 1;
-  rc = mu_acl_append (acl, mu_acl_ifexec, rest, &cidr);
-  if (rc)
-    mu_error (_("cannot append acl entry: %s"), mu_strerror (rc));
-  return rc;
-}
-
-static struct mu_cfg_param acl_param[] = {
-  { "allow", mu_cfg_callback, NULL, 0, cb_allow,
-    N_("Allow connections from this IP address. Optional word `from' is "
-       "allowed between it and its argument. The same holds true for other "
-       "actions below."),
-    N_("addr: IP") },
-  { "deny", mu_cfg_callback, NULL, 0, cb_deny,
-    N_("Deny connections from this IP address."),
-    N_("addr: IP") },
-  { "log", mu_cfg_callback, NULL, 0, cb_log,
-    N_("Log connections from this IP address."),
-    N_("addr: IP") },
-  { "exec", mu_cfg_callback, NULL, 0, cb_exec,
-    N_("Execute supplied program if a connection from this IP address is "
-       "requested. Arguments are:\n"
-       "  <addr: IP> <program: string>\n"
-       "Following macros are expanded in <program> before executing:\n"
-       "  address  -  Source IP address\n"
-       "  port     -  Source port number\n") },
-  { "ifexec", mu_cfg_callback, NULL, 0, cb_ifexec,
-    N_("If a connection from this IP address is requested, execute supplied "
-       "program and allow or deny the connection depending on its exit code. "
-       "See `exec' for a description of its arguments.") },
-  { NULL }
-};
-
-static int
-acl_section_parser (enum mu_cfg_section_stage stage,
-		    const mu_cfg_node_t *node,
-		    const char *section_label, void **section_data,
-		    void *call_data,
-		    mu_cfg_tree_t *tree)
-{
-  switch (stage)
-    {
-    case mu_cfg_section_start:
-      {
-	void *data = *section_data;
-	mu_acl_create ((mu_acl_t*)data);
-      }
-      break;
-      
-    case mu_cfg_section_end:
-      break;
-    }
-  return 0;
-}
-
-void
-mu_acl_cfg_init ()
-{
-  struct mu_cfg_section *section;
-  if (mu_create_canned_section ("acl", &section) == 0)
-    {
-      section->parser = acl_section_parser;
-      mu_cfg_section_add_params (section, acl_param);
-    }
-}
diff --git a/libmu_cfg/auth.c b/libmu_cfg/auth.c
deleted file mode 100644
index 98aa772..0000000
--- a/libmu_cfg/auth.c
+++ /dev/null
@@ -1,131 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
-   Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include "mailutils/libcfg.h"
-#include <mailutils/mu_auth.h>
-#include <string.h>
-
-/* FIXME: mu_auth.c should be reviewed */
-
-
-/* ************************************************************************* */
-/* Resource-style configuration                                              */
-/* ************************************************************************* */
-static int
-cb_authentication (void *data, mu_config_value_t *val)
-{
-  if (val->type == MU_CFG_STRING)
-    {
-      if (strcmp (val->v.string, "clear") == 0)
-	mu_authentication_clear_list ();
-      else
-	/*FIXME: use err for error reporting*/
-	mu_authentication_add_module_list (val->v.string);
-    }
-  else if (val->type == MU_CFG_LIST)
-    {
-      int i;
-      for (i = 0; i < val->v.arg.c; i++)
-	{
-	  if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
-	    return 1;
-	  if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
-	    mu_authentication_clear_list ();
-	  else
-	    mu_authentication_add_module (val->v.arg.v[i].v.string);
-	}
-    }
-  else
-    {
-      mu_error (_("expected string value"));
-      return 1;
-    }
-  return 0;
-}
-
-static int
-cb_authorization (void *data, mu_config_value_t *val)
-{
-  if (val->type == MU_CFG_STRING)
-    {
-      if (strcmp (val->v.string, "clear") == 0)
-	mu_authorization_clear_list ();
-      else
-	/*FIXME: use err for error reporting*/
-	mu_authorization_add_module_list (val->v.string);
-    }
-  else if (val->type == MU_CFG_LIST)
-    {
-      int i;
-      for (i = 0; i < val->v.arg.c; i++)
-	{
-	  if (mu_cfg_assert_value_type (&val->v.arg.v[i], MU_CFG_STRING))
-	    return 1;
-	  if (strcmp (val->v.arg.v[i].v.string, "clear") == 0)
-	    mu_authorization_clear_list ();
-	  else
-	    mu_authorization_add_module (val->v.arg.v[i].v.string);
-	}
-    }
-  else
-    {
-      mu_error (_("expected string value"));
-      return 1;
-    }
-  return 0;
-}
-
-static struct mu_cfg_param mu_auth_param[] = {
-  { "authentication", mu_cfg_callback, NULL, 0, cb_authentication,
-    /* FIXME: The description is incomplete. MU-list is also allowed as
-       argument */
-    N_("Set a list of modules for authentication. Modlist is a "
-       "colon-separated list of module names or a word `clear' to "
-       "clear the previously set up values."),
-    N_("modlist") },
-  { "authorization", mu_cfg_callback, NULL, 0, cb_authorization,
-    N_("Set a list of modules for authorization. Modlist is a "
-       "colon-separated list of module names or a word `clear' to "
-       "clear the previously set up values."),
-    N_("modlist") },
-  { NULL }
-};
-
-int
-mu_auth_section_parser
-   (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,
-    const char *section_label, void **section_data, void *call_data,
-    mu_cfg_tree_t *tree)
-{
-  switch (stage)
-    {
-    case mu_cfg_section_start:
-      break;
-
-    case mu_cfg_section_end:
-      mu_auth_finish_setup ();
-    }
-  return 0;
-}
-
-struct mu_cfg_capa mu_auth_cfg_capa = {
-  "auth",  mu_auth_param, mu_auth_section_parser
-};
diff --git a/libmu_cfg/common.c b/libmu_cfg/common.c
deleted file mode 100644
index 1684b7f..0000000
--- a/libmu_cfg/common.c
+++ /dev/null
@@ -1,213 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include "mailutils/libcfg.h"
-#include <mailutils/debug.h>
-#include <mailutils/syslog.h>
-#include <mailutils/mailbox.h>
-#include <mailutils/io.h>
-#include <mailutils/stream.h>
-#include <mailutils/stdstream.h>
-
-static struct mu_gocs_locking locking_settings;
-static struct mu_gocs_mailbox mailbox_settings;
-static struct mu_gocs_source_email address_settings;
-static struct mu_gocs_mailer mailer_settings;
-static struct mu_gocs_debug debug_settings;
-
-
-/* ************************************************************************* */
-/* Mailbox                                                                   */
-/* ************************************************************************* */
-
-static int
-_cb_folder (void *data, mu_config_value_t *val)
-{
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  mu_set_folder_directory (val->v.string);
-  return 0;
-}
-
-static struct mu_cfg_param mu_mailbox_param[] = {
-  { "mail-spool", mu_c_string, &mailbox_settings.mail_spool, 0, NULL,
-    N_("Use specified URL as a mailspool directory."),
-    N_("url") },
-  { "mailbox-pattern", mu_c_string, &mailbox_settings.mailbox_pattern,
-    0, NULL,
-    N_("Create mailbox URL using <pattern>."),
-    N_("pattern") },
-  { "mailbox-type", mu_c_string, &mailbox_settings.mailbox_type, 0, NULL,
-    N_("Default mailbox type."), N_("protocol") },
-  { "folder", mu_cfg_callback, NULL, 0, _cb_folder,
-    N_("Default user mail folder"),
-    N_("dir") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (mailbox);
-
-
-/* ************************************************************************* */
-/* Locking                                                                   */
-/* ************************************************************************* */
-
-static struct mu_cfg_param mu_locking_param[] = {
-  /* FIXME: Flags are superfluous. */
-  { "flags", mu_c_string, &locking_settings.lock_flags, 0, NULL,
-    N_("Default locker flags (E=external, R=retry, T=time, P=pid).") },
-  { "retry-timeout", mu_c_ulong, &locking_settings.lock_retry_timeout,
-    0, NULL,
-    N_("Set timeout for acquiring the lock.") },
-  { "retry-count", mu_c_ulong, &locking_settings.lock_retry_count, 0, NULL,
-    N_("Set the maximum number of times to retry acquiring the lock.") },
-  { "expire-timeout", mu_c_ulong, &locking_settings.lock_expire_timeout,
-    0, NULL,
-    N_("Expire locks older than this amount of time.") },
-  { "external-locker", mu_c_string, &locking_settings.external_locker, 
-    0, NULL,
-    N_("Use external locker program."),
-    N_("prog") },
-  { NULL, }
-};
-
-DCL_CFG_CAPA (locking);
-
-
-/* ************************************************************************* */
-/* Address                                                                   */
-/* ************************************************************************* */
-     
-static struct mu_cfg_param mu_address_param[] = {
-  { "email-addr", mu_c_string, &address_settings.address, 0, NULL,
-    N_("Set the current user email address (default is "
-       "loginname@defaultdomain)."),
-    N_("email") },
-  { "email-domain", mu_c_string, &address_settings.domain, 0, NULL,
-    N_("Set e-mail domain for unqualified user names (default is this host)"),
-    N_("domain") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (address);
-
-     
-/* ************************************************************************* */
-/* Mailer                                                                    */
-/* ************************************************************************* */
-     
-static struct mu_cfg_param mu_mailer_param[] = {
-  { "url", mu_c_string, &mailer_settings.mailer, 0, NULL,
-    N_("Use this URL as the default mailer"),
-    N_("url") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (mailer);
-
-
-/* ************************************************************************* */
-/* Logging                                                                   */
-/* ************************************************************************* */
-
-static int
-cb_facility (void *data, mu_config_value_t *val)
-{
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  
-  if (mu_string_to_syslog_facility (val->v.string, &mu_log_facility))
-    {
-      mu_error (_("unknown syslog facility `%s'"), val->v.string);
-      return 1;
-    }
-   return 0;
-}
-
-static int
-cb_severity (void *data, mu_config_value_t *val)
-{
-  unsigned n;
-  
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  if (mu_severity_from_string (val->v.string, &n))
-    {
-      mu_error (_("unknown severity `%s'"), val->v.string);
-      return 1;
-    }
-  mu_log_severity_threshold = n;
-  return 0;
-}      
-
-static struct mu_cfg_param mu_logging_param[] = {
-  { "syslog", mu_c_bool, &mu_log_syslog, 0, NULL,
-    N_("Send diagnostics to syslog.") },
-  { "print-severity", mu_c_bool, &mu_log_print_severity, 0, NULL,
-    N_("Print message severity levels.") },
-  { "severity", mu_cfg_callback, NULL, 0, cb_severity,
-    N_("Output only messages with a severity equal to or greater than "
-       "this one.") },
-  { "facility", mu_cfg_callback, NULL, 0, cb_facility,
-    N_("Set syslog facility. Arg is one of the following: user, daemon, "
-       "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
-       "or a facility number.") },
-  { "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
-    N_("Log session ID") },
-  { "tag", mu_c_string, &mu_log_tag, 0, NULL,
-    N_("Tag syslog messages with this string.") },
-  { NULL }
-};
-
-static int logging_settings; /* Dummy variable */
-DCL_CFG_CAPA (logging);
-
-
-/* ************************************************************************* */
-/* Debug                                                                     */
-/* ************************************************************************* */
-
-static int
-_cb2_debug_level (const char *arg, void *data MU_ARG_UNUSED)
-{
-  mu_debug_parse_spec (arg);
-  return 0;
-}
-
-static int
-cb_debug_level (void *data, mu_config_value_t *val)
-{
-  return mu_cfg_string_value_cb (val, _cb2_debug_level, NULL);
-}
-
-static struct mu_cfg_param mu_debug_param[] = {
-  { "level", mu_cfg_callback, NULL, 0, &cb_debug_level,
-    N_("Set Mailutils debugging level.  Argument is a colon-separated list "
-       "of debugging specifications in the form:\n"
-       "   <object: string>[[:]=<level: number>].") },
-  { "line-info", mu_c_bool, &debug_settings.line_info, 0, NULL,
-    N_("Prefix debug messages with Mailutils source locations.") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (debug);
-
diff --git a/libmu_cfg/gsasl.c b/libmu_cfg/gsasl.c
deleted file mode 100644
index 539f8b9..0000000
--- a/libmu_cfg/gsasl.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
-   Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-#include <mailutils/gsasl.h>
-
-static struct mu_gsasl_module_data gsasl_settings;
-
-static struct mu_cfg_param mu_gsasl_param[] = {
-  { "enable", mu_c_bool, &gsasl_settings.enable, 0, NULL,
-    N_("Enable GSASL (default)") },
-  { "cram-passwd", mu_c_string, &gsasl_settings.cram_md5_pwd, 0, NULL,
-    N_("Name of GSASL password file."),
-    N_("file") },
-  { "service", mu_c_string, &gsasl_settings.service, 0, NULL,
-    N_("SASL service name."),
-    N_("name") },
-  { "realm", mu_c_string, &gsasl_settings.realm, 0, NULL,
-    N_("SASL realm name."),
-    N_("name") },
-  { "hostname", mu_c_string, &gsasl_settings.hostname, 0, NULL,
-    N_("SASL host name."),
-    N_("name") },
-  { "anonymous-user", mu_c_string, &gsasl_settings.anon_user, 0, NULL,
-    N_("Anonymous user name."),
-    N_("name") },
-
-  { NULL }
-};
-
-DCL_CFG_CAPA (gsasl);
-     
-     
diff --git a/libmu_cfg/init.c b/libmu_cfg/init.c
deleted file mode 100644
index 5d28567..0000000
--- a/libmu_cfg/init.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2012, 2014-2016 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
-#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
-#include "mailutils/libcfg.h"
-#include <string.h>
-#include <stdlib.h>
-
-#define CFG_CAPA_MAX 512
-static struct mu_cfg_capa *cfg_capa_table[CFG_CAPA_MAX] = {
-#define S(c) &__mu_common_cat3__(mu_,c,_cfg_capa)
-  S (auth),
-  S (mailbox),
-  S (locking),
-  S (address),
-  S (mailer),
-  S (logging),
-  S (gsasl),
-  S (pam),
-  S (radius),
-  S (sql),
-  S (tls),
-  S (virtdomain),
-  S (sieve),
-  S (ldap),
-  S (debug),
-  NULL
-};
-
-static int cfg_capa_index = MU_ARRAY_SIZE(cfg_capa_table) - 1;
-
-static struct mu_cfg_capa *
-find_cfg_capa (const char *name)
-{
-  int i;
-
-  for (i = 0; cfg_capa_table[i]; i++)
-    if (strcmp (cfg_capa_table[i]->name, name) == 0)
-      return cfg_capa_table[i];
-  return NULL;
-}
-
-static int
-reserved_name (const char *name)
-{
-  static char *reserved[] = { "common", NULL };
-  char **p;
-
-  if (name[0] == '.')
-    return 1;
-  
-  for (p = reserved; *p; p++)
-    if (strcmp (name, *p) == 0)
-      return 1;
-  return 0;
-}
-
-int
-mu_libcfg_register_capa (struct mu_cfg_capa *capa)
-{
-  if (cfg_capa_index == CFG_CAPA_MAX)
-    return MU_ERR_NOENT;
-  cfg_capa_table[cfg_capa_index++] = capa;
-  return 0;
-}
-
-void
-mu_libcfg_init (char **cnames)
-{
-  int i;
-  for (i = 0; cnames[i]; i++)
-    {
-      if (!reserved_name (cnames[i]))
-	{
-	  struct mu_cfg_capa *cp = find_cfg_capa (cnames[i]);
-	  if (cp)
-	    mu_config_root_register_section (NULL, cp->name, NULL,
-					     cp->parser, cp->cfgparam);
-#if 0
-	  else
-	    mu_error (_("unknown configuration group requested `%s'"),
-		      cnames[i]);
-#endif
-	}
-    }
-}
-
-int
-mu_libcfg_parse_config (mu_cfg_tree_t **ptree)
-{
-  struct mu_cfg_parse_hints hints;
-
-  memset (&hints, 0, sizeof (hints));
-  
-  if (mu_cfg_parser_verbose)
-    hints.flags |= MU_PARSE_CONFIG_VERBOSE;
-  if (mu_cfg_parser_verbose > 1)
-    hints.flags |= MU_PARSE_CONFIG_DUMP;
-  
-  if (mu_load_site_rcfile)
-    {
-      hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
-      hints.site_rcfile = mu_site_rcfile;
-    }
-  
-  if (mu_load_user_rcfile && mu_program_name)
-    {
-      hints.flags |= MU_CFG_PARSE_PROGRAM;
-      hints.program = (char*) mu_program_name;
-    }
-  
-  if (mu_load_rcfile)
-    {
-      hints.flags |= MU_CFG_PARSE_CUSTOM_RCFILE;
-      hints.custom_rcfile = mu_load_rcfile;
-    }
-
-  return mu_cfg_parse_config (ptree, &hints);
-}
-
-
-
-/* FIXME: Deprecated */
-int
-mu_parse_config_files (struct mu_cfg_param *param, void *target)
-{
-  int flags = 0;
-  int rc;
-  
-  if (mu_cfg_parser_verbose)
-    flags |= MU_PARSE_CONFIG_VERBOSE;
-  if (mu_cfg_parser_verbose > 1)
-    flags |= MU_PARSE_CONFIG_DUMP;
-  
-  if (mu_load_site_rcfile)
-    {
-      rc = mu_parse_config (mu_site_rcfile, mu_program_name, param,
-			    flags | MU_PARSE_CONFIG_GLOBAL, target);
-      if (rc == ENOMEM)
-	{
-	  mu_error ("%s", mu_strerror (rc));
-	  return rc;
-	}
-    }
-
-  if (mu_load_user_rcfile && mu_program_name)
-    {
-      size_t size = 3 + strlen (mu_program_name) + 1;
-      char *file_name = malloc (size);
-      if (file_name)
-	{
-	  strcpy (file_name, "~/.");
-	  strcat (file_name, mu_program_name);
-
-	  rc = mu_parse_config (file_name, mu_program_name, param, flags,
-				target);
-	  if (rc == ENOMEM)
-	    {
-	      mu_error ("%s", mu_strerror (rc));
-	      return rc;
-	    }
-
-	  free (file_name);
-	}
-    }
-
-  if (mu_load_rcfile)
-    {
-      rc = mu_parse_config (mu_load_rcfile, mu_program_name, param,
-			    flags, target);
-      if (rc)
-	{
-	  mu_error (_("errors parsing file %s: %s"), mu_load_rcfile,
-		    mu_strerror (rc));
-	  return rc;
-	}
-    }
-	
-  return 0;
-}
diff --git a/libmu_cfg/ldap.c b/libmu_cfg/ldap.c
deleted file mode 100644
index ec47165..0000000
--- a/libmu_cfg/ldap.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-#include "mailutils/util.h"
-#include "mailutils/ldap.h"
-
-static struct mu_ldap_module_config ldap_settings;
-
-static int
-_cb2_field_map (const char *arg, void *data)
-{
-  int err;
-  int rc = mutil_parse_field_map (arg, &ldap_settings.field_map, &err);
-  if (rc)
-    /* FIXME: this message can be misleading */
-    mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
-  return 0;
-}
-
-static int
-cb_field_map (void *data, mu_config_value_t *val)
-{
-  return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
-}
-
-static struct mu_cfg_param mu_ldap_param[] = {
-  { "enable", mu_c_bool, &ldap_settings.enable, 0, NULL,
-    N_("Enable LDAP lookups.") },
-  { "url", mu_c_string, &ldap_settings.url, 0, NULL,
-    N_("Set URL of the LDAP server."),
-    N_("url") },
-  { "base", mu_c_string, &ldap_settings.base, 0, NULL,
-    N_("Base DN for LDAP lookups."),
-    N_("dn") },
-  { "binddn", mu_c_string, &ldap_settings.binddn, 0, NULL,
-    N_("DN for accessing LDAP database."),
-    N_("dn") },
-  { "passwd", mu_c_string, &ldap_settings.passwd, 0, NULL,
-    N_("Password for use with binddn.") },
-  { "tls", mu_c_bool, &ldap_settings.tls, 0, NULL,
-    N_("Use TLS encryption.") },
-  { "debug", mu_c_int, &ldap_settings.debug, 0, NULL,
-    N_("Set LDAP debugging level.") },
-  { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
-    N_("Set a field-map for parsing LDAP replies.  The map is a "
-       "column-separated list of definitions.  Each definition has the "
-       "following form:\n"
-       "   <name: string>=<attr: string>\n"
-       "where <name> is one of the following: name, passwd, uid, gid, "
-       "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
-       "the corresponding LDAP attribute."),
-    N_("map") },
-  { "getpwnam", mu_c_string, &ldap_settings.getpwnam_filter, 0, NULL,
-    N_("LDAP filter to use for getpwnam requests."),
-    N_("filter") },
-  { "getpwuid", mu_c_string, &ldap_settings.getpwuid_filter, 0, NULL,
-    N_("LDAP filter to use for getpwuid requests."),
-    N_("filter") },
-  { NULL }
-};
-
-int									      
-mu_ldap_section_parser
-   (enum mu_cfg_section_stage stage, const mu_cfg_node_t *node,	      
-    const char *section_label, void **section_data,
-    void *call_data, mu_cfg_tree_t *tree)
-{									      
-  switch (stage)							      
-    {									      
-    case mu_cfg_section_start:
-      ldap_settings.enable = 1;
-      break;								      
-      									      
-    case mu_cfg_section_end:						      
-      mu_gocs_store ("ldap", &ldap_settings);	      
-    }									      
-  return 0;								      
-}
-
-struct mu_cfg_capa mu_ldap_cfg_capa = {                
-  "ldap",  mu_ldap_param, mu_ldap_section_parser
-};
diff --git a/libmu_cfg/pam.c b/libmu_cfg/pam.c
deleted file mode 100644
index ec8c9cc..0000000
--- a/libmu_cfg/pam.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
-   Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-
-static char *pam_settings;
-
-static struct mu_cfg_param mu_pam_param[] = {
-  { "service", mu_c_string, &pam_settings, 0, NULL,
-    N_("Set PAM service name."),
-    N_("name") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (pam);
-
diff --git a/libmu_cfg/radius.c b/libmu_cfg/radius.c
deleted file mode 100644
index fb874a6..0000000
--- a/libmu_cfg/radius.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
-   Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-#include <mailutils/radius.h>
-
-static struct mu_radius_module_data radius_settings;
-
-static struct mu_cfg_param mu_radius_param[] = {
-  { "auth", mu_c_string, &radius_settings.auth_request, 0, NULL,
-    N_("Radius request for authorization."),
-    N_("request") },
-  { "getpwnam", mu_c_string, &radius_settings.getpwnam_request, 0, NULL,
-    N_("Radius request for getpwnam."),
-    N_("request") },
-  { "getpwuid", mu_c_string, &radius_settings.getpwuid_request, 0, NULL,
-    N_("Radius request for getpwuid."),
-    N_("request") },
-  { "directory", mu_c_string, &radius_settings.config_dir, 0, NULL,
-    N_("Set radius configuration directory.") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (radius);
diff --git a/libmu_cfg/sieve.c b/libmu_cfg/sieve.c
deleted file mode 100644
index fb4f106..0000000
--- a/libmu_cfg/sieve.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
-   Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-#include <mailutils/sieve.h>
-
-static struct mu_gocs_sieve sieve_settings;
-
-static int
-cb_clear_library_path (void *data, mu_config_value_t *val)
-{
-  int flag;
-
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
-    {
-      mu_error (_("not a boolean"));
-      return 1;
-    }
-  if (flag)
-    sieve_settings.clearflags |= MU_SIEVE_CLEAR_LIBRARY_PATH;
-  return 0;
-}
-
-static int
-cb_clear_include_path (void *data, mu_config_value_t *val)
-{
-  int flag;
-  
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  if (mu_str_to_c (val->v.string, mu_c_bool, &flag, NULL))
-    {
-      mu_error (_("not a boolean"));
-      return 1;
-    }
-  if (flag)
-    sieve_settings.clearflags |= MU_SIEVE_CLEAR_INCLUDE_PATH;
-  return 0;
-}
-
-static int
-_add_path (const char *arg, void *data)
-{
-  mu_list_t *plist = data;
-    
-  if (!*plist)
-    {
-      int rc = mu_list_create (plist);
-      if (rc)
-	{
-	  mu_error (_("cannot create list: %s"), mu_strerror (rc));
-	  exit (1);
-	}
-      mu_list_set_destroy_item (*plist, mu_list_free_item);
-    }
-  return mu_string_split (arg, ":", *plist);
-}
-
-static int
-cb_include_path (void *data, mu_config_value_t *val)
-{
-  return mu_cfg_string_value_cb (val, _add_path,
-				 &sieve_settings.include_path);
-}  
-
-static int
-cb_library_path (void *data, mu_config_value_t *val)
-{
-  return mu_cfg_string_value_cb (val, _add_path,
-				 &sieve_settings.library_path);
-}
-
-static int
-cb_library_path_prefix (void *data, mu_config_value_t *val)
-{
-  return mu_cfg_string_value_cb (val, _add_path,
-				 &sieve_settings.library_path_prefix);
-}
-
-static struct mu_cfg_param mu_sieve_param[] = {
-  { "clear-library-path", mu_cfg_callback, NULL, 0, cb_clear_library_path,
-     N_("Clear library search path.") },
-  { "clear-include-path", mu_cfg_callback, NULL, 0, cb_clear_include_path,
-     N_("Clear include search path.") },
-  { "library-path", mu_cfg_callback, NULL, 0, cb_library_path,
-    N_("Add directories to the library search path.  Argument is a "
-       "colon-separated list of directories."),
-    N_("list") },
-  { "library-path-prefix", mu_cfg_callback, NULL, 0, cb_library_path_prefix,
-    N_("Add directories to the beginning of the library search path.  "
-       "Argument is a colon-separated list of directories."),
-    N_("list") },
-  { "include-path", mu_cfg_callback, NULL, 0, cb_include_path,
-    N_("Add directories to the include search path.  Argument is a "
-       "colon-separated list of directories."),
-    N_("list") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (sieve);
diff --git a/libmu_cfg/sql.c b/libmu_cfg/sql.c
deleted file mode 100644
index af60300..0000000
--- a/libmu_cfg/sql.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2012, 2014-2016 Free Software Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-#include <mailutils/sql.h>
-#include <mailutils/util.h>
-
-static struct mu_sql_module_config sql_settings;
-
-
-
-/* Resource file configuration */
-static int
-cb_password_type (void *data, mu_config_value_t *val)
-{
-  if (mu_cfg_assert_value_type (val, MU_CFG_STRING))
-    return 1;
-  
-  if (mu_sql_decode_password_type (val->v.string, &sql_settings.password_type))
-    mu_error (_("unknown password type `%s'"), val->v.string);
-  return 0;
-}
-
-static int
-_cb2_field_map (const char *arg, void *data)
-{
-  int err;
-  int rc = mutil_parse_field_map (arg, &sql_settings.field_map, &err);
-  if (rc)
-    /* FIXME: this message may be misleading */
-    mu_error (_("error near element %d: %s"), err, mu_strerror (rc));
-  return 0;
-}
-
-static int
-cb_field_map (void *data, mu_config_value_t *val)
-{
-  return mu_cfg_string_value_cb (val, _cb2_field_map, NULL);
-}
-
-static struct mu_cfg_param mu_sql_param[] = {
-  { "interface", mu_c_string, &sql_settings.interface, 0, NULL,
-    N_("Set SQL interface to use (one of: mysql, odbc, or postgres).") },
-  { "getpwnam", mu_c_string, &sql_settings.getpwnam_query, 0, NULL,
-    N_("SQL query to use for getpwnam requests."),
-    N_("query") },
-  { "getpwuid", mu_c_string, &sql_settings.getpwuid_query, 0, NULL,
-    N_("SQL query to use for getpwuid requests."),
-    N_("query") },
-  { "getpass", mu_c_string, &sql_settings.getpass_query, 0, NULL,
-    N_("SQL query returning the user's password."),
-    N_("query") },
-  { "host", mu_c_string, &sql_settings.host, 0, NULL,
-    N_("SQL server host name.") },
-  { "user", mu_c_string, &sql_settings.user, 0, NULL,
-    N_("SQL user name.") },
-  { "passwd", mu_c_string, &sql_settings.passwd, 0, NULL,
-    N_("Password for the SQL user.") },
-  { "port", mu_c_int, &sql_settings.port, 0, NULL,
-    N_("SQL server port.") },
-  { "db", mu_c_string, &sql_settings.db, 0, NULL,
-    N_("Database name.") },
-  { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
-    N_("Type of password returned by getpass query (one of: plain, hash, "
-       "scrambled).") },
-  { "positional", mu_c_bool, &sql_settings.positional, 0, NULL,
-    N_("Use positional (v1.0 compatible) field interface.") },
-  { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
-    N_("Set a field-map for parsing SQL replies.  The map is a "
-       "column-separated list of definitions.  Each definition has the "
-       "following form:\n"
-       "   <name: string>=<column: string>\n"
-       "where <name> is one of the following: name, passwd, uid, gid, "
-       "gecos, dir, shell, mailbox, quota, and <column> is the name of "
-       "the corresponding SQL column."),
-    N_("map") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (sql);
-
-     
diff --git a/libmu_cfg/tls.c b/libmu_cfg/tls.c
deleted file mode 100644
index 3d568ef..0000000
--- a/libmu_cfg/tls.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007-2008, 2010-2012, 2014-2016 Free Software
-   Foundation, Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-#include <mailutils/tls.h>
-#include <mailutils/util.h>
-#include <mailutils/kwd.h>
-
-#define SSL_CERT_FILE_CHECKS  (MU_FILE_SAFETY_GROUP_WRITABLE |		\
-			       MU_FILE_SAFETY_GROUP_WRITABLE |		\
-			       MU_FILE_SAFETY_LINKED_WRDIR)
-
-#define SSL_KEY_FILE_CHECKS   (MU_FILE_SAFETY_ALL & ~MU_FILE_SAFETY_OWNER_MISMATCH)
-
-#define SSL_CA_FILE_CHECKS    (MU_FILE_SAFETY_GROUP_WRITABLE |		\
-			       MU_FILE_SAFETY_GROUP_WRITABLE |		\
-			       MU_FILE_SAFETY_LINKED_WRDIR)
-
-static struct mu_tls_module_config tls_settings = {
-    1,                   /* enabled by default */
-
-    NULL,                /* Certificate file */
-    SSL_CERT_FILE_CHECKS,
-
-    NULL,                /* Key file */ 
-    SSL_KEY_FILE_CHECKS, /* Stringent safety checks for keys */
-
-    NULL,                /* CA file */
-    SSL_CA_FILE_CHECKS
-};
-
-static int
-cb2_safety_checks (const char *name, void *data)
-{
-  int defval;
-  
-  if (data == &tls_settings.ssl_key_safety_checks)
-    defval = SSL_KEY_FILE_CHECKS;
-  else if (data == &tls_settings.ssl_cert_safety_checks)
-    defval = SSL_CERT_FILE_CHECKS;
-  else if (data == &tls_settings.ssl_cafile_safety_checks)
-    defval = SSL_CA_FILE_CHECKS;
-  else
-    {
-      mu_error (_("INTERNAL ERROR at %s:%d: unknown default value?"),
-		__FILE__, __LINE__);
-      defval = MU_FILE_SAFETY_ALL;
-    }
-  if (mu_file_safety_compose (data, name, defval))
-    mu_error (_("unknown keyword: %s"), name);
-  return 0;
-}
-
-static int
-cb_safety_checks (void *data, mu_config_value_t *arg)
-{
-  return mu_cfg_string_value_cb (arg, cb2_safety_checks, data);
-}
-
-static struct mu_cfg_param mu_tls_param[] = {
-  { "enable", mu_c_bool, &tls_settings.enable, 0, NULL,
-    N_("Enable TLS encryption.") },
-  { "ssl-cert", mu_c_string, &tls_settings.ssl_cert, 0, NULL,
-    N_("Specify SSL certificate file."),
-    N_("file") },
-  { "ssl-key", mu_c_string, &tls_settings.ssl_key, 0, NULL,
-    N_("Specify SSL certificate key file."),
-    N_("file") },
-  { "ssl-cafile", mu_c_string, &tls_settings.ssl_cafile, 0, NULL,
-    N_("Specify trusted CAs file."),
-    N_("file") },
-  { "ssl-priorities", mu_c_string, &tls_settings.priorities, 0, NULL,
-    N_("Set the priorities to use on the ciphers, key exchange methods, "
-       "macs and compression methods."),
-    NULL },
-  { "key-file-safety-checks", mu_cfg_callback,
-    &tls_settings.ssl_key_safety_checks, 0,
-    cb_safety_checks,
-    N_("Configure safety checks for SSL key file.  Argument is a list or "
-       "sequence of check names optionally prefixed with '+' to enable or "
-       "'-' to disable the corresponding check.  Valid check names are:\n"
-       "\n"
-       "  none          disable all checks\n"
-       "  all           enable all checks\n"
-       "  gwrfil        forbid group writable files\n"
-       "  awrfil        forbid world writable files\n"
-       "  grdfil        forbid group readable files\n"
-       "  ardfil        forbid world writable files\n"
-       "  linkwrdir     forbid symbolic links in group or world writable directories\n"
-       "  gwrdir        forbid files in group writable directories\n"
-       "  awrdir        forbid files in world writable directories\n"),
-    N_("arg: list") },  
-  { "cert-file-safety-checks", mu_cfg_callback,
-    &tls_settings.ssl_cert_safety_checks, 0,
-    cb_safety_checks,
-    N_("Configure safety checks for SSL certificate.  See above for a description of <arg>."),
-    N_("arg: list") },  
-  { "ca-file-safety-checks", mu_cfg_callback,
-    &tls_settings.ssl_cafile_safety_checks, 0,
-    cb_safety_checks,
-    N_("Configure safety checks for SSL certificate authority file.  See above for a description of <arg>."),
-    N_("arg: list") },  
-  { NULL }
-}; 
-
-DCL_CFG_CAPA (tls);
-
diff --git a/libmu_cfg/virtdomain.c b/libmu_cfg/virtdomain.c
deleted file mode 100644
index d4e2d1e..0000000
--- a/libmu_cfg/virtdomain.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* This file is part of GNU Mailutils
-   Copyright (C) 2007, 2010-2012, 2014-2016 Free Software Foundation,
-   Inc.
-
-   GNU Mailutils is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 3, or (at
-   your option) any later version.
-
-   GNU Mailutils is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include "mailutils/libcfg.h"
-
-static struct mu_gocs_virtual virtdomain_settings;
-
-static struct mu_cfg_param mu_virtdomain_param[] = {
-  { "passwd-dir", mu_c_string, &virtdomain_settings, 0, NULL,
-    N_("Name of the directory where virtual domain password files are "
-       "located."),
-    N_("dir") },
-  { NULL }
-};
-
-DCL_CFG_CAPA (virtdomain);
-     
diff --git a/libmu_sieve/conf.c b/libmu_sieve/conf.c
index 15b33aa..7b9102f 100644
--- a/libmu_sieve/conf.c
+++ b/libmu_sieve/conf.c
@@ -29,9 +29,6 @@ mu_list_t mu_sieve_library_path = NULL;
 mu_list_t mu_sieve_library_path_prefix = NULL;
 mu_debug_handle_t mu_sieve_debug_handle;
 
-//FIXME: provide definition (from gocs.h)
-static struct mu_gocs_sieve sieve_settings;
-
 void
 mu_sieve_debug_init (void)
 {
@@ -39,6 +36,15 @@ mu_sieve_debug_init (void)
     mu_sieve_debug_handle = mu_debug_register_category ("sieve");
 }
 
+struct sieve_settings
+{
+  int clearflags;
+  mu_list_t include_path;
+  mu_list_t library_path_prefix;
+  mu_list_t library_path;
+};
+static struct sieve_settings sieve_settings;
+
 /*FIXME: REMOVE BEGIN */
 static int
 _path_append (void *item, void *data)
@@ -61,33 +67,6 @@ _path_append (void *item, void *data)
   return mu_list_append (*plist, p);
 }
 
-int
-mu_sieve_module_init (enum mu_gocs_op op, void *data)
-{
-  struct mu_gocs_sieve *p;
-  if (!(op == mu_gocs_op_set && data))
-    return 0;
-  p = data;
-
-  if (p->clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
-    mu_list_destroy (&mu_sieve_include_path);
-  mu_list_foreach (p->include_path, _path_append, &mu_sieve_include_path);
-  if (p->clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH)
-    {
-      mu_list_destroy (&mu_sieve_library_path);
-      mu_list_destroy (&mu_sieve_library_path_prefix);
-    }
-  mu_list_foreach (p->library_path_prefix, _path_append,
-		   &mu_sieve_library_path_prefix);
-  mu_list_foreach (p->library_path, _path_append, &mu_sieve_library_path);
-  mu_list_destroy (&p->library_path);
-  mu_list_destroy (&p->library_path_prefix);
-  mu_list_destroy (&p->include_path);
-  mu_sieve_debug_init ();
-  return 0;
-}
-/* FIXME: REMOVE END */
-
 static int
 cb_clear_library_path (void *data, mu_config_value_t *val)
 {
@@ -238,9 +217,30 @@ static struct mu_option sieve_option[] = {
   MU_OPTION_END
 };
 
+static void
+sieve_commit (void *ptr)
+{
+  if (sieve_settings.clearflags & MU_SIEVE_CLEAR_INCLUDE_PATH)
+    mu_list_destroy (&mu_sieve_include_path);
+  mu_list_foreach (sieve_settings.include_path, _path_append, &mu_sieve_include_path);
+  if (sieve_settings.clearflags & MU_SIEVE_CLEAR_LIBRARY_PATH)
+    {
+      mu_list_destroy (&mu_sieve_library_path);
+      mu_list_destroy (&mu_sieve_library_path_prefix);
+    }
+  mu_list_foreach (sieve_settings.library_path_prefix, _path_append,
+		   &mu_sieve_library_path_prefix);
+  mu_list_foreach (sieve_settings.library_path, _path_append, &mu_sieve_library_path);
+  mu_list_destroy (&sieve_settings.library_path);
+  mu_list_destroy (&sieve_settings.library_path_prefix);
+  mu_list_destroy (&sieve_settings.include_path);
+  mu_sieve_debug_init ();
+}
+
 struct mu_cli_capa mu_cli_capa_sieve = {
   "sieve",
   sieve_option,
   mu_sieve_param,
-  NULL, NULL
+  NULL,
+  sieve_commit
 };
diff --git a/maidag/Makefile.am b/maidag/Makefile.am
index 008713e..53c887e 100644
--- a/maidag/Makefile.am
+++ b/maidag/Makefile.am
@@ -36,7 +36,7 @@ maidag_LDADD = \
  @LIBMU_SCM@ @GUILE_LIBS@\
  @LIBMU_SCM_DEPS@\
  @MU_LIB_PY@ @PYTHON_LIBS@\
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_SIEVE}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
diff --git a/maidag/maidag.c b/maidag/maidag.c
index ddca3ee..9b1c37e 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -270,7 +270,6 @@ static char *capa[] = {
   "locking",
   "mailer",
   "sieve",
-  "tls",
   NULL
 };
 
@@ -553,7 +552,7 @@ main (int argc, char *argv[])
   mu_log_print_severity = 1;
   
   /* Parse command line */
-  mu_cli_capa_register (&mu_cli_capa_tls);
+
   mu_cli_capa_register (&mu_cli_capa_sieve);
   mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 7af953a..7134b5a 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -25,7 +25,7 @@ mailbindir=@MAILBINDIR@
 mailbin_PROGRAMS = mail
 
 mail_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/mail/mail.c b/mail/mail.c
index a10d061..cd8c466 100644
--- a/mail/mail.c
+++ b/mail/mail.c
@@ -17,6 +17,7 @@
 
 #include "mail.h"
 #include "mailutils/cli.h"
+#include "mailutils/mu_auth.h"
 
 /* Global variables and constants*/
 mu_mailbox_t mbox;            /* Mailbox being operated upon */
@@ -240,7 +241,6 @@ static char *mail_capa[] = {
   "debug",
   "mailbox",
   "locking",
-  "tls",
   NULL 
 };
 			     
@@ -368,6 +368,8 @@ main (int argc, char **argv)
   /* Register the desired formats.  */
   mu_register_all_formats ();
 
+  mu_auth_register_module (&mu_auth_tls_module);  
+  
   interactive = isatty (fileno (stdin));
 #ifdef HAVE_SIGACTION
   {
@@ -417,7 +419,6 @@ main (int argc, char **argv)
 	       MOPTF_OVERWRITE);
 
   /* argument parsing */
-  mu_cli_capa_register (&mu_cli_capa_tls);
   mu_cli (argc, argv, &cli, mail_capa, NULL, &argc, &argv);
 
   if ((hint & (HINT_SEND_MODE|HINT_FILE_OPTION)) ==
diff --git a/messages/Makefile.am b/messages/Makefile.am
index 56ff5e7..d611b2c 100644
--- a/messages/Makefile.am
+++ b/messages/Makefile.am
@@ -22,7 +22,7 @@ SUBDIRS = . tests
 bin_PROGRAMS = messages
 messages_SOURCES = messages.c
 messages_LDADD =\
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/messages/messages.c b/messages/messages.c
index 84cf4bf..c0c2c4a 100644
--- a/messages/messages.c
+++ b/messages/messages.c
@@ -41,7 +41,6 @@ static char *capa[] = {
   "debug",
   "mailbox",
   "locking",
-  "tls",
   NULL
 };
 
@@ -65,7 +64,7 @@ main (int argc, char **argv)
   /* register the formats.  */
   mu_register_all_mbox_formats ();
 
-  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_auth_register_module (&mu_auth_tls_module);
   mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   if (argc == 0 && messages_count (NULL) < 0)
diff --git a/mimeview/Makefile.am b/mimeview/Makefile.am
index d85eebb..b4c9108 100644
--- a/mimeview/Makefile.am
+++ b/mimeview/Makefile.am
@@ -47,7 +47,7 @@ mimetypes-lex.c: $(srcdir)/mimetypes.l mimetypes-decl.h
 BUILT_SOURCES = mimetypes-gram.c mimetypes-lex.c mimetypes-decl.h
 
 mimeview_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MAILUTILS}\
  @LTLIBINTL@
  
diff --git a/movemail/Makefile.am b/movemail/Makefile.am
index 5d0b5c6..e166b81 100644
--- a/movemail/Makefile.am
+++ b/movemail/Makefile.am
@@ -19,7 +19,7 @@ AM_CPPFLAGS = @MU_APP_COMMON_INCLUDES@ @MU_AUTHINCS@
 bin_PROGRAMS = movemail
 
 movemail_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/movemail/movemail.c b/movemail/movemail.c
index 8fdaf90..1352578 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -381,7 +381,6 @@ static char *movemail_capa[] = {
   "locking",
   "mailbox",
   "auth",
-  "tls",
   NULL 
 };
 
@@ -843,10 +842,10 @@ main (int argc, char **argv)
   
   /* Register the desired "mailbox" formats.  */
   mu_register_all_formats ();
-
-  /* argument parsing */
+  /* Register authentication modules */
+  mu_auth_register_module (&mu_auth_tls_module);
   
-  mu_cli_capa_register (&mu_cli_capa_tls);
+  /* argument parsing */
   mu_cli (argc, argv, &cli, movemail_capa, NULL, &argc, &argv);
 
   if (argc < 2 || argc > 3)
diff --git a/mu/acl.c b/mu/acl.c
index 749ba28..e7d2de7 100644
--- a/mu/acl.c
+++ b/mu/acl.c
@@ -14,63 +14,24 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <sys/un.h>
-#include <arpa/inet.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include "argp.h"
 #include "mu.h"
 
-static char acl_doc[] = N_("mu acl - test access control lists.");
 char acl_docstring[] = N_("test access control lists");
 static char acl_args_doc[] = N_("ADDRESS [ADDRESS...]");
 
-static struct argp_option acl_options[] = {
-  { "file", 'f', N_("FILE"), 0, N_("read ACLs from FILE") },
-  { "path", 'p', N_("PATH"), 0,
-    N_("path to the ACL in the configuration tree") },
-  { NULL }
-};
-
 static char *input_file_name;
 static struct mu_sockaddr *target_sa;
 static mu_acl_t acl;
 static const char *path = "acl";
 
-static error_t
-acl_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case 'f':
-      input_file_name = arg;
-      break;
-
-    case 'p':
-      path = arg;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp acl_argp = {
-  acl_options,
-  acl_parse_opt,
-  acl_args_doc,
-  acl_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option acl_options[] = {
+  { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read ACLs from FILE"),
+    mu_c_string, &input_file_name },
+  { "path", 'p', N_("PATH"), MU_OPTION_DEFAULT,
+    N_("path to the ACL in the configuration tree"),
+    mu_c_string, &path },
+  { NULL }
 };
 
 
@@ -82,16 +43,13 @@ static struct mu_cfg_param acl_cfg_param[] = {
 int
 mutool_acl (int argc, char **argv)
 {
-  int rc, index;
+  int rc;
   mu_acl_result_t result;
   mu_cfg_tree_t *tree = NULL, *temp_tree = NULL;
   mu_cfg_node_t *node;
-  
-  if (argp_parse (&acl_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
+  struct mu_cfg_parse_hints hints;
 
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, acl_options, acl_docstring, acl_args_doc);
 
   if (argc == 0)
     {
@@ -99,16 +57,13 @@ mutool_acl (int argc, char **argv)
       return 1;
     }
 
-  if (input_file_name)
-    {
-      mu_load_site_rcfile = 0;
-      mu_load_user_rcfile = 0;
-      mu_load_rcfile = input_file_name;
-    }
+  memset (&hints, 0, sizeof (hints));
+  hints.flags = MU_CFG_PARSE_CUSTOM_RCFILE;
+  hints.custom_rcfile = input_file_name;
 
   mu_acl_cfg_init ();
-  if (mu_libcfg_parse_config (&tree))
-    return 1;
+  if (mu_cfg_parse_config (&tree, &hints))
+    exit (EX_CONFIG);
   if (!tree)
     return 0;
   
diff --git a/mu/cflags.c b/mu/cflags.c
index 1ecadb5..dd549e6 100644
--- a/mu/cflags.c
+++ b/mu/cflags.c
@@ -14,32 +14,19 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <argp.h>
-
-static char cflags_doc[] = N_("mu cflags - show compiler options");
-char cflags_docstring[] = N_("show compiler options");
+#include "mu.h"
 
-static struct argp cflags_argp = {
-  NULL,
-  NULL,
-  NULL,
-  cflags_doc,
-  NULL,
-  NULL,
-  NULL
-};
+char cflags_docstring[] = N_("show compiler options");
 
 int
 mutool_cflags (int argc, char **argv)
 {
-  if (argp_parse (&cflags_argp, argc, argv, ARGP_IN_ORDER, NULL, NULL))
-    return 1;
+  mu_action_getopt (&argc, &argv, NULL, cflags_docstring, NULL);
+  if (argc)
+    {
+      mu_error (_("too many arguments"));
+      return EX_USAGE;
+    }
   mu_printf ("%s\n", COMPILE_FLAGS);
   return 0;
 }
diff --git a/mu/dbm.c b/mu/dbm.c
index 4c0e4d2..531a3cf 100644
--- a/mu/dbm.c
+++ b/mu/dbm.c
@@ -14,21 +14,12 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grp.h>
-#include <sysexits.h>
+#include "mu.h"
+#include <mailutils/dbm.h>
 #include <fnmatch.h>
 #include <regex.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/dbm.h>
-#include "argp.h"
-#include "mu.h"
+#include <sys/stat.h>
+#include <grp.h>
 
 static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
 "Valid COMMANDs are:\n"
@@ -39,6 +30,7 @@ static char dbm_doc[] = N_("mu dbm - DBM management tool\n"
 "  delete         - delete specified keys from the database\n"
 "  add            - add records to the database\n"
 "  replace        - add records replacing ones with matching keys\n");
+
 char dbm_docstring[] = N_("DBM management tool");
 static char dbm_args_doc[] = N_("COMMAND FILE [KEY...]");
 
@@ -1603,154 +1595,161 @@ delete_database (int argc, char **argv)
   mu dbm --replace a.db < input
  */
 
-static struct argp_option dbm_options[] = {
-  { NULL, 0, NULL, 0, N_("Create Options"), 0},
-  { "file",   'f', N_("FILE"), 0,
-    N_("read input from FILE (with create, delete, add and replace)") },
-  { "permissions", 'p', N_("NUM"), 0,
-    N_("set permissions on the created database") },
-  { "user",        'u', N_("USER"), 0,
-    N_("set database owner name") },
-  { "group",       'g', N_("GROUP"), 0,
-    N_("set database owner group") },
-  { "copy-permissions", 'P', NULL, 0,
-    N_("copy database permissions and ownership from the input file") },
-  { "ignore-meta",      'm', NULL, 0,
-    N_("ignore meta-information from input file headers") },
-  { "ignore-directives", 'I', N_("NAMES"), 0,
-    N_("ignore the listed directives") },
-  { NULL, 0, NULL, 0, N_("List and Dump Options"), 0},
-  { "format",           'H', N_("TYPE"), 0,
-    N_("select output format") },
-  { "no-header",        'q', NULL, 0,
-    N_("suppress format header") },
-  { NULL, 0, NULL, 0, N_("List, Dump and Delete Options"), 0},
-  { "glob",        'G', NULL, 0,
-    N_("treat keys as globbing patterns") },
-  { "regex",       'R', NULL, 0,
-    N_("treat keys as regular expressions") },
-  { "ignore-case", 'i', NULL, 0,
-    N_("case-insensitive matches") },
-  { NULL, 0, NULL, 0, N_("Options for Use with Format 0.0"), 0 },
-  { "count-null",  'N', NULL, 0,
-    N_("data length accounts for terminating zero") },
-  { "no-count-null", 'n', NULL, 0,
-    N_("data length does not account for terminating zero") },
-  { NULL }
-};
-
-static error_t
-dbm_parse_opt (int key, char *arg, struct argp_state *state)
+static void
+set_permissions (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
+  char *p;
+  unsigned long d = strtoul (arg, &p, 8);
+  if (*p || (d & ~0777))
     {
-    case 'f':
-      input_file = arg;
-      break;
-
-    case 'H':
-      select_format (arg);
-      break;
-      
-    case 'p':
-      {
-	char *p;
-	unsigned long d = strtoul (arg, &p, 8);
-	if (*p || (d & ~0777))
-	  argp_error (state, _("invalid file mode: %s"), arg);
-	file_mode = d;
-	known_meta_data |= META_FILE_MODE;
-      }
-      break;
+      mu_parseopt_error (po, _("invalid file mode: %s"), arg);
+      exit (po->po_exit_error);
+    }
+  file_mode = d;
+  known_meta_data |= META_FILE_MODE;
+}
 
-    case 'P':
-      copy_permissions = 1;
-      break;
+static void
+set_user (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  auth = mu_get_auth_by_name (arg);
+  if (auth)
+    known_meta_data |= META_AUTH;
+  else
+    {
+      char *p;
+      unsigned long n = strtoul (arg, &p, 0);
+      if (*p == 0)
+	{
+	  owner_uid = n;
+	  known_meta_data |= META_UID;
+	}
+      else
+	{
+	  mu_parseopt_error (po, _("no such user: %s"), arg);
+	  exit (po->po_exit_error);
+	}
+    }
+  ignore_directives ("user,uid");
+}
 
-    case 'q':
-      suppress_header = 1;
-      break;
-      
-    case 'u':
-      auth = mu_get_auth_by_name (arg);
-      if (auth)
-	known_meta_data |= META_AUTH;
+static void
+set_group (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  struct group *gr = getgrnam (arg);
+  if (!gr)
+    {
+      char *p;
+      unsigned long n = strtoul (arg, &p, 0);
+      if (*p == 0)
+	owner_gid = n;
       else
 	{
-	  char *p;
-	  unsigned long n = strtoul (arg, &p, 0);
-	  if (*p == 0)
-	    {
-	      owner_uid = n;
-	      known_meta_data |= META_UID;
-	    }
-	  else
-	    argp_error (state, _("no such user: %s"), arg);
+	  mu_parseopt_error (po, _("no such group: %s"), arg);
+	  exit (po->po_exit_error);
 	}
-      ignore_directives ("user,uid");
-      break;
+    }
+  else
+    owner_gid = gr->gr_gid;
+  known_meta_data |= META_GID;
+  ignore_directives ("group,gid");
+}
 
-    case 'g':
-      {
-	struct group *gr = getgrnam (arg);
-	if (!gr)
-	  {
-	    char *p;
-	    unsigned long n = strtoul (arg, &p, 0);
-	    if (*p == 0)
-	      owner_gid = n;
-	    else
-	      argp_error (state, _("no such group: %s"), arg);
-	  }
-	else
-	  owner_gid = gr->gr_gid;
-	known_meta_data |= META_GID;
-	ignore_directives ("group,gid");
-      }
-      break;
+static void
+set_ignore_meta (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  ignore_flagged_directives (DF_META);
+}
 
-    case 'G':
-      key_type = key_glob;
-      break;
+static void
+set_ignore_directives (struct mu_parseopt *po, struct mu_option *opt,
+		       char const *arg)
+{
+  ignore_directives (arg);
+}
 
-    case 'R':
-      key_type = key_regex;
-      break;
+static void
+set_format (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  select_format (arg);
+}
 
-    case 'm':/* FIXME: Why m? */
-      ignore_flagged_directives (DF_META);
-      break;
+static void
+set_glob (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  key_type = key_glob;
+}
 
-    case 'I':
-      ignore_directives (arg);
-      break;
-      
-    case 'i':
-      case_sensitive = 0;
-      break;
+static void
+set_regex (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  key_type = key_regex;
+}
 
-    case 'N':
-      include_zero = 1;
-      break;
+static void
+set_ignore_case (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  case_sensitive = 0;
+}
 
-    case 'n':
-      include_zero = 0;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+clear_include_zero (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  include_zero = 0;
 }
 
-static struct argp dbm_argp = {
-  dbm_options,
-  dbm_parse_opt,
-  dbm_args_doc,
-  dbm_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option dbm_options[] = {
+  MU_OPTION_GROUP (N_("Create Options")),
+  { "file",   'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read input from FILE (with create, delete, add and replace)"),
+    mu_c_string, &input_file },
+  { "permissions", 'p', N_("NUM"), MU_OPTION_DEFAULT,
+    N_("set permissions on the created database"),
+    mu_c_string, NULL, set_permissions },
+  { "user",        'u', N_("USER"), MU_OPTION_DEFAULT,
+    N_("set database owner name"),
+    mu_c_string, NULL, set_user },
+  { "group",       'g', N_("GROUP"), MU_OPTION_DEFAULT,
+    N_("set database owner group"),
+    mu_c_string, NULL, set_group },
+  { "copy-permissions", 'P', NULL, MU_OPTION_DEFAULT,
+    N_("copy database permissions and ownership from the input file"),
+    mu_c_bool, &copy_permissions },
+  { "ignore-meta",      'm', NULL, MU_OPTION_DEFAULT,
+    N_("ignore meta-information from input file headers"),
+    mu_c_string, NULL, set_ignore_meta },
+  { "ignore-directives", 'I', N_("NAMES"), MU_OPTION_DEFAULT,
+    N_("ignore the listed directives"),
+    mu_c_string, NULL, set_ignore_directives },
+  
+  MU_OPTION_GROUP (N_("List and Dump Options")),
+  { "format",           'H', N_("TYPE"), MU_OPTION_DEFAULT,
+    N_("select output format"),
+    mu_c_string, NULL, set_format },
+  { "no-header",        'q', NULL, MU_OPTION_DEFAULT,
+    N_("suppress format header"),
+    mu_c_bool, &suppress_header },
+  
+  MU_OPTION_GROUP (N_("List, Dump and Delete Options")),
+  { "glob",        'G', NULL, MU_OPTION_DEFAULT,
+    N_("treat keys as globbing patterns"),
+    mu_c_string, NULL, set_glob },
+  { "regex",       'R', NULL, MU_OPTION_DEFAULT,
+    N_("treat keys as regular expressions"),
+    mu_c_string, NULL, set_regex },
+  { "ignore-case", 'i', NULL, MU_OPTION_DEFAULT,
+    N_("case-insensitive matches"),
+    mu_c_string, NULL, set_ignore_case },
+  
+  MU_OPTION_GROUP (N_("Options for Use with Format 0.0")),
+  { "count-null",  'N', NULL, MU_OPTION_DEFAULT,
+    N_("data length accounts for terminating zero"),
+    mu_c_bool, &include_zero },
+  { "no-count-null", 'n', NULL, MU_OPTION_DEFAULT,
+    N_("data length does not account for terminating zero"),
+    mu_c_string, NULL, clear_include_zero },
+  MU_OPTION_END
 };
 
 struct mu_kwd mode_tab[] =
@@ -1769,12 +1768,8 @@ int
 mutool_dbm (int argc, char **argv)
 {
   int index;
-
-  if (argp_parse (&dbm_argp, argc, argv, 0, &index, NULL))
-    return 1;
-
-  argc -= index;
-  argv += index;
+    
+  mu_action_getopt (&argc, &argv, dbm_options, dbm_doc, dbm_args_doc);
 
   if (argc == 0)
     {
diff --git a/mu/dispatch.c b/mu/dispatch.c
index 05ffeec..cd27a66 100644
--- a/mu/dispatch.c
+++ b/mu/dispatch.c
@@ -49,33 +49,34 @@ dispatch_find_action (const char *name)
   return NULL;
 }
 
-char *
-dispatch_docstring (const char *text)
+void
+subcommand_help (mu_stream_t str)
 {
-  mu_stream_t str;
   struct mutool_action_tab *p;
-  mu_off_t size;
-  size_t n;
-  char *ret;
+  unsigned margin;
   
-  mu_memory_stream_create (&str, MU_STREAM_RDWR);
-  mu_stream_printf (str, "%s\n%s\n\n", text, _("Commands are:"));
+  mu_stream_printf (str, "%s\n\n", _("Commands are:"));
   for (p = mutool_action_tab; p->name; p++)
-    mu_stream_printf (str, "  %s %-16s - %s\n",
-		      mu_program_name,
-		      p->name, gettext (p->docstring));
+    {
+      margin = 2;
+      mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		       MU_IOCTL_WORDWRAP_SET_MARGIN,
+		       &margin);
+      mu_stream_printf (str, "%s %s",  mu_program_name, p->name);
+      margin = 29;
+      mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		       MU_IOCTL_WORDWRAP_SET_MARGIN,
+		       &margin);
+      mu_stream_printf (str, "%s", gettext (p->docstring));
+    }
+  margin = 0;
+  mu_stream_ioctl (str, MU_IOCTL_WORDWRAPSTREAM,
+		   MU_IOCTL_WORDWRAP_SET_MARGIN,
+		   &margin);
   mu_stream_printf (str,
 		      _("\nTry `%s COMMAND --help' to get help on a particular "
 		      "COMMAND.\n\n"),
 		      mu_program_name);
-  mu_stream_printf (str, "%s\n", _("Options are:"));
-  mu_stream_flush (str);
-  mu_stream_size (str, &size);
-  ret = mu_alloc (size + 1);
-  mu_stream_seek (str, 0, MU_SEEK_SET, NULL);
-  mu_stream_read (str, ret, size, &n);
-  ret[n] = 0;
-  mu_stream_destroy (&str);
-  return ret;
+  mu_stream_printf (str, "%s\n", _("OPTIONs are:"));
 }
     
diff --git a/mu/filter.c b/mu/filter.c
index 33a5588..ea23979 100644
--- a/mu/filter.c
+++ b/mu/filter.c
@@ -23,57 +23,41 @@
 #include "argp.h"
 #include "mu.h"
 
-static char filter_doc[] = N_("mu filter - apply a chain of filters to the input");
 char filter_docstring[] = N_("apply a chain of filters to the input");
 static char filter_args_doc[] = N_("[~]NAME [ARGS] [+ [~]NAME [ARGS]...]");
 
-static struct argp_option filter_options[] = {
-  { "encode", 'e', NULL, 0, N_("encode the input (default)") },
-  { "decode", 'd', NULL, 0, N_("decode the input") },
-  { "newline", 'n', NULL, 0, N_("print additional newline") },
-  { "list", 'L', NULL, 0, N_("list supported filters") },
-  { NULL }
-};
-
 static int filter_mode = MU_FILTER_ENCODE;
 static int newline_option = 0;
 static int list_option;
 
-static error_t
-filter_parse_opt (int key, char *arg, struct argp_state *state)
+static void
+set_encode_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
 {
-  switch (key)
-    {
-    case 'e':
-      filter_mode = MU_FILTER_ENCODE;
-      break;
-
-    case 'd':
-      filter_mode = MU_FILTER_DECODE;
-      break;
-
-    case 'n':
-      newline_option = 1;
-      break;
+  filter_mode = MU_FILTER_ENCODE;
+}
 
-    case 'L':
-      list_option = 1;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+set_decode_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  filter_mode = MU_FILTER_DECODE;
 }
 
-static struct argp filter_argp = {
-  filter_options,
-  filter_parse_opt,
-  filter_args_doc,
-  filter_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option filter_options[] = {
+  { "encode", 'e', NULL, MU_OPTION_DEFAULT,
+    N_("encode the input (default)"),
+    mu_c_string, NULL, set_encode_mode },
+  { "decode", 'd', NULL, MU_OPTION_DEFAULT,
+    N_("decode the input"),
+    mu_c_string, NULL, set_decode_mode },
+  { "newline", 'n', NULL, MU_OPTION_DEFAULT,
+    N_("print additional newline"),
+    mu_c_bool, &newline_option },
+  { "list", 'L', NULL, MU_OPTION_DEFAULT,
+    N_("list supported filters"),
+    mu_c_bool, &list_option },
+  MU_OPTION_END
 };
 
 static int
@@ -85,7 +69,7 @@ filter_printer (void *item, void *data)
 }
 
 static int
-list_filters ()
+list_filters (void)
 {
   mu_list_t list;
   int rc = mu_filter_get_list (&list);
@@ -111,17 +95,14 @@ negate_filter_mode (int mode)
 int
 mutool_filter (int argc, char **argv)
 {
-  int rc, index;
+  int rc;
   mu_stream_t flt, prev_stream;
   const char *fltname;
   int mode;
-  
-  if (argp_parse (&filter_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
-
-  argc -= index;
-  argv += index;
 
+  mu_action_getopt (&argc, &argv, filter_options, filter_docstring,
+		    filter_args_doc);
+  
   if (list_option)
     {
       if (argc)
diff --git a/mu/flt2047.c b/mu/flt2047.c
index df02409..eb99b7b 100644
--- a/mu/flt2047.c
+++ b/mu/flt2047.c
@@ -14,87 +14,50 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/mailutils.h>
-#include "argp.h"
 #include "mu.h"
 
-static char flt2047_doc[] = N_("mu 2047 - decode/encode message headers.");
 char flt2047_docstring[] = N_("decode/encode email message headers");
 static char flt2047_args_doc[] = N_("[text]");
 
-static struct argp_option flt2047_options[] = {
-  { "encode", 'e', NULL, 0, N_("encode the input (default)") },
-  { "decode", 'd', NULL, 0, N_("decode the input") },
-  { "newline", 'n', NULL, 0, N_("print additional newline") },
-  { "charset", 'c', N_("NAME"), 0,
-    N_("set charset (default: iso-8859-1)") },
-  { "encoding", 'E', N_("NAME"), 0,
-    N_("set encoding (default: quoted-printable)") },
-  { NULL }
-};
-  
 static int decode_mode = 0;
 static int newline_option = 0;
 static const char *charset = "iso-8859-1";
 static const char *encoding = "quoted-printable";
 
-static error_t
-flt2047_parse_opt (int key, char *arg, struct argp_state *state)
+static void
+set_encode_mode (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
 {
-  switch (key)
-    {
-    case 'c':
-      charset = arg;
-      break;
-      
-    case 'e':
-      decode_mode = 0;
-      break;
-
-    case 'E':
-      encoding = arg;
-      break;
-
-    case 'd':
-      decode_mode = 1;
-      break;
-
-    case 'n':
-      newline_option = 0;
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+  decode_mode = 0;
 }
 
-static struct argp flt2047_argp = {
-  flt2047_options,
-  flt2047_parse_opt,
-  flt2047_args_doc,
-  flt2047_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option flt2047_options[] = {
+  { "encode", 'e', NULL, MU_OPTION_DEFAULT,
+    N_("encode the input (default)"),
+    mu_c_string, NULL, set_encode_mode },
+  { "decode", 'd', NULL, MU_OPTION_DEFAULT,
+    N_("decode the input"),
+    mu_c_bool, &decode_mode },
+  { "newline", 'n', NULL, MU_OPTION_DEFAULT,
+    N_("print additional newline"),
+    mu_c_bool, &newline_option },  
+  { "charset", 'c', N_("NAME"), MU_OPTION_DEFAULT,
+    N_("set charset (default: iso-8859-1)"),
+    mu_c_string, &charset },
+  { "encoding", 'E', N_("NAME"), MU_OPTION_DEFAULT,
+    N_("set encoding (default: quoted-printable)"),
+    mu_c_string, &encoding },
+  MU_OPTION_END
 };
-
+  
 int
 mutool_flt2047 (int argc, char **argv)
 {
-  int rc, index;
+  int rc;
   char *p;
-  
-  if (argp_parse (&flt2047_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
 
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, flt2047_options, flt2047_docstring,
+		    flt2047_args_doc);
 
   if (argc)
     {
diff --git a/mu/getans.c b/mu/getans.c
index dc59401..529aca4 100644
--- a/mu/getans.c
+++ b/mu/getans.c
@@ -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/>. */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <mailutils/mailutils.h>
 #include "mu.h"
 
 int
diff --git a/mu/getarg.c b/mu/getarg.c
index f7197df..6a084ed 100644
--- a/mu/getarg.c
+++ b/mu/getarg.c
@@ -14,16 +14,8 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <mailutils/mailutils.h>
 #include "mu.h"
+#include <netdb.h>
 
 int
 get_bool (const char *str, int *pb)
diff --git a/mu/getyn.c b/mu/getyn.c
index eb36492..d721f96 100644
--- a/mu/getyn.c
+++ b/mu/getyn.c
@@ -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/>. */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <mailutils/mailutils.h>
 #include "mu.h"
 
 int
diff --git a/mu/help.c b/mu/help.c
index 9889cab..3334417 100644
--- a/mu/help.c
+++ b/mu/help.c
@@ -29,37 +29,24 @@ static char help_doc[] = N_("mu help - display a terse help summary");
 char help_docstring[] = N_("display a terse help summary");
 static char help_args_doc[] = N_("[COMMAND]");
 
-static struct argp help_argp = {
-  NULL,
-  NULL,
-  help_args_doc,
-  help_doc,
-  NULL,
-  NULL,
-  NULL
-};
-
 int
 mutool_help (int argc, char **argv)
 {
-  int index;
-
-  if (argp_parse (&help_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
+  mu_action_getopt (&argc, &argv, NULL, help_doc, help_args_doc);
 
-  if (index == argc - 1)
+  if (argc == 1)
     {
-      mutool_action_t action = dispatch_find_action (argv[index]);
+      mutool_action_t action = dispatch_find_action (argv[0]);
       if (!action)
 	{
-	  mu_error (_("don't know what %s is"), argv[index]);
+	  mu_error (_("don't know what %s is"), argv[0]);
 	  exit (1);
 	}
-      mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[index]);
+      mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[0]);
       argv[1] = "--help";
       return action (2, argv);
     }
-  else if (argc != index)
+  else if (argc > 1)
     {
       mu_error (_("too many arguments"));
       exit (1);
diff --git a/mu/imap.c b/mu/imap.c
index 3aee4fb..3f64817 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -31,35 +31,7 @@
 #include "mu.h"
 #include "argp.h"
 
-static char imap_doc[] = N_("mu imap - IMAP4 client shell.");
 char imap_docstring[] = N_("IMAP4 client shell");
-static char imap_args_doc[] = "";
-
-static struct argp_option imap_options[] = {
-  { NULL }
-};
-
-static error_t
-imap_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp imap_argp = {
-  imap_options,
-  imap_parse_opt,
-  imap_args_doc,
-  imap_doc,
-  NULL,
-  NULL,
-  NULL
-};
-
 
 static mu_imap_t imap;
 static int uid_mode;
@@ -1336,13 +1308,7 @@ struct mutool_command imap_comtab[] = {
 int
 mutool_imap (int argc, char **argv)
 {
-  int index;
-
-  if (argp_parse (&imap_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
-
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, NULL, imap_docstring, NULL);
 
   if (argc)
     {
diff --git a/mu/info.c b/mu/info.c
index c44e7e1..dfbb2df 100644
--- a/mu/info.c
+++ b/mu/info.c
@@ -14,13 +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/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/mailutils.h>
-#include "argp.h"
 #include "mu.h"
 
 static char info_doc[] = N_("mu info - print a list of configuration\
@@ -29,49 +22,19 @@ static char info_doc[] = N_("mu info - print a list of configuration\
 char info_docstring[] = N_("show Mailutils configuration");
 static char info_args_doc[] = N_("[capa...]");
 
-static struct argp_option info_options[] = {
-  { "verbose", 'v', NULL, 0,
-    N_("increase output verbosity"), 0},
-  { NULL }
-};
-
 static int verbose;
 
-static error_t
-info_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case 'v':
-      verbose++;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp info_argp = {
-  info_options,
-  info_parse_opt,
-  info_args_doc,
-  info_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option info_options[] = {
+  { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
+    N_("increase output verbosity"),
+    mu_c_bool, &verbose },
+  MU_OPTION_END
 };
 
 int
 mutool_info (int argc, char **argv)
 {
-  int index;
-  
-  if (argp_parse (&info_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
-
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, info_options, info_doc, info_args_doc);
 
   if (argc == 0)
     mu_format_options (mu_strout, verbose);
diff --git a/mu/ldflags.c b/mu/ldflags.c
index 71f80a6..7f52bf2 100644
--- a/mu/ldflags.c
+++ b/mu/ldflags.c
@@ -14,28 +14,11 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <argp.h>
+#include "mu.h"
 
-static char ldflags_doc[] = N_("mu ldflags - list libraries required to link");
 char ldflags_docstring[] = N_("list libraries required to link");
 static char ldflags_args_doc[] = N_("KEYWORD [KEYWORD...]");
 
-static struct argp ldflags_argp = {
-  NULL,
-  NULL,
-  ldflags_args_doc,
-  ldflags_doc,
-  NULL,
-  NULL,
-  NULL
-};
-
 
 #ifdef WITH_TLS
 # define NEEDAUTH "-lmu_auth " AUTHLIBS
@@ -140,13 +123,9 @@ sort_entries ()
 int
 mutool_ldflags (int argc, char **argv)
 {
-  int i, j;
-  
-  if (argp_parse (&ldflags_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
-    return 1;
+  int j;
 
-  argc -= i;
-  argv += i;
+  mu_action_getopt (&argc, &argv, NULL, ldflags_docstring, ldflags_args_doc);
   
   add_entry (-100, LINK_FLAGS);
   add_entry (100, LINK_POSTFLAGS);
diff --git a/mu/logger.c b/mu/logger.c
index 37520dd..18a425a 100644
--- a/mu/logger.c
+++ b/mu/logger.c
@@ -14,35 +14,11 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <mailutils/mailutils.h>
-#include "argp.h"
 #include "mu.h"
 
-static char logger_doc[] = N_("mu logger - log data using Mailutils log facility");
 char logger_docstring[] = N_("log data using Mailutils log facility");
 static char logger_args_doc[] = N_("[TEXT]");
 
-#define OPT_SYSLOG 256
-#define OPT_STDERR 257
-
-static struct argp_option logger_options[] = {
-  { "file", 'f', N_("FILE"), 0, N_("read message from FILE") },
-  { "priority", 'p', N_("FACILITY[.LEVEL]"), 0,
-    N_("log at the specified syslog priority (implies --syslog)") },
-  { "syslog", OPT_SYSLOG, NULL, 0, N_("log via syslog") },
-  { "stderr", OPT_STDERR, NULL, 0, N_("log to the standard error") },
-  { "severity", 's', N_("SEV"), 0,
-    N_("log at Mailutils severity level SEV") },
-  { "locus", 'l', N_("FILE:LINE[:COL]"), 0,
-    N_("set locus for logging") },
-  { "tag", 't', N_("syslog tag"), 0,
-    N_("set syslog tag") },
-  { NULL }
-};
-
 static char *input_file = NULL;
 static int logger_type = MU_STRERR_STDERR;
 static int log_severity = MU_LOG_ERROR;
@@ -51,104 +27,119 @@ static int syslog_facility = LOG_USER;
 static int syslog_priority = LOG_ERR;
 static char *syslog_tag = NULL;
 
-static error_t
-logger_parse_opt (int key, char *arg, struct argp_state *state)
+static void
+set_priority (struct mu_parseopt *po, struct mu_option *opt,
+	      char const *arg)
 {
-  switch (key)
+  char *s = strchr (arg, '.');
+  if (s)
+    *s++ = 0;
+  if (mu_string_to_syslog_facility (arg, &syslog_facility))
     {
-    case 'f':
-      input_file = arg;
-      break;
+      mu_parseopt_error (po, _("unknown facility: %s"), arg);
+      exit (po->po_exit_error);
+    }
+  if (s && mu_string_to_syslog_priority (s, &syslog_priority))
+    {
+      mu_parseopt_error (po, _("unknown priority: %s"), s);
+      exit (po->po_exit_error);
+    }
+  
+  logger_type = MU_STRERR_SYSLOG;
+}
 
-    case OPT_SYSLOG:
-      logger_type = MU_STRERR_SYSLOG;
-      break;
+static void
+set_syslog (struct mu_parseopt *po, struct mu_option *opt,
+	    char const *arg)
+{
+  logger_type = MU_STRERR_SYSLOG;
+}
 
-    case OPT_STDERR:
-      logger_type = MU_STRERR_STDERR;
-      break;
+static void
+set_stderr (struct mu_parseopt *po, struct mu_option *opt,
+	    char const *arg)
+{
+  logger_type = MU_STRERR_STDERR;
+}
 
-    case 's':
+static void
+set_severity (struct mu_parseopt *po, struct mu_option *opt,
+	      char const *arg)
+{
+  int i;
+  
+  for (i = 0; i < _mu_severity_num; i++)
+    if (mu_c_strcasecmp (_mu_severity_str[i], arg) == 0)
       {
-	int i;
+	log_severity = i;
+	return;
+      }
+  mu_parseopt_error (po, _("unknown severity: %s"), arg);
+  exit (po->po_exit_error);
+}
 
-	for (i = 0; i < _mu_severity_num; i++)
-	  if (mu_c_strcasecmp (_mu_severity_str[i], arg) == 0)
+static void
+set_locus (struct mu_parseopt *po, struct mu_option *opt,
+	   char const *arg)
+{
+  char *s;
+  
+  locus.mu_file = mu_strdup (arg);
+  s = strchr (arg, ':');
+  if (s)
+    {
+      *s++ = 0;
+      locus.mu_line = strtoul (s, &s, 10);
+      if (*s == ':')
+	{
+	  locus.mu_col = strtoul (s + 1, &s, 10);
+	  if (*s)
 	    {
-	      log_severity = i;
-	      return 0;
+	      mu_parseopt_error (po, _("bad column number: %s"), arg);
+	      exit (po->po_exit_error);
 	    }
-	argp_error (state, _("unknown severity: %s"), arg);
-	break;
-      }
-
-    case 't':
-      syslog_tag = arg;
-      break;
-      
-    case 'p':
-      {
-	char *s = strchr (arg, '.');
-	if (s)
-	  *s++ = 0;
-	if (mu_string_to_syslog_facility (arg, &syslog_facility))
-	  argp_error (state, _("unknown facility: %s"), arg);
-	if (s &&
-	    mu_string_to_syslog_priority (s, &syslog_priority))
-	  argp_error (state, _("unknown priority: %s"), s);
-	logger_type = MU_STRERR_SYSLOG;
-	break;
-      }
-      
-    case 'l':
-      {
-	char *s;
-	
-	locus.mu_file = arg;
-	s = strchr (arg, ':');
-	if (s)
-	  {
-	    *s++ = 0;
-	    locus.mu_line = strtoul (s, &s, 10);
-	    if (*s == ':')
-	      {
-		locus.mu_col = strtoul (s + 1, &s, 10);
-		if (*s)
-		  argp_error (state, _("bad column number: %s"), arg);
-	      }
-	    else if (*s)
-	      argp_error (state, _("bad line number: %s"), arg);
-	  }
-	break;
-      }
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
+	}
+      else if (*s)
+	{
+	  mu_parseopt_error (po, _("bad line number: %s"), arg);
+	  exit (po->po_exit_error);
+	}
     }
-  return 0;
 }
 
-static struct argp logger_argp = {
-  logger_options,
-  logger_parse_opt,
-  logger_args_doc,
-  logger_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option logger_options[] = {
+  { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read message from FILE"),
+    mu_c_string, &input_file },
+  { "priority", 'p', N_("FACILITY[.LEVEL]"), MU_OPTION_DEFAULT,
+    N_("log at the specified syslog priority (implies --syslog)"),
+    mu_c_string, NULL, set_priority },
+  { "syslog", 0, NULL, MU_OPTION_DEFAULT,
+    N_("log via syslog"),
+    mu_c_string, NULL, set_syslog },
+  { "stderr", 0, NULL, MU_OPTION_DEFAULT,
+    N_("log to the standard error"),
+    mu_c_string, NULL, set_stderr },  
+  { "severity", 's', N_("SEV"), MU_OPTION_DEFAULT,
+    N_("log at Mailutils severity level SEV"),
+    mu_c_string, NULL, set_severity },
+  { "locus", 'l', N_("FILE:LINE[:COL]"), MU_OPTION_DEFAULT,
+    N_("set locus for logging"),
+    mu_c_string, NULL, set_locus },
+  { "tag", 't', N_("TAG"), MU_OPTION_DEFAULT,
+    N_("set syslog tag"),
+    mu_c_string, &syslog_tag },
+  MU_OPTION_END
 };
 
 int
 mutool_logger (int argc, char **argv)
 {
-  int index;
   mu_stream_t logger, input;
   int rc, mode;
-  
-  if (argp_parse (&logger_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
-  argc -= index;
-  argv += index;
+
+  mu_action_getopt (&argc, &argv, logger_options, logger_docstring,
+		    logger_args_doc);
 
   if (argc && input_file)
     {
diff --git a/mu/mu.c b/mu/mu.c
index 6334414..0b471aa 100644
--- a/mu/mu.c
+++ b/mu/mu.c
@@ -21,58 +21,17 @@
 #include <string.h>
 #include <mailutils/mailutils.h>
 #include <mailutils/tls.h>
-#include "mailutils/libargp.h"
+#include "mailutils/cli.h"
 #include "mu.h"
 
-static char args_doc[] = N_("COMMAND [CMDOPTS]");
-static char doc[] = N_("GNU Mailutils multi-purpose tool.");
-
-static struct argp_option options[] = {
-  { NULL }
+struct mu_cli_setup cli = {
+  .prog_doc = N_("GNU Mailutils multi-purpose tool."),
+  .prog_args = N_("COMMAND [CMDOPTS]"),
+  .inorder = 1,
+  .prog_doc_hook = subcommand_help
 };
 
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static char *
-mu_help_filter (int key, const char *text, void *input)
-{
-  char *s;
-  
-  switch (key)
-    {
-    case ARGP_KEY_HELP_PRE_DOC:
-      s = dispatch_docstring (text);
-      break;
-
-    default:
-      s = (char*) text;
-    }
-  return s;
-}
-
-
-static struct argp argp = {
-  options,
-  parse_opt,
-  args_doc,
-  doc,
-  NULL,
-  mu_help_filter,
-  NULL
-};
-
-static const char *mu_tool_capa[] = {
-  "mailutils",
-  "common",
+static char *capa[] = {
   "debug",
   "locking",
   "mailbox",
@@ -80,26 +39,9 @@ static const char *mu_tool_capa[] = {
   NULL 
 };
 
-struct mu_cfg_param mu_tool_param[] = {
-  { NULL }
-};
-
-int
-mu_help ()
-{
-  char *x_argv[3];
-    
-  x_argv[0] = (char*) mu_program_name;
-  x_argv[1] = "--help";
-  x_argv[2] = NULL;
-  return mu_app_init (&argp, mu_tool_capa, mu_tool_param, 
-		      2, x_argv, 0, NULL, NULL);
-}
-
 int
 main (int argc, char **argv)
 {
-  int index;
   mutool_action_t action;
   
   /* Native Language Support */
@@ -109,16 +51,7 @@ main (int argc, char **argv)
   /* Register the desired mailbox formats.  */
   mu_register_all_mbox_formats ();
 
-#ifdef WITH_TLS
-  mu_gocs_register ("tls", mu_tls_module_init);
-#endif
-  mu_argp_init (NULL, NULL);
-  if (mu_app_init (&argp, mu_tool_capa, mu_tool_param, 
-		   argc, argv, ARGP_IN_ORDER, &index, NULL))
-    exit (1);
-
-  argc -= index;
-  argv += index;
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   if (argc < 1)
     {
@@ -133,16 +66,60 @@ main (int argc, char **argv)
       exit (1);
     }
 
-  /* Disable --version option in action. */
-  argp_program_version = NULL;
-  argp_program_version_hook = NULL;
-
-  /* Reset argv[0] for diagnostic purposes */
-  mu_asprintf (&argv[0], "%s %s", mu_program_name, argv[0]);
-  
   /* Run the action. */
   exit (action (argc, argv));
 }
+
+int
+mu_help (void)
+{
+  char *argv[3];
+  argv[0] = mu_full_program_name;
+  argv[1] = "--help";
+  argv[2] = NULL;
+  mu_cli (2, argv, &cli, capa, NULL, NULL, NULL);
+  return 0;
+} 
+
+void
+mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
+		  char const *docstring, char const *argdoc)
+{
+  struct mu_parseopt po;
+  int flags = MU_PARSEOPT_IMMEDIATE;
+  struct mu_option *options[2];
+  char const *prog_args[2];
+  char *progname;
+  
+  options[0] = opt;
+  options[1] = NULL;
+
+  mu_asprintf (&progname, "%s %s", mu_program_name, (*pargv)[0]);
+  po.po_prog_name = progname;
+  flags |= MU_PARSEOPT_PROG_NAME;
+  
+  po.po_prog_doc = docstring;
+  flags |= MU_PARSEOPT_PROG_DOC;
+
+  if (argdoc)
+    {
+      prog_args[0] = argdoc;
+      prog_args[1] = NULL;
+      po.po_prog_args = prog_args;
+      flags |= MU_PARSEOPT_PROG_ARGS;
+    }
+  
+  po.po_bug_address = PACKAGE_BUGREPORT;
+  flags |= MU_PARSEOPT_BUG_ADDRESS;
+
+  if (mu_parseopt (&po, *pargc, *pargv, options, flags))
+    exit (po.po_exit_error);
+
+  *pargc -= po.po_arg_start;
+  *pargv += po.po_arg_start;
+  
+  mu_parseopt_free (&po);  
+}
 
   
   
diff --git a/mu/mu.h b/mu/mu.h
index 51f1463..c6771c2 100644
--- a/mu/mu.h
+++ b/mu/mu.h
@@ -14,7 +14,17 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#include <mailutils/types.h>
+#if defined(HAVE_CONFIG_H)
+# include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <sys/un.h>
+#include <arpa/inet.h>
+#include <sysexits.h>
+#include <mailutils/mailutils.h>
 
 typedef int (*mutool_action_t) (int argc, char **argv);
 
@@ -40,7 +50,7 @@ mu_stream_t mutool_open_pager (void);
 
 int mu_help (void);
 mutool_action_t dispatch_find_action (const char *name);
-char *dispatch_docstring (const char *text);
+void subcommand_help (mu_stream_t str);
 
 int port_from_sa (struct mu_sockaddr *sa);
 
@@ -64,3 +74,6 @@ int get_port (const char *port_str, int *pn);
 
 int mu_getans (const char *variants, const char *fmt, ...);
 
+void mu_action_getopt (int *pargc, char ***pargv, struct mu_option *opt,
+		       char const *docstring, char const *argdoc);
+
diff --git a/mu/pop.c b/mu/pop.c
index 0ae586f..7a24011 100644
--- a/mu/pop.c
+++ b/mu/pop.c
@@ -14,48 +14,9 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <mailutils/mailutils.h>
 #include "mu.h"
-#include "argp.h"
 
-static char pop_doc[] = N_("mu pop - POP3 client shell.");
 char pop_docstring[] = N_("POP3 client shell");
-static char pop_args_doc[] = "";
-
-static struct argp_option pop_options[] = {
-  { NULL }
-};
-
-static error_t
-pop_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp pop_argp = {
-  pop_options,
-  pop_parse_opt,
-  pop_args_doc,
-  pop_doc,
-  NULL,
-  NULL,
-  NULL
-};
 
 /* Global handle for pop3.  */
 static mu_pop3_t pop3;
@@ -656,13 +617,7 @@ struct mutool_command pop_comtab[] = {
 int
 mutool_pop (int argc, char **argv)
 {
-  int index;
-
-  if (argp_parse (&pop_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
-  
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, NULL, pop_docstring, NULL);
 
   if (argc)
     {
diff --git a/mu/query.c b/mu/query.c
index 6223293..d0016da 100644
--- a/mu/query.c
+++ b/mu/query.c
@@ -14,98 +14,44 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include "argp.h"
 #include "mu.h"
 
-static char query_doc[] = N_("mu query - query configuration values.");
 char query_docstring[] = N_("query configuration values");
 static char query_args_doc[] = N_("path [path...]");
 
 static char *file_name;
-static struct mu_cfg_parse_hints hints;
+int value_option;
+int path_option;
+int verbose_option;
+char *progname;
 
-enum {
-  VALUE_OPTION = 256,
-  PATH_OPTION
-};
-
-static struct argp_option query_options[] = {
-  { "file", 'f', N_("FILE"), 0,
+static struct mu_option query_options[] = {
+  { "file", 'f', N_("FILE"), MU_OPTION_DEFAULT,
     N_("query configuration values from FILE (default mailutils.rc)"),
-    0 },
-  { "value", VALUE_OPTION, NULL, 0,
+    mu_c_string, &file_name },
+  { "value", 0, NULL, MU_OPTION_DEFAULT,
     N_("display parameter values only"),
-    0 },
-  { "program", 'p', N_("NAME"), 0,
+    mu_c_bool, &value_option },
+  { "program", 'p', N_("NAME"), MU_OPTION_DEFAULT,
     N_("set program name for configuration lookup"),
-    0 },
-  { "path", PATH_OPTION, NULL, 0,
-    N_("display parameters as paths") },
-  { "verbose", 'v', NULL, 0,
-    N_("increase output verbosity"), 0},
-  { NULL }
-};
-
-static error_t
-query_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case 'f':
-      file_name = arg;
-      break;
-
-    case 'p':
-      hints.flags |= MU_CFG_PARSE_PROGRAM;
-      hints.program = arg;
-      break;
-      
-    case 'v':
-      hints.flags |= MU_CFG_FMT_LOCUS;
-      break;
-
-    case VALUE_OPTION:
-      hints.flags |= MU_CFG_FMT_VALUE_ONLY;
-      break;
-      
-    case PATH_OPTION:
-      hints.flags |= MU_CFG_FMT_PARAM_PATH;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp query_argp = {
-  query_options,
-  query_parse_opt,
-  query_args_doc,
-  query_doc,
-  NULL,
-  NULL,
-  NULL
+    mu_c_string, &progname },
+  { "path", 0, NULL, MU_OPTION_DEFAULT,
+    N_("display parameters as paths"),
+    mu_c_bool, &path_option },
+  { "verbose", 'v', NULL, MU_OPTION_DEFAULT,
+    N_("increase output verbosity"),
+    mu_c_bool, &verbose_option },
+  MU_OPTION_END
 };
 
 int
 mutool_query (int argc, char **argv)
 {
-  int index;
+  static struct mu_cfg_parse_hints hints;
   mu_cfg_tree_t *tree = NULL;
-  
-  if (argp_parse (&query_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
 
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, query_options, query_docstring,
+		    query_args_doc);
 
   if (argc == 0)
     {
@@ -113,8 +59,21 @@ mutool_query (int argc, char **argv)
       return 1;
     }
 
-  hints.flags |= MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL;
-  hints.site_rcfile = file_name ? file_name : mu_site_rcfile;
+  hints.flags = MU_CFG_PARSE_SITE_RCFILE | MU_PARSE_CONFIG_GLOBAL;
+  hints.site_rcfile = file_name ? file_name : mu_site_config_file ();
+
+  if (progname)
+    {
+      hints.flags |= MU_CFG_PARSE_PROGRAM;
+      hints.program = progname;
+    }
+
+  if (verbose_option)
+    hints.flags |= MU_CFG_FMT_LOCUS;
+  if (value_option)
+    hints.flags |= MU_CFG_FMT_VALUE_ONLY;
+  if (path_option)
+    hints.flags |= MU_CFG_FMT_PARAM_PATH;
   
   if (mu_cfg_parse_config (&tree, &hints))
     return 1;
diff --git a/mu/send.c b/mu/send.c
index a069df0..9a82f20 100644
--- a/mu/send.c
+++ b/mu/send.c
@@ -14,17 +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/>. */
 
-#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 <argp.h>
 #include "mu.h"
 
 static int read_recipients;
@@ -46,59 +35,41 @@ send_address_add (mu_address_t *paddr, const char *value)
   MU_ASSERT (mu_address_union (paddr, addr));
   mu_address_destroy (&addr);
 }
-
-static char send_doc[] = N_("mu send - send a message.");
+
 char send_docstring[] = N_("send a message");
 static char send_args_doc[] = "URL-or-HOST [FILE]";
 
-static struct argp_option send_options[] = {
-  { "from",  'F', N_("ADDRESS"), 0,
-    N_("send mail from this ADDRESS") },
-  { "rcpt",  'T', N_("ADDRESS"), 0,
-    N_("send mail to this ADDRESS") },
-  { "read-recipients", 't', NULL, 0,
-    N_("read recipients from the message") },
-  { NULL }
-};
-
-static error_t
-send_parse_opt (int key, char *arg, struct argp_state *state)
+static void
+set_from_address (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
 {
-  switch (key)
-    {
-    case 'F':
-      MU_ASSERT (mu_address_create_null (&from_addr));
-      send_address_add (&from_addr, arg);
-      break;
-
-    case 'T':
-      send_address_add (&rcpt_addr, arg);
-      break;
-
-    case 't':
-      read_recipients = 1;
-      break;
+  MU_ASSERT (mu_address_create_null (&from_addr));
+  send_address_add (&from_addr, arg);
+}
 
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+set_rcpt_address (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  send_address_add (&rcpt_addr, arg);
 }
 
-static struct argp send_argp = {
-  send_options,
-  send_parse_opt,
-  send_args_doc,
-  send_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option send_options[] = {
+  { "from",  'F', N_("ADDRESS"), MU_OPTION_DEFAULT,
+    N_("send mail from this ADDRESS"),
+    mu_c_string, NULL, set_from_address },
+  { "rcpt",  'T', N_("ADDRESS"), MU_OPTION_DEFAULT,
+    N_("send mail to this ADDRESS"),
+    mu_c_string, NULL, set_rcpt_address },
+  { "read-recipients", 't', NULL, MU_OPTION_DEFAULT,
+    N_("read recipients from the message"),
+    mu_c_bool, &read_recipients },
+  MU_OPTION_END
 };
 
 int
 mutool_send (int argc, char **argv)
 {
-  int index;
   char *infile;
   mu_stream_t instr;
   mu_message_t msg;
@@ -108,12 +79,8 @@ mutool_send (int argc, char **argv)
   
   MU_ASSERT (mu_address_create_null (&rcpt_addr));
   mu_register_all_mailer_formats ();
-  
-  if (argp_parse (&send_argp, argc, argv, 0, &index, NULL))
-    return 1;
 
-  argc -= index;
-  argv += index;
+  mu_action_getopt (&argc, &argv, send_options, send_docstring, send_args_doc);
 
   if (argc < 1)
     {
diff --git a/mu/shell.c b/mu/shell.c
index 30966d9..ff4bd05 100644
--- a/mu/shell.c
+++ b/mu/shell.c
@@ -14,17 +14,9 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
+#include "mu.h"
 #include <signal.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/tls.h>
-#include "mailutils/libargp.h"
 #include "muaux.h"
-#include "mu.h"
 
 #ifdef WITH_READLINE
 # include <readline/readline.h>
diff --git a/mu/smtp.c b/mu/smtp.c
index d9ac79b..bc6d292 100644
--- a/mu/smtp.c
+++ b/mu/smtp.c
@@ -28,34 +28,7 @@
 #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
   {
@@ -958,16 +931,10 @@ struct mutool_command smtp_comtab[] = {
 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;
 
+  mu_action_getopt (&argc, &argv, NULL, smtp_docstring, NULL);
   if (argc)
     {
       mu_error (_("bad arguments"));
diff --git a/mu/util.c b/mu/util.c
index c51243a..8ad5afe 100644
--- a/mu/util.c
+++ b/mu/util.c
@@ -14,14 +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/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <mailutils/mailutils.h>
 #include "mu.h"
 
 int
diff --git a/mu/verbose.c b/mu/verbose.c
index 070b049..53c979e 100644
--- a/mu/verbose.c
+++ b/mu/verbose.c
@@ -14,12 +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/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <mailutils/mailutils.h>
 #include "mu.h"
 
 /* Manipulations with verbosity flags, which are common for pop and imap. */
diff --git a/mu/wicket.c b/mu/wicket.c
index 2855175..7d46125 100644
--- a/mu/wicket.c
+++ b/mu/wicket.c
@@ -14,59 +14,32 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#if defined(HAVE_CONFIG_H)
-# include <config.h>
-#endif
-#include <stdlib.h>
-#include <mailutils/mailutils.h>
-#include <mailutils/libcfg.h>
-#include <argp.h>
-
-static char wicket_doc[] = N_("mu wicket - find matching URL in wicket");
+#include "mu.h"
+
 char wicket_docstring[] = N_("scan wickets for matching URLs");
 static char wicket_args_doc[] = N_("URL");
 
-static struct argp_option wicket_options[] = {
-  { "file",    'f', N_("FILE"), 0, N_("use FILE instead of ~/.mu-tickets") },
-  { "verbose", 'v', NULL,       0, N_("increase output verbosity") },
-  { "quiet",   'q', NULL,       0, N_("suppress any output") },
-  { NULL }
-};
-
 static char *wicket_file = "~/.mu-tickets";
 static int wicket_verbose = 1;
 
-static error_t
-wicket_parse_opt (int key, char *arg, struct argp_state *state)
+static void
+clear_wicket_verbose (struct mu_parseopt *po, struct mu_option *opt,
+		      char const *arg)
 {
-  switch (key)
-    {
-    case 'f':
-      wicket_file = arg;
-      break;
-
-    case 'v':
-      wicket_verbose++;
-      break;
-
-    case 'q':
-      wicket_verbose = 0;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+  wicket_verbose = 0;
 }
 
-static struct argp wicket_argp = {
-  wicket_options,
-  wicket_parse_opt,
-  wicket_args_doc,
-  wicket_doc,
-  NULL,
-  NULL,
-  NULL
+static struct mu_option wicket_options[] = {
+  { "file",    'f', N_("FILE"), MU_OPTION_DEFAULT,
+    N_("use FILE instead of ~/.mu-tickets"),
+    mu_c_string, &wicket_file },
+  { "verbose", 'v', NULL,       MU_OPTION_DEFAULT,
+    N_("increase output verbosity"),
+    mu_c_string, &wicket_verbose },
+  { "quiet",   'q', NULL,       MU_OPTION_DEFAULT,
+    N_("suppress any output"),
+    mu_c_string, NULL, clear_wicket_verbose },
+  { NULL }
 };
 
 
@@ -129,12 +102,8 @@ mutool_wicket (int argc, char **argv)
   mu_stream_t stream;
   int rc, i, exit_code;
   
-  if (argp_parse (&wicket_argp, argc, argv, ARGP_IN_ORDER, &i, NULL))
-    return 1;
-
-  argc -= i;
-  argv += i;
-
+  mu_action_getopt (&argc, &argv, wicket_options, wicket_docstring,
+		    wicket_args_doc);
   if (argc == 0)
     {
       mu_error (_("not enough arguments"));
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 135171c..d62e071 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,37 +25,16 @@ imap4d/signal.c
 imap4d/starttls.c
 imap4d/util.c
 
-lib/gnu/argp-help.c
-lib/gnu/argp-parse.c
-lib/gnu/getopt.c
 lib/mailcap.c
 lib/tcpwrap.c
 lib/strexit.c
 lib/manlock.c
 
-libmu_argp/cmdline.c
-libmu_argp/common.c
-libmu_argp/mu_argp.c
-libmu_argp/sieve.c
-
 libmu_auth/ldap.c
 libmu_auth/radius.c
 libmu_auth/sql.c
 libmu_auth/tls.c
 
-libmu_cfg/acl.c
-libmu_cfg/auth.c
-libmu_cfg/common.c
-libmu_cfg/gsasl.c
-libmu_cfg/init.c
-libmu_cfg/ldap.c
-libmu_cfg/pam.c
-libmu_cfg/radius.c
-libmu_cfg/sieve.c
-libmu_cfg/sql.c
-libmu_cfg/tls.c
-libmu_cfg/virtdomain.c
-
 libmu_sieve/actions.c
 libmu_sieve/comparator.c
 libmu_sieve/conf.c
@@ -117,7 +96,6 @@ libmailutils/cfg/driver.c
 libmailutils/cfg/format.c
 libmailutils/cfg/lexer.l
 libmailutils/cfg/parser.y
-libmailutils/cfg/gocs.c
 
 libmailutils/diag/debug.c
 libmailutils/diag/diag.c
diff --git a/pop3d/Makefile.am b/pop3d/Makefile.am
index 7fea649..792acd4 100644
--- a/pop3d/Makefile.am
+++ b/pop3d/Makefile.am
@@ -51,7 +51,7 @@ if MU_COND_DBM
 endif
 
 pop3d_LDADD = \
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_MH}\
  ${MU_LIB_MAILDIR}\
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index 9329725..adf1a5c 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -104,8 +104,7 @@ static struct mu_option pop3d_options[] = {
   { "daemon", 'd', N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
     N_("runs in daemon mode with a maximum of NUMBER children"),
     mu_c_string, NULL, set_daemon_mode },
-
-  {NULL, 0, NULL, 0, NULL, 0}
+  MU_OPTION_END
 }, *options[] = { pop3d_options, NULL };
 
 static int
@@ -308,7 +307,6 @@ static char *capa[] = {
   "mailbox",
   "locking",
   "logging",
-  "tls",
   NULL
 };
 
@@ -585,7 +583,6 @@ main (int argc, char **argv)
 #ifdef ENABLE_DBM
   set_dbm_safety ();
 #endif
-  mu_cli_capa_register (&mu_cli_capa_tls);
 
   mu_cli (argc, argv, &cli, capa, server, &argc, &argv);
   if (argc)
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index 2765690..6a04976 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -121,6 +121,7 @@ extern int expire_on_exit;
 #include <mailutils/filter.h>
 #include <mailutils/stdstream.h>
 #include <mailutils/stream.h>
+#include "mailutils/syslog.h"
 
 /* For Berkley DB2 APOP password file */
 #ifdef HAVE_DB_H
diff --git a/readmsg/Makefile.am b/readmsg/Makefile.am
index 57c9dc3..66ffef6 100644
--- a/readmsg/Makefile.am
+++ b/readmsg/Makefile.am
@@ -23,7 +23,7 @@ bin_PROGRAMS = readmsg
 readmsg_SOURCES = readmsg.c msglist.c readmsg.h
 
 readmsg_LDADD =\
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
  ${MU_LIB_POP}\
diff --git a/readmsg/readmsg.c b/readmsg/readmsg.c
index bbbabf5..a405452 100644
--- a/readmsg/readmsg.c
+++ b/readmsg/readmsg.c
@@ -21,6 +21,7 @@
 
 #include "readmsg.h"
 #include "mailutils/cli.h"
+#include "mailutils/mu_auth.h"
 #include "mu_umaxtostr.h"
 
 #define WEEDLIST_SEPARATOR " :,"
@@ -94,7 +95,6 @@ static char *readmsg_argp_capa[] = {
   "debug",
   "mailbox",
   "locking",
-  "tls",
   NULL
 };
 
@@ -242,7 +242,7 @@ main (int argc, char **argv)
   mu_register_all_mbox_formats ();
   mu_register_extra_formats ();
 
-  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_auth_register_module (&mu_auth_tls_module);
 
   mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
 
diff --git a/sieve/Makefile.am b/sieve/Makefile.am
index 2a294ba..d51db0c 100644
--- a/sieve/Makefile.am
+++ b/sieve/Makefile.am
@@ -22,7 +22,7 @@ EXTRA_DIST = examples
 bin_PROGRAMS = sieve
 sieve_SOURCES = sieve.c
 sieve_LDADD =\
- ${MU_APP_NEW_LIBRARIES}\
+ ${MU_APP_LIBRARIES}\
  ${MU_LIB_SIEVE}\
  ${MU_LIB_MBOX}\
  ${MU_LIB_IMAP}\
diff --git a/sieve/sieve.c b/sieve/sieve.c
index d3738df..8642fc0 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -44,6 +44,7 @@
 #include <mailutils/nls.h>
 #include <mailutils/tls.h>
 #include <mailutils/cli.h>
+#include <mailutils/mu_auth.h>
 
 #define D_DEFAULT "TPt"
 
@@ -238,7 +239,6 @@ static char *sieve_argp_capa[] = {
   "locking",
   "logging",
   "mailer",
-  "tls",
   "sieve",
   NULL
 };
@@ -394,7 +394,7 @@ main (int argc, char *argv[])
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mu_cli_capa_register (&mu_cli_capa_tls);
+  mu_auth_register_module (&mu_auth_tls_module);
   mu_cli_capa_register (&mu_cli_capa_sieve);
   mu_sieve_debug_init ();
   
diff --git a/sql/sql.c b/sql/sql.c
index 7510592..dddab6f 100644
--- a/sql/sql.c
+++ b/sql/sql.c
@@ -69,7 +69,7 @@ add_disptab (mu_sql_dispatch_t *tab)
 #endif
 
 int
-mu_sql_interface_index (char *name)
+mu_sql_interface_index (char const *name)
 {
   int i;
   //mu_sql_dispatch_t *tab;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Wed Oct 19 15:08:58 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bwwEU-0002Yv-Lv
	for mharc-commit-mailutils@gnu.org; Wed, 19 Oct 2016 15:08:58 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54995)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bwwES-0002X5-0M
	for commit-mailutils@gnu.org; Wed, 19 Oct 2016 15:08:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bwwER-0002b6-6j
	for commit-mailutils@gnu.org; Wed, 19 Oct 2016 15:08:55 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:40453)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bwwER-0002b2-3c
	for commit-mailutils@gnu.org; Wed, 19 Oct 2016 15:08:55 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 7DB7B22014E; Wed, 19 Oct 2016 19:08:54 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-784-g3619df5
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 3dc377159eb6afba231bcbdaf6a2d4331c0c337d
X-Git-Newrev: 3619df585404004c8c695268c8da611ef95d9800
Message-Id: <20161019190854.7DB7B22014E@vcs.savannah.gnu.org>
Date: Wed, 19 Oct 2016 19:08:54 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 19 Oct 2016 19:08: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=3619df585404004c8c695268c8da611ef95d9800

The branch, master has been updated
       via  3619df585404004c8c695268c8da611ef95d9800 (commit)
      from  3dc377159eb6afba231bcbdaf6a2d4331c0c337d (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 3619df585404004c8c695268c8da611ef95d9800
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Wed Oct 19 22:07:58 2016 +0300

    Minor fix

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

Summary of changes:
 libmu_auth/gsasl.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmu_auth/gsasl.c b/libmu_auth/gsasl.c
index e8c50dc..d1f3b54 100644
--- a/libmu_auth/gsasl.c
+++ b/libmu_auth/gsasl.c
@@ -20,6 +20,7 @@
 # include <config.h>
 #endif
 #include <mailutils/cli.h>
+#include <mailutils/mu_auth.h>
 
 #ifdef WITH_GSASL
 
@@ -29,7 +30,6 @@
 #include <unistd.h>
 #include <mailutils/error.h>
 #include <mailutils/errno.h>
-#include <mailutils/mu_auth.h>
 #include <mailutils/nls.h>
 #include <mailutils/stream.h>
 #include <mailutils/gsasl.h>


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Oct 20 01:24:24 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bx5q4-0008H7-4u
	for mharc-commit-mailutils@gnu.org; Thu, 20 Oct 2016 01:24:24 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41158)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bx5q1-0008F6-Mt
	for commit-mailutils@gnu.org; Thu, 20 Oct 2016 01:24:22 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bx5q0-0003Qh-KI
	for commit-mailutils@gnu.org; Thu, 20 Oct 2016 01:24:21 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:45361)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bx5q0-0003QV-Db
	for commit-mailutils@gnu.org; Thu, 20 Oct 2016 01:24:20 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 3586222014E; Thu, 20 Oct 2016 05:24:20 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-786-gfa7ac60
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 3619df585404004c8c695268c8da611ef95d9800
X-Git-Newrev: fa7ac6058b528897684ec2eed9f396da159d856d
Message-Id: <20161020052420.3586222014E@vcs.savannah.gnu.org>
Date: Thu, 20 Oct 2016 05:24:20 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 20 Oct 2016 05:24:23 -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=fa7ac6058b528897684ec2eed9f396da159d856d

The branch, master has been updated
       via  fa7ac6058b528897684ec2eed9f396da159d856d (commit)
       via  f52ed2c7d8e5baa10f04fad38b8d7da1b987da52 (commit)
      from  3619df585404004c8c695268c8da611ef95d9800 (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 fa7ac6058b528897684ec2eed9f396da159d856d
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Thu Oct 20 08:11:34 2016 +0300

    Minor fix in wordwrapper stream
    
    * libmailutils/stream/wordwrap.c (set_margin): Flush the stream
    if the new margin equals the current offset.
    (_wordwrap_write): Fix conditional

commit f52ed2c7d8e5baa10f04fad38b8d7da1b987da52
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Thu Oct 20 07:54:02 2016 +0300

    Minor fix
    
    * mu/ldflags.c: Ignore "cfg" and "argp" keywords.

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

Summary of changes:
 libmailutils/stream/wordwrap.c |   28 +++++++++++++++-------------
 mu/ldflags.c                   |    6 +++---
 2 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/libmailutils/stream/wordwrap.c b/libmailutils/stream/wordwrap.c
index 789966e..fce3359 100644
--- a/libmailutils/stream/wordwrap.c
+++ b/libmailutils/stream/wordwrap.c
@@ -132,7 +132,8 @@ _wordwrap_write (mu_stream_t stream, const char *iptr, size_t isize,
   for (n = 0; n < isize; n++)
     {
       if (str->offset == str->right_margin
-	  || (str->offset > 0 && str->buffer[str->offset - 1] == '\n'))
+	  || (str->offset > str->left_margin
+	      && str->buffer[str->offset - 1] == '\n'))
 	_wordwrap_flush_line (str, iptr[n]);
       if (str->offset == str->left_margin && mu_isblank (iptr[n]))
 	continue;
@@ -178,19 +179,20 @@ set_margin (mu_stream_t stream, unsigned lmargin, int off)
   if (lmargin >= str->right_margin)
     return EINVAL;
 
+  /* Flush the stream if the new margin is set to the left of the current
+     column, or it equals the current column and the character in previous
+     column is a word constituent, or the last character on line is a newline.
+  */
   if (str->offset > str->left_margin
-      && (lmargin < str->offset || str->buffer[str->offset - 1] == '\n'))
-    {
-      str->left_margin = lmargin;
-      _wordwrap_flush (stream);
-    }
-  else
-    {
-      if (lmargin > str->offset)
-	memset (str->buffer + str->offset, ' ', lmargin - str->offset);
-      str->left_margin = lmargin;
-      str->offset = lmargin;
-    }
+      && (lmargin < str->offset
+	  || (lmargin == str->offset && is_word (str->buffer[str->offset - 1]))
+	  || str->buffer[str->offset - 1] == '\n'))
+    _wordwrap_flush (stream);
+
+  if (lmargin > str->offset)
+    memset (str->buffer + str->offset, ' ', lmargin - str->offset);
+  str->left_margin = lmargin;
+  str->offset = lmargin;
 
   return 0;
 }
diff --git a/mu/ldflags.c b/mu/ldflags.c
index 7f52bf2..9559cce 100644
--- a/mu/ldflags.c
+++ b/mu/ldflags.c
@@ -65,8 +65,8 @@ struct lib_descr {
 #ifdef WITH_PYTHON
   { "python", "-lmu_py " PYTHON_LIBS, -1, NOTALL },
 #endif
-  { "cfg",    "-lmu_cfg",  -1, NOTALL },
-  { "argp",   "-lmu_argp", -2, NOTALL },
+  { "cfg",    NULL,  0, 0 },  /* deprecated */
+  { "argp",   NULL,  0, 0 },  /* deprecated */
   { NULL }
 };
 
@@ -100,7 +100,7 @@ add_entry (int level, char *ptr)
 
 /* Sort the entries by their level. */
 void
-sort_entries ()
+sort_entries (void)
 {
   int j;
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Thu Oct 20 09:53:04 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bxDmJ-0005pD-RR
	for mharc-commit-mailutils@gnu.org; Thu, 20 Oct 2016 09:53:03 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:35224)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxDmA-0005gJ-II
	for commit-mailutils@gnu.org; Thu, 20 Oct 2016 09:53:01 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxDm5-0006xi-E7
	for commit-mailutils@gnu.org; Thu, 20 Oct 2016 09:52:54 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:49893)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxDm5-0006xe-AD
	for commit-mailutils@gnu.org; Thu, 20 Oct 2016 09:52:49 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id E3A2B22015E; Thu, 20 Oct 2016 13:52:48 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-787-g53eb681
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: fa7ac6058b528897684ec2eed9f396da159d856d
X-Git-Newrev: 53eb68133eeede20c49445cd4ff58ad6e4becc07
Message-Id: <20161020135248.E3A2B22015E@vcs.savannah.gnu.org>
Date: Thu, 20 Oct 2016 13:52:48 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Thu, 20 Oct 2016 13:53:01 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=53eb68133eeede20c49445cd4ff58ad6e4becc07

The branch, master has been updated
       via  53eb68133eeede20c49445cd4ff58ad6e4becc07 (commit)
      from  fa7ac6058b528897684ec2eed9f396da159d856d (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 53eb68133eeede20c49445cd4ff58ad6e4becc07
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Thu Oct 20 16:25:45 2016 +0300

    Support for single-dash long options (as in MH) and negation for boolean options.
    
    * include/mailutils/opt.h (MU_PARSEOPT_SINGLE_DASH)
    (MU_PARSEOPT_NEGATION): New flags.
    (mu_parseopt) <po_negation, po_long_opt_start>: New fields.
    (mu_option_describe_options): Change signature.
    * libmailutils/opt/help.c (init_usage_vars): Initialize
    long_opt_col depending on the value of MU_PARSEOPT_SINGLE_DASH
    bit.
    (print_option): Handle single-dash long options and boolean
    options with negations.
    (option_summary): Likewise.
    (mu_option_describe_options): Take struct mu_parseopt *
    as its second parameter.
    * libmailutils/opt/opt.c (find_long_option): Handle
    boolean options with negations.  Return also a pointer
    to the mu_option describing the originally used option
    (as opposed to the canonical one returned by the function).
    (parse): Handle single-dash long options.
    (parseopt_init): Initialize po_negation and po_long_opt_start.
    * libmailutils/tests/parseopt.c (parseopt_param): Handle
    MU_PARSEOPT_SINGLE_DASH and MU_PARSEOPT_NEGATION.

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

Summary of changes:
 include/mailutils/opt.h       |   16 +++-
 libmailutils/opt/help.c       |  139 +++++++++++++++++-------------
 libmailutils/opt/opt.c        |  187 ++++++++++++++++++++++++++++-------------
 libmailutils/tests/parseopt.c |    4 +
 4 files changed, 226 insertions(+), 120 deletions(-)

diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index fc40824..972e3ef 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -103,13 +103,17 @@ struct mu_option_cache
 #define MU_PARSEOPT_DATA           0x00400000
 #define MU_PARSEOPT_VERSION_HOOK   0x00800000
 #define MU_PARSEOPT_PROG_DOC_HOOK  0x01000000
+/* Long options start with single dash.  Disables recognition of traditional
+   short options */
+#define MU_PARSEOPT_SINGLE_DASH    0x02000000
+/* Negation prefix is set */
+#define MU_PARSEOPT_NEGATION       0x04000000
 
 /* Reuse mu_parseopt struct initialized previously */
 #define MU_PARSEOPT_REUSE          0x80000000
 /* Mask for immutable flag bits */
 #define MU_PARSEOPT_IMMUTABLE_MASK 0xFFFFF000
 
-
 struct mu_parseopt
 {
   /* Input data: */
@@ -119,6 +123,7 @@ struct mu_parseopt
   struct mu_option **po_optv;      /* Array of ptrs to option structures */ 
   int po_flags;                        
 
+  char *po_negation;               /* Negation prefix for boolean options */
   void *po_data;                   /* Call-specific data */
 
   int po_exit_error;               /* Exit on error with this code */
@@ -145,6 +150,9 @@ struct mu_parseopt
   /* Auxiliary data */
   char *po_cur;                    /* Points to the next character */
   int po_chr;                      /* Single-char option */
+
+  char *po_long_opt_start;         /* Character sequence that starts
+				      long option */
   
   /* The following two keep the position of the first non-optional argument
      and the number of contiguous non-optional arguments after it.
@@ -161,6 +169,7 @@ struct mu_parseopt
   unsigned po_permuted:1;           /* Whether the arguments were permuted */
 };
 
+
 int mu_parseopt (struct mu_parseopt *p,
 		 int argc, char **argv, struct mu_option **optv,
 		 int flags);
@@ -171,8 +180,7 @@ void mu_parseopt_free (struct mu_parseopt *p);
 
 unsigned mu_parseopt_getcolumn (const char *name);
 
-void mu_option_describe_options (mu_stream_t str,
-				 struct mu_option **optbuf, size_t optcnt);
+void mu_option_describe_options (mu_stream_t str, struct mu_parseopt *p);
 void mu_program_help (struct mu_parseopt *p, mu_stream_t str);
 void mu_program_usage (struct mu_parseopt *p, int optsummary, mu_stream_t str);
 void mu_program_version (struct mu_parseopt *po, mu_stream_t str);
@@ -180,4 +188,6 @@ void mu_program_version (struct mu_parseopt *po, mu_stream_t str);
 void mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
 			  char const *arg);
 
+int mu_option_possible_negation (struct mu_parseopt *po, struct mu_option *opt);
+
 #endif
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index 8e54578..9ad20f0 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -30,7 +30,7 @@
 #include <mailutils/stream.h>
 
 unsigned short_opt_col = 2;
-unsigned long_opt_col = 6;
+unsigned long_opt_col; /* Initialized in init_usage_vars */
 /*FIXME: doc_opt_col? */
 unsigned header_col = 1;
 unsigned opt_doc_col = 29;
@@ -170,6 +170,11 @@ init_usage_vars (struct mu_parseopt *po)
   struct mu_wordsplit ws;
   size_t i;
   
+  if (po->po_flags & MU_PARSEOPT_SINGLE_DASH)
+    long_opt_col = 2;
+  else
+    long_opt_col = 6;
+
   fmt = getenv ("ARGP_HELP_FMT");
   if (!fmt)
     return;
@@ -223,11 +228,10 @@ print_opt_arg (mu_stream_t str, struct mu_option *opt, int delim)
 }
 
 static size_t
-print_option (mu_stream_t str,
-	      struct mu_option **optbuf, size_t optcnt, size_t num,
+print_option (mu_stream_t str, struct mu_parseopt *po, size_t num,
 	      int *argsused)
 {
-  struct mu_option *opt = optbuf[num];
+  struct mu_option *opt = po->po_optv[num];
   size_t next, i;
   int delim;
   int first_option = 1;
@@ -240,38 +244,47 @@ print_option (mu_stream_t str,
       if (opt->opt_doc[0])
 	{
 	  set_margin (str, header_col);
-	  mu_stream_printf (str, "%s", gettext (opt->opt_doc));
+	  mu_stream_printf (str, "%s\n", gettext (opt->opt_doc));
 	}
       return num + 1;
     }
 
   /* count aliases */
   for (next = num + 1;
-       next < optcnt && optbuf[next]->opt_flags & MU_OPTION_ALIAS;
+       next < po->po_optc && po->po_optv[next]->opt_flags & MU_OPTION_ALIAS;
        next++);
 
   if (opt->opt_flags & MU_OPTION_HIDDEN)
     return next;
 
-  set_margin (str, short_opt_col); 
-  for (i = num; i < next; i++)
+  if (po->po_flags & MU_PARSEOPT_SINGLE_DASH)
+    {
+      if (!opt->opt_long)
+	return num + 1; /* Ignore erroneous option */
+      set_margin (str, long_opt_col);
+    }
+  else
     {
-      if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]))
+      set_margin (str, short_opt_col); 
+      for (i = num; i < next; i++)
 	{
-	  if (first_option)
-	    first_option = 0;
-	  else
-	    mu_stream_printf (str, ", ");
-	  mu_stream_printf (str, "-%c", optbuf[i]->opt_short);
-	  delim = ' ';
-	  if (opt->opt_arg && dup_args)
-	    print_opt_arg (str, opt, delim);
+	  if (MU_OPTION_IS_VALID_SHORT_OPTION (po->po_optv[i]))
+	    {
+	      if (first_option)
+		first_option = 0;
+	      else
+		mu_stream_printf (str, ", ");
+	      mu_stream_printf (str, "-%c", po->po_optv[i]->opt_short);
+	      delim = ' ';
+	      if (opt->opt_arg && dup_args)
+		print_opt_arg (str, opt, delim);
+	    }
 	}
     }
-
+  
   for (i = num; i < next; i++)
     {
-      if (MU_OPTION_IS_VALID_LONG_OPTION (optbuf[i]))
+      if (MU_OPTION_IS_VALID_LONG_OPTION (po->po_optv[i]))
 	{
 	  if (first_option)
 	    first_option = 0;
@@ -287,8 +300,12 @@ print_option (mu_stream_t str,
 	      first_long_option = 0;
 	    }
 	  
-  	  mu_stream_printf (str, "--%s", optbuf[i]->opt_long);
-	  delim = '=';
+  	  mu_stream_printf (str, "%s", po->po_long_opt_start);
+	  if (mu_option_possible_negation (po, po->po_optv[i]))
+	    mu_stream_printf (str, "[%s]", po->po_negation);
+  	  mu_stream_printf (str, "%s", po->po_optv[i]->opt_long);	  
+	  delim = ((po->po_flags & MU_PARSEOPT_SINGLE_DASH)
+		   && !(opt->opt_flags & MU_OPTION_ARG_OPTIONAL)) ? ' ' : '=';
 	  if (opt->opt_arg && dup_args)
 	    print_opt_arg (str, opt, delim);
 	}
@@ -308,14 +325,13 @@ print_option (mu_stream_t str,
 }
 
 void
-mu_option_describe_options (mu_stream_t str,
-			    struct mu_option **optbuf, size_t optcnt)
+mu_option_describe_options (mu_stream_t str, struct mu_parseopt *po)
 {
   unsigned i;
   int argsused = 0;
 
-  for (i = 0; i < optcnt; )
-    i = print_option (str, optbuf, optcnt, i, &argsused);
+  for (i = 0; i < po->po_optc; )
+    i = print_option (str, po, i, &argsused);
   mu_stream_printf (str, "\n");
 
   if (argsused && dup_args_note)
@@ -334,7 +350,7 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
 {
   mu_stream_t str;
   int rc;
-  
+
   init_usage_vars (po);
 
   rc = mu_wordwrap_stream_create (&str, outstr, 0, rmargin);
@@ -358,7 +374,7 @@ mu_program_help (struct mu_parseopt *po, mu_stream_t outstr)
       mu_stream_printf (str, "\n");
     }
   
-  mu_option_describe_options (str, po->po_optv, po->po_optc);
+  mu_option_describe_options (str, po);
 
   if (po->po_help_hook)
     {
@@ -432,41 +448,44 @@ option_summary (struct mu_parseopt *po, mu_stream_t str)
   
   idxbuf = mu_calloc (optcnt, sizeof (idxbuf[0]));
 
-  /* Print a list of short options without arguments. */
-  for (i = nidx = 0; i < optcnt; i++)
-    if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && !optbuf[i]->opt_arg)
-      idxbuf[nidx++] = i;
-
-  if (nidx)
+  if (!(po->po_flags & MU_PARSEOPT_SINGLE_DASH))
     {
-      qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
-      mu_stream_printf (str, "[-");
-      for (i = 0; i < nidx; i++)
+      /* Print a list of short options without arguments. */
+      for (i = nidx = 0; i < optcnt; i++)
+	if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && !optbuf[i]->opt_arg)
+	  idxbuf[nidx++] = i;
+      
+      if (nidx)
 	{
-	  mu_stream_printf (str, "%c", optbuf[idxbuf[i]]->opt_short);
+	  qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
+	  mu_stream_printf (str, "[-");
+	  for (i = 0; i < nidx; i++)
+	    {
+	      mu_stream_printf (str, "%c", optbuf[idxbuf[i]]->opt_short);
+	    }
+	  mu_stream_printf (str, "%c", ']');
 	}
-      mu_stream_printf (str, "%c", ']');
-    }
 
-  /* Print a list of short options with arguments. */
-  for (i = nidx = 0; i < optcnt; i++)
-    {
-      if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && optbuf[i]->opt_arg)
-	idxbuf[nidx++] = i;
-    }
+      /* Print a list of short options with arguments. */
+      for (i = nidx = 0; i < optcnt; i++)
+	{
+	  if (MU_OPTION_IS_VALID_SHORT_OPTION (optbuf[i]) && optbuf[i]->opt_arg)
+	    idxbuf[nidx++] = i;
+	}
 
-  if (nidx)
-    {
-      qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
-    
-      for (i = 0; i < nidx; i++)
+      if (nidx)
 	{
-	  struct mu_option *opt = optbuf[idxbuf[i]];
-	  const char *arg = gettext (opt->opt_arg);
-	  if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
-	    mu_stream_printf (str, " [-%c[%s]]", opt->opt_short, arg);
-	  else
-	    mu_stream_printf (str, " [-%c %s]", opt->opt_short, arg);
+	  qsort (idxbuf, nidx, sizeof (idxbuf[0]), cmpidx_short);
+	  
+	  for (i = 0; i < nidx; i++)
+	    {
+	      struct mu_option *opt = optbuf[idxbuf[i]];
+	      const char *arg = gettext (opt->opt_arg);
+	      if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
+		mu_stream_printf (str, " [-%c[%s]]", opt->opt_short, arg);
+	      else
+		mu_stream_printf (str, " [-%c %s]", opt->opt_short, arg);
+	    }
 	}
     }
   
@@ -486,11 +505,17 @@ option_summary (struct mu_parseopt *po, mu_stream_t str)
 	  struct mu_option *opt = optbuf[idxbuf[i]];
 	  const char *arg = opt->opt_arg ? gettext (opt->opt_arg) : NULL;
 
-	  mu_stream_printf (str, " [--%s", opt->opt_long);
+	  mu_stream_printf (str, " [%s", po->po_long_opt_start);
+	  if (mu_option_possible_negation (po, opt))
+	    mu_stream_printf (str, "[%s]", po->po_negation);
+	  mu_stream_printf (str, "%s", opt->opt_long);
+
 	  if (opt->opt_arg)
 	    {
 	      if (opt->opt_flags & MU_OPTION_ARG_OPTIONAL)
 		mu_stream_printf (str, "[=%s]", arg);
+	      else if (po->po_flags & MU_PARSEOPT_SINGLE_DASH)
+		mu_stream_printf (str, " %s", arg);
 	      else
 		mu_stream_printf (str, "=%s", arg);
 	    }
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 967cf89..b7dc8d0 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -193,58 +193,94 @@ find_short_option (struct mu_parseopt *po, int chr)
    it in *ARGPTR. */
 struct mu_option *
 find_long_option (struct mu_parseopt *po, char const *optstr,
-		  char **argptr)
+		  struct mu_option **used_opt_ptr,
+		  char **used_value,
+		  char **value)
 {
   size_t i;
-  size_t optlen;
-  size_t ind;
-  int found = 0;
+  size_t optlen;       /* Length of the option in optstr */
+  int found = 0;       /* 1 if the match was found, 2 if option is ambiguous */
+  int neglen;          /* Length of the negation prefix, if any */
+  int neg = 0;         /* 1 if a boolean option is negated */
+  struct mu_option *ret_opt = NULL;
+  struct mu_option *used_opt;
   
   optlen = strcspn (optstr, "=");
+  if (po->po_negation)
+    neglen = strlen (po->po_negation);
   
   for (i = 0; i < po->po_optc; i++)
     {
-      if (MU_OPTION_IS_VALID_LONG_OPTION (po->po_optv[i])
-	  && optlen <= strlen (po->po_optv[i]->opt_long)
-	  && memcmp (po->po_optv[i]->opt_long, optstr, optlen) == 0)
+      if (MU_OPTION_IS_VALID_LONG_OPTION (po->po_optv[i]))
 	{
-	  switch (found)
+	  size_t len = strlen (po->po_optv[i]->opt_long);
+	  struct mu_option *opt = option_unalias (po, i);
+	  
+	  if ((optlen <= len
+	       && memcmp (po->po_optv[i]->opt_long, optstr, optlen) == 0)
+	      || (neg = (mu_option_possible_negation (po, opt)
+			 && optlen <= neglen + len
+			 && memcmp (optstr, po->po_negation, neglen) == 0
+			 && memcmp (optstr + neglen, po->po_optv[i]->opt_long,
+				    optlen - neglen) == 0)))
 	    {
-	    case 0:
-	      ind = i;
-	      found++;
-	      if (optlen == strlen (po->po_optv[i]->opt_long))
-		i = po->po_optc - 1; /* exact match: break the loop */
-	      break;
-
-	    case 1:
-	      if (option_unalias (po, i) == option_unalias (po, ind))
-		continue;
-	      if (po->po_flags & MU_PARSEOPT_IGNORE_ERRORS)
-		return NULL;
-	      mu_parseopt_error (po,
-			   _("option '--%*.*s' is ambiguous; possibilities:"),
-			   optlen, optlen, optstr);
-	      fprintf (stderr, "--%s\n", po->po_optv[ind]->opt_long);
-	      found++;
-
-	    case 2:
-	      fprintf (stderr, "--%s\n", po->po_optv[i]->opt_long);
+	      switch (found)
+		{
+		case 0:
+		  used_opt = po->po_optv[i];
+		  ret_opt = opt;
+		  found++;
+		  if (optlen == len || (neg && optlen == neglen + len))
+		    i = po->po_optc - 1; /* exact match: break the loop */
+		  break;
+		  
+		case 1:
+		  if (opt == ret_opt)
+		    continue;
+		  if (po->po_flags & MU_PARSEOPT_IGNORE_ERRORS)
+		    return NULL;
+		  mu_parseopt_error (po,
+				     _("option '%s%*.*s' is ambiguous; possibilities:"),
+				     po->po_long_opt_start,
+				     optlen, optlen, optstr);
+		  fprintf (stderr, "%s%s%s\n",
+			   po->po_long_opt_start,
+			   neg ? po->po_negation : "",
+			   used_opt->opt_long);
+		  found++;
+		  
+		case 2:
+		  fprintf (stderr, "%s%s%s\n",
+			   po->po_long_opt_start,
+			   neg ? po->po_negation : "",
+			   po->po_optv[i]->opt_long);
+		}
 	    }
 	}
     }
-
+  
   switch (found)
     {
     case 0:
-      mu_parseopt_error (po, _("unrecognized option '--%s'"), optstr);
+      mu_parseopt_error (po, _("unrecognized option '%s%s'"),
+			 po->po_long_opt_start, optstr);
       break;
       
     case 1:
+      *used_opt_ptr = used_opt;
       if (optstr[optlen])
 	++optlen;
-      *argptr = (char *)(optstr + optlen);
-      return option_unalias (po, ind);
+      *used_value = (char *)(optstr + optlen);
+      if (ret_opt->opt_type == mu_c_bool)
+	{
+	  if (neg)
+	    *value = "0";
+	  else
+	    *value = "1";
+	}
+      else
+	*value = NULL;
+      return ret_opt;
 
     case 2:
       break;
@@ -313,7 +349,36 @@ next_opt (struct mu_parseopt *po)
 	  if (!po->po_cur)
 	    return 1;
 	  if (po->po_cur[0] == '-' && po->po_cur[1])
-	    break;
+	    {
+	      if (*++po->po_cur == '-')
+		{
+		  if (*++po->po_cur == 0)
+		    {
+		      /* End of options */
+		      permute (po);
+		      ++po->po_ind;
+		      return 1;
+		    }
+		  
+		  if (po->po_flags & MU_PARSEOPT_SINGLE_DASH)
+		    /* a non-optional argument */;
+		  else
+		    {
+		      /* It's a long option */
+		      po->po_chr = 0;
+		      return 0;
+		    }
+		}
+	      else if (po->po_flags & MU_PARSEOPT_SINGLE_DASH)
+		{
+		  /* Assume single-dash long option */
+		  po->po_chr = 0;
+		  return 0;
+		}
+	      else
+		break;
+	    }
+
 	  if (!(po->po_flags & MU_PARSEOPT_IN_ORDER))
 	    {
 	      if (!po->po_permuted && po->po_arg_count == 0)
@@ -324,21 +389,6 @@ next_opt (struct mu_parseopt *po)
 	  else
 	    return 1;
 	}
-
-      if (*++po->po_cur == '-')
-	{
-	  if (*++po->po_cur == 0)
-	    {
-	      /* End of options */
-	      permute (po);
-	      ++po->po_ind;
-	      return 1;
-	    }
-
-	  /* It's a long option */
-	  po->po_chr = 0;
-	  return 0;
-	}
     }
 
   po->po_chr = *po->po_cur++;
@@ -386,18 +436,18 @@ parse (struct mu_parseopt *po)
   
   while (next_opt (po) == 0)
     {
-      struct mu_option *opt;
-      char *long_opt;
+      struct mu_option *opt, *uopt;
+      char *value;
       
       if (po->po_chr)
 	{
 	  opt = find_short_option (po, po->po_chr);
-	  long_opt = NULL;
+	  uopt = NULL;
+	  value = NULL;
 	}
       else
 	{
-	  long_opt = po->po_cur;
-	  opt = find_long_option (po, long_opt, &po->po_cur);
+	  opt = find_long_option (po, po->po_cur, &uopt, &po->po_cur, &value);
 	}
 
       if (opt)
@@ -417,14 +467,14 @@ parse (struct mu_parseopt *po)
 		arg = po->po_argv[po->po_ind++];
 	      else
 		{
-		  if (long_opt)
+		  if (uopt)
 		    mu_parseopt_error (po,
-				 _("option '--%s' requires an argument"),
-				 long_opt);
+				 _("option '%s%s' requires an argument"),
+				       po->po_long_opt_start, uopt->opt_long);
 		  else
 		    mu_parseopt_error (po,
 				 _("option '-%c' requires an argument"),
-				 po->po_chr);
+				       po->po_chr);
 		  po->po_opterr = po->po_ind;
 		  if (po->po_flags & MU_PARSEOPT_NO_ERREXIT)
 		    {
@@ -437,13 +487,14 @@ parse (struct mu_parseopt *po)
 	    }
 	  else
 	    {
-	      if (long_opt
+	      if (uopt
 		  && po->po_cur[0]
 		  && !(po->po_flags & MU_OPTION_ARG_OPTIONAL))
 		{
 		  mu_parseopt_error (po,
-			       _("option '--%s' doesn't allow an argument"),
-			       long_opt);
+			       _("option '%s%s' doesn't allow an argument"),
+				     po->po_long_opt_start,
+				     uopt->opt_long);
 		  po->po_opterr = po->po_ind;
 		  if (po->po_flags & MU_PARSEOPT_NO_ERREXIT)
 		    {
@@ -455,6 +506,9 @@ parse (struct mu_parseopt *po)
 		}
 	      arg = NULL;
 	    }
+
+	  if (!arg && value)
+	    arg = value;
 	  
 	  add_option_cache (po, opt, arg);
 	}
@@ -515,6 +569,13 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
     po->po_version_hook = NULL;
   if (!(flags & MU_PARSEOPT_PROG_DOC_HOOK))
     po->po_prog_doc_hook = NULL;
+  if (!(flags & MU_PARSEOPT_NEGATION))
+    po->po_negation = NULL;
+  
+  if (flags & MU_PARSEOPT_SINGLE_DASH)
+    po->po_long_opt_start = "-";
+  else
+    po->po_long_opt_start = "--";    
   
   /* Count the options */
   po->po_optc = 0;
@@ -686,3 +747,9 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
 	}
     }
 }
+
+int
+mu_option_possible_negation (struct mu_parseopt *po, struct mu_option *opt)
+{
+  return po->po_negation && opt->opt_type == mu_c_bool && !opt->opt_arg;
+}
diff --git a/libmailutils/tests/parseopt.c b/libmailutils/tests/parseopt.c
index d335823..7b2aade 100644
--- a/libmailutils/tests/parseopt.c
+++ b/libmailutils/tests/parseopt.c
@@ -141,6 +141,10 @@ static struct parseopt_param parseopt_param[] = {
   { "MU_PARSEOPT_EXIT_ERROR", MU_PARSEOPT_EXIT_ERROR,
     mu_c_int, mu_offsetof(struct mu_parseopt, po_exit_error) },
   { "MU_PARSEOPT_VERSION_HOOK", MU_PARSEOPT_VERSION_HOOK, mu_c_void },
+  { "MU_PARSEOPT_SINGLE_DASH", MU_PARSEOPT_SINGLE_DASH, mu_c_void },
+  { "MU_PARSEOPT_NEGATION", MU_PARSEOPT_NEGATION,
+    mu_c_string, mu_offsetof(struct mu_parseopt, po_negation) },
+    
   { NULL }
 };
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Oct 21 11:00:15 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bxbIt-0005EE-H6
	for mharc-commit-mailutils@gnu.org; Fri, 21 Oct 2016 11:00:15 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43333)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxbIf-00058u-E2
	for commit-mailutils@gnu.org; Fri, 21 Oct 2016 11:00:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxbIW-0007Gh-0O
	for commit-mailutils@gnu.org; Fri, 21 Oct 2016 11:00:01 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:36047)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxbIV-0007GQ-QU
	for commit-mailutils@gnu.org; Fri, 21 Oct 2016 10:59:51 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 832CA22015E; Fri, 21 Oct 2016 14:59:51 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-788-gf434857
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 53eb68133eeede20c49445cd4ff58ad6e4becc07
X-Git-Newrev: f434857b8318b05b7036025605ab18cdf3e7c238
Message-Id: <20161021145951.832CA22015E@vcs.savannah.gnu.org>
Date: Fri, 21 Oct 2016 14:59:51 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 21 Oct 2016 15:00:14 -0000

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

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

The branch, master has been updated
       via  f434857b8318b05b7036025605ab18cdf3e7c238 (commit)
      from  53eb68133eeede20c49445cd4ff58ad6e4becc07 (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 f434857b8318b05b7036025605ab18cdf3e7c238
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Fri Oct 21 17:48:26 2016 +0300

    Begin rewriting MH to get rid of argp stuff.
    
    MH utilities will use only single-dash long options.
    
    * include/mailutils/opt.h (mu_option) <opt_default>: New member.
    * libmailutils/opt/opt.c (find_long_option): Improve detection
    of ambiguous options.
    (mu_option_set_value): Use default value (opt_default), if
    supplied.
    * mh/mh_argp.c: Delete.
    * mh/Makefile.am (libmh_a_SOURCES): Remove mh_argp.c
    * mh/mh_getopt.c: Rewrite from scratch using mailutils/opt
    * mh/mh_getopt.h: Likewise.
    * mh/mh.h: Add missing includes
    (mh_read_formfile, mh_alias_read): Change signatures.
    * mh/mh_alias.l (mh_alias_read): Name is const
    * mh/mh_init.c (mh_read_formfile): Name is const.
    
    * mh/ali.c: Convert to mh_getopt.
    * mh/anno.c: Likewise.
    * mh/burst.c: Likewise.
    * mh/comp.c: Likewise.
    * mh/fmtcheck.c: Likewise.
    * mh/folder.c: Likewise.
    * mh/forw.c: Likewise.
    * mh/inc.c: Likewise.
    * mh/install-mh.c: Likewise.
    * mh/mark.c: Likewise.
    * mh/mhl.c: Likewise.
    * mh/scan.c: Likewise.
    
    * mh/tests/burst.at: Don't use double-dash options
    * mh/tests/folder.at: Likewise.

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

Summary of changes:
 include/mailutils/opt.h |    1 +
 libmailutils/opt/opt.c  |   57 ++++++--
 mh/Makefile.am          |    1 -
 mh/ali.c                |   89 ++++---------
 mh/anno.c               |  103 ++++-----------
 mh/burst.c              |  118 ++++-------------
 mh/comp.c               |  202 ++++++++++------------------
 mh/fmtcheck.c           |   85 ++++--------
 mh/folder.c             |  261 ++++++++++++++----------------------
 mh/forw.c               |  282 +++++++++++++--------------------------
 mh/inc.c                |  239 +++++++++++----------------------
 mh/install-mh.c         |   44 ++-----
 mh/mark.c               |  186 +++++++++++++-------------
 mh/mh.h                 |    5 +-
 mh/mh_alias.l           |    2 +-
 mh/mh_argp.c            |  298 -----------------------------------------
 mh/mh_format.c          |    5 +-
 mh/mh_getopt.c          |  335 +++++++++++++++++++++++++----------------------
 mh/mh_getopt.h          |  204 +++--------------------------
 mh/mh_init.c            |    2 +-
 mh/mhl.c                |  155 +++++++---------------
 mh/scan.c               |  136 +++++--------------
 mh/tests/burst.at       |    4 +-
 mh/tests/folder.at      |    4 +-
 24 files changed, 871 insertions(+), 1947 deletions(-)
 delete mode 100644 mh/mh_argp.c

diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 972e3ef..efecd8f 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -47,6 +47,7 @@ struct mu_option
   void *opt_ptr;          /* Data pointer */
   void (*opt_set) (struct mu_parseopt *, struct mu_option *, char const *);
                           /* Function to set the option */
+  char const *opt_default;/* Default value */
 };
 
 #define MU_OPTION_GROUP(text) { NULL, 0, NULL, 0, text }
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index b7dc8d0..fbe2868 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -189,6 +189,31 @@ find_short_option (struct mu_parseopt *po, int chr)
   return NULL;
 }
 
+enum neg_match
+  {
+    neg_nomatch,
+    neg_match_inexact,
+    neg_match_exact
+  };
+  
+static enum neg_match
+negmatch (struct mu_parseopt *po, size_t i, char const *optstr, size_t optlen)
+{
+  if (mu_option_possible_negation (po, po->po_optv[i]))
+    {
+      size_t neglen = strlen (po->po_negation);
+      size_t len = strlen (po->po_optv[i]->opt_long);
+      if (optlen <= neglen + len
+	  && memcmp (optstr, po->po_negation, neglen) == 0
+	  && memcmp (optstr + neglen, po->po_optv[i]->opt_long,
+		     optlen - neglen) == 0)
+	{
+	  return (optlen == neglen + len) ? neg_match_exact : neg_match_inexact;
+	}
+    }
+  return neg_nomatch;
+}
+
 /* Find a descriptor of long option OPTSTR.  If it has argument, return
    it in *ARGPTR. */
 struct mu_option *
@@ -200,14 +225,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
   size_t i;
   size_t optlen;       /* Length of the option in optstr */
   int found = 0;       /* 1 if the match was found, 2 if option is ambiguous */
-  int neglen;          /* Length of the negation prefix, if any */
-  int neg = 0;         /* 1 if a boolean option is negated */
+  enum neg_match neg;  /* 1 if a boolean option is negated */
   struct mu_option *ret_opt = NULL;
   struct mu_option *used_opt;
   
   optlen = strcspn (optstr, "=");
-  if (po->po_negation)
-    neglen = strlen (po->po_negation);
   
   for (i = 0; i < po->po_optc; i++)
     {
@@ -215,14 +237,10 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
 	{
 	  size_t len = strlen (po->po_optv[i]->opt_long);
 	  struct mu_option *opt = option_unalias (po, i);
-	  
+	  neg = neg_nomatch;
 	  if ((optlen <= len
 	       && memcmp (po->po_optv[i]->opt_long, optstr, optlen) == 0)
-	      || (neg = (mu_option_possible_negation (po, opt)
-			 && optlen <= neglen + len
-			 && memcmp (optstr, po->po_negation, neglen) == 0
-			 && memcmp (optstr + neglen, po->po_optv[i]->opt_long,
-				    optlen - neglen) == 0)))
+	      || (neg = negmatch (po, i, optstr, optlen)))
 	    {
 	      switch (found)
 		{
@@ -230,7 +248,7 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
 		  used_opt = po->po_optv[i];
 		  ret_opt = opt;
 		  found++;
-		  if (optlen == len || (neg && optlen == neglen + len))
+		  if (optlen == len || neg == neg_match_exact)
 		    i = po->po_optc - 1; /* exact match: break the loop */
 		  break;
 		  
@@ -247,6 +265,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
 			   po->po_long_opt_start,
 			   neg ? po->po_negation : "",
 			   used_opt->opt_long);
+		  if (neg == neg_nomatch && negmatch (po, i, optstr, optlen))
+		    fprintf (stderr, "%s%s%s\n",
+			     po->po_long_opt_start,
+			     po->po_negation,
+			     po->po_optv[i]->opt_long);
 		  found++;
 		  
 		case 2:
@@ -254,6 +277,11 @@ find_long_option (struct mu_parseopt *po, char const *optstr,
 			   po->po_long_opt_start,
 			   neg ? po->po_negation : "",
 			   po->po_optv[i]->opt_long);
+		  if (neg == neg_nomatch && negmatch (po, i, optstr, optlen))
+		    fprintf (stderr, "%s%s%s\n",
+			     po->po_long_opt_start,
+			     po->po_negation,
+			     po->po_optv[i]->opt_long);
 		}
 	    }
 	}
@@ -719,7 +747,9 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
       
       if (arg == NULL)
 	{
-	  if (opt->opt_arg == NULL)
+	  if (opt->opt_default)
+	    arg = opt->opt_default;
+	  else if (opt->opt_arg == NULL)
 	    arg = "1";
 	  else
 	    {
@@ -737,7 +767,8 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
 	    errtext = mu_strerror (rc);
 
 	  if (opt->opt_long)
-	    mu_parseopt_error (po, "--%s: %s", opt->opt_long, errtext);
+	    mu_parseopt_error (po, "%s%s: %s", po->po_long_opt_start,
+			       opt->opt_long, errtext);
 	  else
 	    mu_parseopt_error (po, "-%c: %s", opt->opt_short, errtext);
 	  free (errmsg);
diff --git a/mh/Makefile.am b/mh/Makefile.am
index 3cca334..91c4985 100644
--- a/mh/Makefile.am
+++ b/mh/Makefile.am
@@ -70,7 +70,6 @@ libmh_a_SOURCES= \
  mboxprop.c\
  mh_alias_gram.c\
  mh_alias_lex.c\
- mh_argp.c\
  mh_getopt.c\
  mh_global.c\
  mh_format.c\
diff --git a/mh/ali.c b/mh/ali.c
index 84fc1d4..d52145a 100644
--- a/mh/ali.c
+++ b/mh/ali.c
@@ -23,73 +23,41 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 
-static char doc[] = N_("GNU MH ali")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH ali");
 static char args_doc[] = N_("ALIAS [ALIAS...]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"alias",  ARG_ALIAS, N_("FILE"), 0,
-   N_("use the additional alias FILE")},
-  {"noalias", ARG_NOALIAS, NULL, 0,
-   N_("do not read the system alias file") },
-  {"list", ARG_LIST, N_("BOOL"),  OPTION_ARG_OPTIONAL,
-   N_("list each address on a separate line") },
-  {"normalize", ARG_NORMALIZE, N_("BOOL"),  OPTION_ARG_OPTIONAL,
-   N_("try to determine the official hostname for each address") },
-  {"user", ARG_USER, N_("BOOL"),  OPTION_ARG_OPTIONAL,
-   N_("list the aliases that expand to given addresses") },
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "alias", MH_OPT_ARG, "aliasfile" },
-  { "noalias", },
-  { "list", MH_OPT_BOOL },
-  { "normalize", MH_OPT_BOOL },
-  { "user", MH_OPT_BOOL },
-  { NULL }
-};
-
 static int list_mode;
 static int user_mode;
 static int normalize_mode;
 static int nolist_mode;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+alias_handler (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARG_ALIAS:
-      mh_alias_read (arg, 1);
-      break;
-
-    case ARG_NOALIAS:
-      nolist_mode = 1;
-      break;
-      
-    case ARG_LIST:
-      list_mode = is_true (arg);
-      break;
-	
-    case ARG_NORMALIZE:
-      normalize_mode = is_true (arg);
-      break;
-
-    case ARG_USER:
-      user_mode = is_true (arg);
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+  mh_alias_read (arg, 1);
 }
 
+static struct mu_option options[] = {
+  { "alias",  0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("use the additional alias FILE"),
+    mu_c_string, NULL, alias_handler },
+  { "noalias", 0, NULL, 0,
+    N_("do not read the system alias file"),
+    mu_c_int, &nolist_mode, NULL, "1" },
+  { "list", 0, NULL,  MU_OPTION_DEFAULT,
+    N_("list each address on a separate line"),
+    mu_c_bool, &list_mode },
+  { "normalize", 0, NULL, MU_OPTION_DEFAULT,
+    N_("try to determine the official hostname for each address"),
+    mu_c_bool, &normalize_mode },
+  { "user", 0, NULL,  MU_OPTION_DEFAULT,
+    N_("list the aliases that expand to given addresses"),
+    mu_c_bool, &user_mode },
+  MU_OPTION_END
+};
+
 static int
-getcols ()
+getcols (void)
 {
   struct winsize ws;
 
@@ -174,17 +142,10 @@ ali_print_name (char *name)
 int
 main (int argc, char **argv)
 {
-  int index;
-  
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
-  argc -= index;
-  argv += index;
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (!nolist_mode)
     mh_read_aliases ();
diff --git a/mh/anno.c b/mh/anno.c
index d047d6b..aa36718 100644
--- a/mh/anno.c
+++ b/mh/anno.c
@@ -19,81 +19,29 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH anno")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH anno");
 static char args_doc[] = N_("[MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  {"inplace", ARG_INPLACE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* annotate the message in place")},
-  {"noinplace", ARG_NOINPLACE, NULL, OPTION_HIDDEN,  "" },
-  {"date", ARG_DATE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("add FIELD: date header") },
-  {"nodate", ARG_NODATE, NULL, OPTION_HIDDEN, "" },
-  {"component", ARG_COMPONENT, N_("FIELD"), 0,
-   N_("add this FIELD to the message header") },
-  {"text", ARG_TEXT, N_("STRING"), 0,
-   N_("field value for the component") },
-  { NULL }
-};
-
-struct mh_option mh_option[] = {
-  { "inplace",   MH_OPT_BOOL },
-  { "date",      MH_OPT_BOOL },
-  { "component", MH_OPT_ARG, "field" },
-  { "text",      MH_OPT_ARG, "body" },
-  { NULL }
-};
-
-static int inplace;       /* Annotate the message in place */
+//static int inplace;       /* Annotate the message in place */
 static int anno_date = 1; /* Add date to the annotation */
 static char *component;   /* header field */
 static char *anno_text;   /* header field value */
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_INPLACE:
-      mh_opt_notimpl_warning ("-inplace");
-      inplace = is_true (arg);
-      break;
-
-    case ARG_NOINPLACE:
-      mh_opt_notimpl_warning ("-noinplace");
-      inplace = 0;
-      break;
-
-    case ARG_DATE:
-      anno_date = is_true (arg);
-      break;
-
-    case ARG_NODATE:
-      anno_date = 0;
-      break;
-
-    case ARG_COMPONENT:
-      component = arg;
-      break;
-
-    case ARG_TEXT:
-      mh_quote (arg, &anno_text);
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
+static struct mu_option options[] = {
+  { "inplace", 0, NULL, MU_OPTION_HIDDEN,
+    N_("annotate the message in place"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+  { "date", 0, NULL, MU_OPTION_DEFAULT,
+    N_("add FIELD: date header"),
+    mu_c_bool, &anno_date },
+  { "component", 0, N_("FIELD"), MU_OPTION_DEFAULT,
+    N_("add this FIELD to the message header"),
+    mu_c_string, &component },
+  { "text", 0, N_("STRING"), MU_OPTION_DEFAULT,
+    N_("field value for the component"),
+    mu_c_string, &anno_text },
+  MU_OPTION_END
+};
 
 int
 anno (size_t n, mu_message_t msg, void *call_data)
@@ -106,17 +54,21 @@ int
 main (int argc, char **argv)
 {
   int rc;
-  int index;
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
   size_t len;
 
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+  if (anno_text)
+    {
+      char *arg = anno_text;
+      mh_quote (arg, &anno_text);
+      free (arg);
+    }
+  
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
 
   if (!component)
@@ -152,9 +104,6 @@ main (int argc, char **argv)
   if (len > 0 && component[len-1] == ':')
     component[len-1] = 0;
   
-  argc -= index;
-  argv += index;
-  
   mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
   rc = mu_msgset_foreach_message (msgset, anno, NULL);
   if (rc)
diff --git a/mh/burst.c b/mh/burst.c
index 28ad2dd..87b067c 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -18,40 +18,9 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH burst")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH burst");
 static char args_doc[] = N_("[MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",        ARG_FOLDER,        N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  {"inplace",      ARG_INPLACE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("replace the source message with the table of contents, insert extracted messages after it") },
-  {"noinplace",    ARG_NOINPLACE,    0, OPTION_HIDDEN, ""},
-  {"quiet",        ARG_QUIET,        N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("be quiet about the messages that are not in digest format") },
-  {"noquiet",      ARG_NOQUIET,      0, OPTION_HIDDEN, ""},
-  {"verbose",      ARG_VERBOSE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("verbosely list the actions taken") },
-  {"noverbose",    ARG_NOVERBOSE,    0, OPTION_HIDDEN, ""},
-  {"recursive",    ARG_RECURSIVE,    N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("recursively expand MIME messages") },
-  {"norecursive",  ARG_NORECURSIVE,  0, OPTION_HIDDEN, ""},
-  {"length",       ARG_LENGTH,       N_("NUMBER"), 0,
-   N_("set minimal length of digest encapsulation boundary (default 1)") },
-  { NULL }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "inplace",    MH_OPT_BOOL },
-  { "quiet",      MH_OPT_BOOL },
-  { "verbose",    MH_OPT_BOOL },
-  { NULL }
-};
-
 /* Command line switches */
 int inplace; 
 int quiet;
@@ -61,59 +30,24 @@ int eb_min_length = 1;  /* Minimal length of encapsulation boundary */
 
 #define VERBOSE(c) do { if (verbose) { printf c; putchar ('\n'); } } while (0)
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_INPLACE:
-      inplace = is_true (arg);
-      break;
-
-    case ARG_NOINPLACE:
-      inplace = 0;
-      break;
-
-    case ARG_LENGTH:
-      eb_min_length = strtoul (arg, NULL, 0);
-      if (eb_min_length == 0)
-	eb_min_length = 1;
-      break;
-      
-    case ARG_VERBOSE:
-      verbose = is_true (arg);
-      break;
-
-    case ARG_NOVERBOSE:
-      verbose = 0;
-      break;
-
-    case ARG_RECURSIVE:
-      recursive = is_true (arg);
-      break;
-      
-    case ARG_NORECURSIVE:
-      recursive = 0;
-      break;
-      
-    case ARG_QUIET:
-      quiet = is_true (arg);
-      break;
-
-    case ARG_NOQUIET:
-      quiet = 0;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+static struct mu_option options[] = {
+  { "inplace",     0,      NULL, MU_OPTION_DEFAULT,
+   N_("replace the source message with the table of contents, insert extracted messages after it"),
+    mu_c_bool, &inplace },
+  { "quiet",       0,      NULL, MU_OPTION_DEFAULT,
+    N_("be quiet about the messages that are not in digest format"),
+    mu_c_bool, &quiet },
+  { "verbose",     0,      NULL, MU_OPTION_DEFAULT,
+    N_("verbosely list the actions taken"),
+    mu_c_bool, &verbose },
+  { "recursive",   0,      NULL, MU_OPTION_DEFAULT,
+    N_("recursively expand MIME messages"),
+    mu_c_bool, &recursive },
+  { "length",      0, N_("NUM"), MU_OPTION_DEFAULT,
+    N_("set minimal length of digest encapsulation boundary (default 1)"),
+    mu_c_int, &eb_min_length },
+  MU_OPTION_END
+};
 
 /* General-purpose data structures */
 struct burst_map
@@ -713,7 +647,7 @@ finalize_inplace (size_t lastuid)
 int
 main (int argc, char **argv)
 {
-  int index, rc;
+  int rc;
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
   const char *tempfolder = mh_global_profile_get ("Temp-Folder", ".temp");
@@ -721,13 +655,11 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
-  argc -= index;
-  argv += index;
-
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+  if (eb_min_length == 0)
+    eb_min_length = 1;
+  
   VERBOSE ((_("Opening folder `%s'"), mh_current_folder ()));
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
   mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
diff --git a/mh/comp.c b/mh/comp.c
index 0697d2f..c80e343 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -21,143 +21,73 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-static char doc[] = N_("GNU MH comp")"\v"
-N_("Options marked with `*' are not yet implemented.\n"
-"Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH comp");
 static char args_doc[] = N_("[MSG]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"build",         ARG_BUILD, 0, 0,
-   N_("build the draft and quit immediately.")},
-  {"draftfolder",   ARG_DRAFTFOLDER, N_("FOLDER"), 0,
-   N_("specify the folder for message drafts")},
-  {"nodraftfolder", ARG_NODRAFTFOLDER, 0, 0,
-   N_("undo the effect of the last --draftfolder option")},
-  {"draftmessage" , ARG_DRAFTMESSAGE, N_("MSG"), 0,
-   N_("invoke the draftmessage facility")},
-  {"folder",        ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  {"file",          ARG_FILE, N_("FILE"), 0,
-   N_("use FILE as the message draft")},
-  {"editor",        ARG_EDITOR, N_("PROG"), 0,
-   N_("set the editor program to use")},
-  {"noedit",        ARG_NOEDIT, 0, 0,
-   N_("suppress the initial edit")},
-  {"form",          ARG_FORM, N_("FILE"), 0,
-   N_("read format from given file")},
-  {"whatnowproc",   ARG_WHATNOWPROC, N_("PROG"), 0,
-   N_("set the replacement for whatnow program")},
-  {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
-   N_("don't run whatnowproc")},
-  {"use",           ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("use draft file preserved after the last session") },
-  {"nouse",         ARG_NOUSE, NULL, OPTION_HIDDEN, ""},
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "build" },
-  { "file",          MH_OPT_ARG, "draftfile" },
-  { "form",          MH_OPT_ARG, "formatfile" },
-  { "draftfolder",   MH_OPT_ARG, "folder" },
-  { "nodraftfolder" },
-  { "draftmessage" },
-  { "editor",        MH_OPT_ARG, "program" },
-  { "noedit" },
-  { "whatnowproc",   MH_OPT_ARG, "program" },
-  { "nowhatnowproc" },
-  { "use" },
-  { NULL }
-};
-
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
 static const char *whatnowproc;
 static int nowhatnowproc;
 char *formfile;
-static int build_only = 0; /* --build flag */
-static int use_draft = 0;  /* --use flag */
+static int build_only = 0; /* -build flag */
+static int use_draft = 0;  /* -use flag */
 static char *draftmessage = "new";
 static const char *draftfolder = NULL;
 static int folder_set; /* Folder is set on the command line */
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARGP_KEY_INIT:
-      draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
-      whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
-      break;
-
-    case ARG_BUILD:
-      build_only = 1;
-      break;
-      
-    case ARG_DRAFTFOLDER:
-      draftfolder = arg;
-      break;
-      
-    case ARG_EDITOR:
-      wh_env.editor = arg;
-      break;
-      
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      folder_set = 1;
-      break;
-
-    case ARG_FORM:
-      mh_find_file (arg, &formfile);
-      break;
-
-    case ARG_DRAFTMESSAGE:
-      draftmessage = arg;
-      break;
-
-    case ARG_USE:
-      use_draft = is_true (arg);
-      draftmessage = "cur";
-      break;
-
-    case ARG_NOUSE:
-      use_draft = 0;
-      break;
-      
-    case ARG_FILE:
-      wh_env.file = mh_expand_name (NULL, arg, NAME_ANY);
-      break;
-	
-    case ARG_NODRAFTFOLDER:
-      draftfolder = NULL;
-      break;
-
-    case ARG_NOEDIT:
-      initial_edit = 0;
-      break;
-      
-    case ARG_WHATNOWPROC:
-      whatnowproc = arg;
-      break;
-
-    case ARG_NOWHATNOWPROC:
-      nowhatnowproc = 1;
-      break;
+  mh_set_current_folder (arg);
+  folder_set = 1;
+}
 
-    case ARGP_KEY_FINI:
-      if (!formfile)
-	mh_find_file ("components", &formfile);
-      break;
-	  
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+set_file (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  wh_env.file = mh_expand_name (NULL, arg, NAME_ANY);
 }
 
+static struct mu_option options[] = {
+  { "build",        0, NULL, MU_OPTION_DEFAULT,
+    N_("build the draft and quit immediately."),
+    mu_c_bool, &build_only },
+  { "draftfolder",  0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder for message drafts"),
+    mu_c_string, &draftfolder },
+  { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("undo the effect of the last --draftfolder option"),
+    mu_c_string, &draftfolder, mh_opt_clear_string },
+  { "draftmessage" , 0, N_("MSG"), MU_OPTION_DEFAULT,
+    N_("invoke the draftmessage facility"),
+    mu_c_string, &draftmessage },
+  { "folder",        0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify folder to operate upon"),
+    mu_c_string, NULL, set_folder },
+  { "file",          0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("use FILE as the message draft"),
+    mu_c_string, NULL, set_file },
+  { "editor",        0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the editor program to use"),
+    mu_c_string, &wh_env.editor },
+  { "noedit",        0, NULL, MU_OPTION_DEFAULT,
+    N_("suppress the initial edit"),
+    mu_c_int, &initial_edit, NULL, "0" },
+  { "form",          0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, &formfile, mh_opt_find_file },
+  { "whatnowproc",   0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the replacement for whatnow program"),
+    mu_c_string, &whatnowproc },
+  { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT,
+    N_("don't run whatnowproc"),
+    mu_c_string, &nowhatnowproc, NULL, "1" },
+  { "use",           0, NULL, MU_OPTION_DEFAULT,
+    N_("use draft file preserved after the last session"),
+    mu_c_bool, &use_draft },
+  MU_OPTION_END
+};
+
 /* Copy Nth message from mailbox MBOX to FILE. */
 int
 copy_message (mu_mailbox_t mbox, size_t n, const char *file)
@@ -201,14 +131,18 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
 int
 main (int argc, char **argv)
 {
-  int index;
-  
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
+  whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
+
+  mh_getopt (&argc, &argv, options, 0,
+	     args_doc, prog_doc, NULL);
+  if (use_draft)
+    draftmessage = "cur";
+  if (!formfile)
+    mh_find_file ("components", &formfile);
   
   if (wh_env.file)
     {
@@ -226,14 +160,14 @@ main (int argc, char **argv)
     {
       if (build_only || !draftfolder)
 	{
-	  switch (argc - index)
+	  switch (argc)
 	    {
 	    case 0:
 	      wh_env.file = mh_expand_name (NULL, "draft", 0);
 	      break;
 
 	    case 1:
-	      wh_env.file = mh_expand_name (NULL, argv[index], 0);
+	      wh_env.file = mh_expand_name (NULL, argv[0], 0);
 	      break;
 	      
 	    default:
@@ -245,7 +179,7 @@ main (int argc, char **argv)
 	{
 	  /* Comp accepts a `file', and it will, if given
 	     `-draftfolder +folder'  treat this arguments  as `msg'. */
-	  if (use_draft || index < argc)
+	  if (use_draft || argc)
 	    {
 	      mu_msgset_t msgset;
 	      mu_mailbox_t mbox;
@@ -253,7 +187,7 @@ main (int argc, char **argv)
 	      mbox = mh_open_folder (draftfolder, 
                                      MU_STREAM_RDWR|MU_STREAM_CREAT);
 	      mh_msgset_parse (&msgset, mbox, 
-	                       argc - index, argv + index,
+	                       argc, argv,
 			       use_draft ? "cur" : "new");
 	      if (!mh_msgset_single_message (msgset))
 		{
@@ -271,13 +205,13 @@ main (int argc, char **argv)
     }
   wh_env.draftfile = wh_env.file;
 
-  if (folder_set && index < argc)
+  if (folder_set && argc)
     {
       mu_msgset_t msgset;
       mu_mailbox_t mbox;
       
       mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
-      mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur");
+      mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
       if (!mh_msgset_single_message (msgset))
 	{
 	  mu_error (_("only one message at a time!"));
@@ -304,7 +238,7 @@ main (int argc, char **argv)
 	}
     }
   
-  /* Exit immediately if --build is given */
+  /* Exit immediately if -build is given */
   if (build_only || nowhatnowproc)
     return 0;
 
diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c
index e938a9a..c3a2b46 100644
--- a/mh/fmtcheck.c
+++ b/mh/fmtcheck.c
@@ -19,37 +19,33 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH fmtcheck")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
-
-/* GNU options */
-static struct argp_option options[] = {
-  {"form",    ARG_FORM, N_("FILE"),   0,
-   N_("read format from given file")},
-  {"format",  ARG_FORMAT, N_("FORMAT"), 0,
-   N_("use this format string")},
-  {"dump",    ARG_DUMP, NULL,     0,
-   N_("dump the listing of compiled format code")},
-  { "debug",  ARG_DEBUG, NULL,     0,
-    N_("enable parser debugging output"),},
-
-  { NULL }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "form",    MH_OPT_ARG, "formatfile" },
-  { "format",  MH_OPT_ARG, "string" },
-  { NULL }
-};
+static char prog_doc[] = N_("GNU MH fmtcheck");
 
 char *format_str;
 static mh_format_t format;
-
-typedef int (*action_fp) (void);
+int dump_option;
+int debug_option;
+
+static struct mu_option options[] = {
+  { "form",    0, N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, &format_str, mh_opt_read_formfile },
+  
+  { "format",  0, N_("FORMAT"), MU_OPTION_DEFAULT,
+    N_("use this format string"),
+    mu_c_string, &format_str },
+  { "dump",    0, NULL,     MU_OPTION_HIDDEN,
+    N_("dump the listing of compiled format code"),
+    mu_c_bool,   &dump_option },
+  { "debug",   0, NULL,     MU_OPTION_DEFAULT,
+    N_("enable parser debugging output"),
+    mu_c_bool,   &debug_option },
+
+  MU_OPTION_END
+};
 
 static int
-action_dump ()
+action_dump (void)
 {
   if (!format_str)
     {
@@ -60,49 +56,18 @@ action_dump ()
   return 0;
 }
 
-static action_fp action = action_dump;
-
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FORM:
-      mh_read_formfile (arg, &format_str);
-      break;
-
-    case ARG_FORMAT:
-      format_str = arg;
-      break;
-
-    case ARG_DUMP:
-      action = action_dump;
-      break;
-
-    case ARG_DEBUG:
-      mh_format_debug (1);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
 int
 main (int argc, char **argv)
 {
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, NULL, doc,
-		 opt_handler, NULL, NULL);
-
+  mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL);
+  mh_format_debug (debug_option);
   if (format_str && mh_format_parse (format_str, &format))
     {
       mu_error (_("Bad format string"));
       exit (1);
     }
-  return (*action) ();
+  return action_dump ();
 }
diff --git a/mh/folder.c b/mh/folder.c
index 59f6aa8..e68a624 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -28,78 +28,16 @@
 
 #include <dirent.h>
 
-static char doc[] = N_("GNU MH folder")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH folder");
 static char args_doc[] = N_("[ACTION] [MSG]");
 
-static struct argp_option options[] = {
-  {N_("Actions are:"), 0, 0, OPTION_DOC, NULL, 0 },
-  {"print", ARG_PRINT, NULL, 0,
-   N_("list the folders (default)"), 1 },
-  {"list",  ARG_LIST,  NULL, 0,
-   N_("list the contents of the folder stack"), 1},
-  {"pack",  ARG_PACK,  N_("NUMBER"), OPTION_ARG_OPTIONAL,
-   N_("remove holes in message numbering, begin numbering from NUMBER (default: first message number)"), 1},
-  {"push",  ARG_PUSH,  N_("FOLDER"), OPTION_ARG_OPTIONAL,
-    N_("push the folder on the folder stack. If FOLDER is specified, it is pushed. "
-       "Otherwise, if a folder is given in the command line (via + or --folder), "
-       "it is pushed on stack. Otherwise, the current folder and the top of the folder "
-       "stack are exchanged"), 1},
-  {"pop",   ARG_POP,    NULL, 0,
-   N_("pop the folder off the folder stack"), 1},
-  
-  {N_("Options are:"), 0, 0, OPTION_DOC, NULL, 2 },
-  
-  {"folder", ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon"), 3},
-  {"all",    ARG_ALL,    NULL, 0,
-   N_("list all folders"), 3},
-  {"create", ARG_CREATE, N_("BOOL"), OPTION_ARG_OPTIONAL, 
-    N_("create non-existing folders"), 3},
-  {"nocreate", ARG_NOCREATE, NULL, OPTION_HIDDEN, ""},
-  {"fast",   ARG_FAST, N_("BOOL"), OPTION_ARG_OPTIONAL, 
-    N_("list only the folder names"), 3},
-  {"nofast", ARG_NOFAST, NULL, OPTION_HIDDEN, ""},
-  {"header", ARG_HEADER, N_("BOOL"), OPTION_ARG_OPTIONAL, 
-    N_("print the header line"), 3},
-  {"noheader", ARG_NOHEADER, NULL, OPTION_HIDDEN, ""},
-  {"recurse",ARG_RECURSIVE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("scan folders recursively"), 3},
-  {"norecurse", ARG_NORECURSIVE, NULL, OPTION_HIDDEN, ""},
-  {"total",  ARG_TOTAL, N_("BOOL"), OPTION_ARG_OPTIONAL, 
-    N_("output the total statistics"), 3},
-  {"nototal", ARG_NOTOTAL, NULL, OPTION_HIDDEN, ""},
-  {"verbose", ARG_VERBOSE, NULL, 0,
-   N_("verbosely list actions taken"), 3},
-  {"dry-run", ARG_DRY_RUN, NULL, 0,
-   N_("do nothing, print what would be done (with --pack)"), 3},
-   
-  {NULL},
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "print" },
-  { "list" },
-  { "push" },
-  { "pop" },
-  { "all" },
-  { "pack" },
-  { "create",  MH_OPT_BOOL },
-  { "fast",    MH_OPT_BOOL },
-  { "header",  MH_OPT_BOOL },
-  { "recurse", MH_OPT_BOOL },
-  { "total",   MH_OPT_BOOL },
-  { NULL }
-};
-
-typedef int (*folder_action) ();
+typedef int (*folder_action) (void);
 
-static int action_print ();
-static int action_list ();
-static int action_push ();
-static int action_pop ();
-static int action_pack ();
+static int action_print (void);
+static int action_list (void);
+static int action_push (void);
+static int action_pop (void);
+static int action_pack (void);
 static folder_action action = action_print;
 
 int show_all = 0; /* List all folders. Raised by --all switch */
@@ -121,110 +59,105 @@ const char *push_folder; /* Folder name to push on stack */
 const char *mh_seq_name; /* Name of the mh sequence file (defaults to
 			    .mh_sequences) */
 int has_folder;    /* Folder has been explicitely given */
+int recurse_option = 0;
 size_t max_depth = 1;  /* Maximum recursion depth (0 means infinity) */ 
 
 #define OPTION_IS_SET(opt) ((opt) == -1 ? show_all : opt)
 
-static int
-opt_handler (int key, char *arg, struct argp_state *state)
+void
+set_action (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
+  if (strcmp (opt->opt_long, "print") == 0)
+    action = action_print;
+  else if (strcmp (opt->opt_long, "pack") == 0)
     {
-    case ARG_DRY_RUN:
-      dry_run++;
-      break;
-	
-    case ARG_PACK:
       action = action_pack;
       if (arg)
 	{
-	  char *p;
-	  pack_start = strtoul (arg, &p, 10);
-	  if (*p)
-	    argp_error (state, _("invalid number"));
+	  if (mu_str_to_c (arg, mu_c_size, &pack_start, NULL))
+	    {
+	      mu_parseopt_error (po, _("%s: invalid number"), arg);
+	      exit (po->po_exit_error);
+	    }
 	}
-      break;
-      
-    case ARG_PRINT:
-      action = action_print;
-      break;
-      
-    case ARG_LIST:
-      action = action_list;
-      break;
-
-    case ARG_PUSH:
+    }
+  else if (strcmp (opt->opt_long, "list") == 0)
+    action = action_list;
+  else if (strcmp (opt->opt_long, "push") == 0)
+    {
       action = action_push;
       if (arg)
 	{
 	  push_folder = mh_current_folder ();
 	  mh_set_current_folder (arg);
 	}
-      break;
-      
-    case ARG_POP:
-      action = action_pop;
-      break;
-      
-    case ARG_ALL:
-      show_all = 1;
-      break;
-
-    case ARG_CREATE:
-      create_flag = is_true (arg);
-      break;
-
-    case ARG_NOCREATE:
-      create_flag = 0;
-      
-    case ARG_FAST:
-      fast_mode = is_true (arg);
-      break;
-
-    case ARG_NOFAST:
-      fast_mode = 0;
-      break;
-      
-    case ARG_HEADER:
-      print_header = is_true (arg);
-      break;
-
-    case ARG_NOHEADER:
-      print_header = 0;
-      break;
-      
-    case ARG_RECURSIVE:
-      max_depth = is_true (arg) ? 0 : 1;
-      break;
-
-    case ARG_NORECURSIVE:
-      max_depth = 0;
-      break;
-      
-    case ARG_TOTAL:
-      print_total = is_true (arg);
-      break;
-
-    case ARG_NOTOTAL:
-      print_total = 0;
-      break;
-      
-    case ARG_FOLDER:
-      has_folder = 1;
-      push_folder = mh_current_folder ();
-      mh_set_current_folder (arg);
-      break;
-      
-    case ARG_VERBOSE:
-      verbose++;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
     }
-  return 0;
+  else if (strcmp (opt->opt_long, "pop") == 0)
+    action = action_pop;
+  else
+    abort ();
+}
+
+void
+set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  has_folder = 1;
+  push_folder = mh_current_folder ();
+  mh_set_current_folder (arg);
 }
 
+static struct mu_option options[] = {
+  MU_OPTION_GROUP (N_("Actions are:")),
+  { "print", 0, NULL, MU_OPTION_DEFAULT,
+    N_("list the folders (default)"),
+    mu_c_string, NULL, set_action },
+  { "list",   0, NULL, MU_OPTION_DEFAULT,
+    N_("list the contents of the folder stack"),
+    mu_c_string, NULL, set_action },
+  { "pack",   0, N_("NUMBER"), MU_OPTION_ARG_OPTIONAL,
+    N_("remove holes in message numbering, begin numbering from NUMBER (default: first message number)"),
+    mu_c_string, NULL, set_action },
+  { "push",   0, N_("FOLDER"), MU_OPTION_ARG_OPTIONAL,
+    N_("push the folder on the folder stack. If FOLDER is specified, it is pushed. "
+       "Otherwise, if a folder is given in the command line (via + or --folder), "
+       "it is pushed on stack. Otherwise, the current folder and the top of the folder "
+       "stack are exchanged"),
+    mu_c_string, NULL, set_action },
+  { "pop",    0, NULL, MU_OPTION_DEFAULT,
+    N_("pop the folder off the folder stack"), 
+    mu_c_string, NULL, set_action },
+  
+  MU_OPTION_GROUP (N_("Options are:")),
+  
+  { "folder", 0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify folder to operate upon"),
+    mu_c_string, NULL, set_folder },
+  { "all",    0,    NULL, MU_OPTION_DEFAULT,
+    N_("list all folders"),
+    mu_c_bool, &show_all },
+  { "create", 0, NULL, MU_OPTION_DEFAULT, 
+    N_("create non-existing folders"),
+    mu_c_bool, &create_flag },
+  { "fast",   0, NULL, MU_OPTION_DEFAULT, 
+    N_("list only the folder names"),
+    mu_c_bool, &fast_mode },
+  { "header", 0, NULL, MU_OPTION_DEFAULT, 
+    N_("print the header line"),
+    mu_c_bool, &print_header },
+  { "recurse",0, NULL, MU_OPTION_DEFAULT,
+    N_("scan folders recursively"),
+    mu_c_bool, &recurse_option },
+  { "total",  0, NULL, MU_OPTION_DEFAULT, 
+    N_("output the total statistics"),
+    mu_c_bool, &print_total },
+  { "verbose", 0, NULL, MU_OPTION_DEFAULT,
+    N_("verbosely list actions taken"),
+    mu_c_bool, &verbose },
+  { "dry-run", 0, NULL, MU_OPTION_DEFAULT,
+    N_("do nothing, print what would be done (with --pack)"),
+    mu_c_bool, &dry_run },
+  MU_OPTION_END
+};
 
 /* ************************************************************* */
 /* Printing */
@@ -430,19 +363,19 @@ _folder_name_printer (void *item, void *data)
 }
 
 static void
-print_all ()
+print_all (void)
 {
   mu_list_foreach (folder_info_list, _folder_info_printer, NULL);
 }
 
 static void
-print_fast ()
+print_fast (void)
 {
   mu_list_foreach (folder_info_list, _folder_name_printer, NULL);
 }
 
 static int
-action_print ()
+action_print (void)
 {
   const char *folder_dir = mu_folder_directory ();
   mh_seq_name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE);
@@ -502,7 +435,7 @@ action_print ()
 /* Listing */
 
 static int
-action_list ()
+action_list (void)
 {
   const char *stack = mh_global_context_get ("Folder-Stack", NULL);
 
@@ -598,7 +531,7 @@ pop_val (size_t *pc, char ***pv)
 }
   
 static int
-action_push ()
+action_push (void)
 {
   size_t c;
   char **v;
@@ -623,7 +556,7 @@ action_push ()
 }
 
 static int
-action_pop ()
+action_pop (void)
 {
   size_t c;
   char **v;
@@ -849,7 +782,7 @@ fixup_private (const char *name, const char *value, void *data)
 }
 
 int
-action_pack ()
+action_pack (void)
 {
   const char *folder_dir = mh_expand_name (NULL, mh_current_folder (), 
                                            NAME_ANY);
@@ -959,9 +892,9 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
+  if (recurse_option)
+    max_depth = 0;
 
   /* If  folder  is invoked by a name ending with "s" (e.g.,  folders),
      `-all'  is  assumed */
diff --git a/mh/forw.c b/mh/forw.c
index 56c0c82..7c25ea8 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -19,79 +19,9 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH forw")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH forw");
 static char args_doc[] = N_("[MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"annotate",      ARG_ANNOTATE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("add Forwarded: header to each forwarded message")},
-  {"build",         ARG_BUILD,         0, 0,
-   N_("build the draft and quit immediately")},
-  {"draftfolder",   ARG_DRAFTFOLDER,   N_("FOLDER"), 0,
-   N_("specify the folder for message drafts")},
-  {"nodraftfolder", ARG_NODRAFTFOLDER, 0, 0,
-   N_("undo the effect of the last --draftfolder option")},
-  {"draftmessage" , ARG_DRAFTMESSAGE,  N_("MSG"), 0,
-   N_("invoke the draftmessage facility")},
-  {"folder",        ARG_FOLDER,        N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  {"editor",        ARG_EDITOR,        N_("PROG"), 0,
-   N_("set the editor program to use")},
-  {"noedit",        ARG_NOEDIT,        0, 0,
-   N_("suppress the initial edit")},
-  {"file",          ARG_FILE, N_("FILE"), 0,
-   N_("read message from FILE")},
-  {"format",        ARG_FORMAT,        N_("BOOL"), 0, 
-   N_("format messages")},
-  {"noformat",      ARG_NOFORMAT,      NULL, 0,
-   N_("undo the effect of the last --format option") },
-  {"form",          ARG_FORM,          N_("FILE"), 0,
-   N_("read format from given file")},
-  {"filter",        ARG_FILTER,        N_("FILE"), 0,
-  N_("use filter FILE to preprocess the body of the message") },
-  {"nofilter",      ARG_NOFILTER,      NULL, 0,
-   N_("undo the effect of the last --filter option") },
-  {"inplace",       ARG_INPLACE,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* annotate the message in place")},
-  {"noinplace",     ARG_NOINPLACE,     0,          OPTION_HIDDEN, "" },
-  {"mime",          ARG_MIME,          N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("use MIME encapsulation") },
-  {"nomime",        ARG_NOMIME,        NULL, OPTION_HIDDEN, "" },
-  {"width", ARG_WIDTH, N_("NUMBER"), 0, N_("Set output width")},
-  {"whatnowproc",   ARG_WHATNOWPROC,   N_("PROG"), 0,
-   N_("set the replacement for whatnow program")},
-  {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
-   N_("don't run whatnowproc")},
-  {"use",           ARG_USE,           N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("use draft file preserved after the last session") },
-  {"nouse",         ARG_NOUSE,         N_("BOOL"), OPTION_HIDDEN, "" },
-
-  {NULL},
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "annotate",      MH_OPT_BOOL },
-  { "build" },
-  { "file",          MH_OPT_ARG, "msgfile" },
-  { "form",          MH_OPT_ARG, "formatfile" },
-  { "format",        MH_OPT_BOOL },
-  { "draftfolder",   MH_OPT_ARG, "folder" },
-  { "nodraftfolder" },
-  { "draftmessage" },
-  { "editor",        MH_OPT_ARG, "program" },
-  { "noedit" },
-  { "filter",        MH_OPT_ARG, "program" },
-  { "inplace",       MH_OPT_BOOL },
-  { "whatnowproc",   MH_OPT_ARG, "program" },
-  { "nowhatnowproc" },
-  { "mime",          MH_OPT_BOOL },
-  { NULL }
-};
-
 enum encap_type
   {
     encap_clear,
@@ -120,123 +50,99 @@ static char *input_file;        /* input file name (--file option) */
 static mu_msgset_t msgset;
 static mu_mailbox_t mbox;
 
-static int
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_filter (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARGP_KEY_INIT:
-      draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
-      whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
-      break;
-
-    case ARG_ANNOTATE:
-      annotate = is_true (arg);
-      break;
-      
-    case ARG_BUILD:
-      build_only = 1;
-      break;
-
-    case ARG_FILE:
-      input_file = arg;
-      break;
-      
-    case ARG_DRAFTFOLDER:
-      draftfolder = arg;
-      break;
-
-    case ARG_NODRAFTFOLDER:
-      draftfolder = NULL;
-      break;
-      
-    case ARG_DRAFTMESSAGE:
-      draftmessage = arg;
-      break;
-
-    case ARG_USE:
-      use_draft = is_true (arg);
-      break;
-
-    case ARG_NOUSE:
-      use_draft = 0;
-      break;
-
-    case ARG_WIDTH:
-      width = strtoul (arg, NULL, 0);
-      if (!width)
-	{
-	  argp_error (state, _("invalid width"));
-	  exit (1);
-	}
-      break;
-
-    case ARG_EDITOR:
-      wh_env.editor = arg;
-      break;
-      
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
+  mh_find_file (arg, &mhl_filter_file);
+  encap = encap_mhl;
+}
 
-    case ARG_FORM:
-      mh_find_file (arg, &formfile);
-      break;
+static void
+clear_filter (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  mhl_filter_file = NULL;
+  encap = encap_clear;
+}
 
-    case ARG_FORMAT:
-      if (is_true (arg))
-	{
-	  encap = encap_mhl;
-	  mh_find_file ("mhl.forward", &mhl_filter_file);
-	}
-      else
-	encap = encap_clear;
-      break;
-      
-    case ARG_NOFORMAT:
-      encap = encap_clear;
-      break;
+static void
+set_mime (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (strcmp (arg, "1") == 0)
+    encap = encap_mime;
+  else
+    encap = encap_clear;
+}
 
-    case ARG_FILTER:
-      mh_find_file (arg, &mhl_filter_file);
+static void
+set_format (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (arg)
+    {
       encap = encap_mhl;
-      break;
-	
-    case ARG_MIME:
-      if (is_true (arg))
-	{
-	  encap = encap_mime;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOMIME:
-      if (encap == encap_mime)
-	encap = encap_clear;
-      break;
-      
-    case ARG_INPLACE:
-      mh_opt_notimpl_warning ("-inplace");
-      break;
-
-    case ARG_WHATNOWPROC:
-      whatnowproc = arg;
-      break;
-
-    case ARG_NOWHATNOWPROC:
-      nowhatnowproc = 1;
-      break;
-
-    case ARGP_KEY_FINI:
-      if (!formfile)
-	mh_find_file ("forwcomps", &formfile);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
+      mh_find_file ("mhl.forward", &mhl_filter_file);
     }
-  return 0;
+  else
+    encap = encap_clear;
 }
 
+static struct mu_option options[] = {
+  { "annotate",      0,      NULL, MU_OPTION_DEFAULT,
+    N_("add Forwarded: header to each forwarded message"),
+    mu_c_bool, &annotate },
+  { "build",         0,      NULL, MU_OPTION_DEFAULT,
+    N_("build the draft and quit immediately"),
+    mu_c_bool, &build_only },
+  { "draftfolder",   0,      N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder for message drafts"),
+    mu_c_string, &draftfolder },
+  { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("undo the effect of the last --draftfolder option"),
+    mu_c_string, &draftfolder, mh_opt_clear_string },
+  { "draftmessage" , 0, N_("MSG"), MU_OPTION_DEFAULT,
+    N_("invoke the draftmessage facility"),
+    mu_c_string, &draftmessage },
+  { "editor",        0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the editor program to use"),
+    mu_c_string, &wh_env.editor },
+  { "noedit",        0, NULL, MU_OPTION_DEFAULT,
+    N_("suppress the initial edit"),
+    mu_c_int, &initial_edit, NULL, "0" },
+  { "file",          0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read message from FILE"),
+    mu_c_string, &input_file },
+  { "format",        0, NULL, MU_OPTION_DEFAULT, 
+    N_("format messages"),
+    mu_c_bool, NULL, set_format },
+  { "form",          0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, &formfile, mh_opt_find_file },
+  { "filter",        0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("use filter FILE to preprocess the body of the message"),
+    mu_c_string, NULL, set_filter },
+  { "nofilter",      0, NULL, MU_OPTION_DEFAULT,
+   N_("undo the effect of the last --filter option"),
+    mu_c_string, NULL, clear_filter },
+  { "inplace",       0, NULL, MU_OPTION_HIDDEN,
+    N_("annotate the message in place"),
+    mu_c_bool, NULL, mh_opt_notimpl_warning },
+  { "mime",          0, NULL, MU_OPTION_DEFAULT,
+    N_("use MIME encapsulation"),
+    mu_c_bool, NULL, set_mime },
+  { "width",         0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("Set output width"),
+    mu_c_int, &width },
+  { "whatnowproc",   0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the replacement for whatnow program"),
+    mu_c_string, &whatnowproc },
+  { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT,
+    N_("don't run whatnowproc"),
+    mu_c_int, &nowhatnowproc, NULL, "1" },
+  { "use",           0, NULL, MU_OPTION_DEFAULT,
+    N_("use draft file preserved after the last session"),
+    mu_c_bool, &use_draft },
+  MU_OPTION_END
+};
+
 struct format_data
 {
   int num;
@@ -475,18 +381,18 @@ finish_draft ()
 int
 main (int argc, char **argv)
 {
-  int index, rc;
+  int rc;
 
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
-  argc -= index;
-  argv += index;
-
+  draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
+  whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+  if (!formfile)
+    mh_find_file ("forwcomps", &formfile);
+  
   if (input_file)
     {
       if (encap == encap_mime)
diff --git a/mh/inc.c b/mh/inc.c
index 579f34f..f6fed0f 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -20,71 +20,14 @@
 #include <mh.h>
 #include "muscript.h"
 
-static char doc[] = N_("GNU MH inc")"\v"
-N_("Debug flags are:\n\
+static char prog_doc[] = N_("GNU MH inc");
+static char extra_doc[] = N_("Debug flags are:\n\
   g - guile stack traces\n\
   t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
   i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
-  l - sieve action logs\n\n\
-Use -help to obtain the list of traditional MH options.");
+  l - sieve action logs");
 static char args_doc[] = N_("[+FOLDER]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"file",    ARG_FILE, N_("FILE"),   0,
-   N_("incorporate mail from named file")},
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to incorporate mail to")},
-  {"audit",   ARG_AUDIT, N_("FILE"), 0,
-   N_("enable audit")},
-  {"noaudit", ARG_NOAUDIT, 0, 0,
-   N_("disable audit")},
-  {"changecur", ARG_CHANGECUR, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("mark first incorporated message as current (default)")},
-  {"nochangecur", ARG_NOCHANGECUR, NULL, OPTION_HIDDEN, ""},
-  {"form",    ARG_FORM, N_("FILE"),   0,
-   N_("read format from given file")},
-  {"format",  ARG_FORMAT, N_("FORMAT"), 0,
-   N_("use this format string")},
-  {"truncate", ARG_TRUNCATE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("truncate source mailbox after incorporating (default)")},
-  {"notruncate", ARG_NOTRUNCATE, NULL, OPTION_HIDDEN, ""},
-  {"moveto",  ARG_MOVETO, N_("MAILBOX"), 0,
-   N_("move incorporated messages to MAILBOX instead of deleting them") },
-  {"width",   ARG_WIDTH, N_("NUMBER"), 0,
-   N_("set output width")},
-  {"quiet",   ARG_QUIET, 0,        0,
-   N_("be quiet")},
-  {"notify",  ARG_NOTIFY,N_("BOOL"),   OPTION_ARG_OPTIONAL,
-   N_("enable biff notification"), },
-  {"language",ARG_LANG,  N_("LANG"), 0,
-   N_("set language for the --script option") },
-  {"script",  ARG_SCRIPT,N_("FILE"), 0,
-   N_("filter incoming messages using script FILE") },
-  {"debug",   ARG_DEBUG, N_("FLAGS"), 0,
-   N_("enable debugging") },   
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "audit",     MH_OPT_ARG, "audit-file" },
-  { "noaudit" },
-  { "changecur", MH_OPT_BOOL },
-  { "file",      MH_OPT_ARG, "input-file" },
-  { "form",      MH_OPT_ARG, "format-file" },
-  { "format",    MH_OPT_ARG, "string" },
-  { "truncate",  MH_OPT_BOOL },
-  { "moveto",    MH_OPT_ARG, "folder" },
-  { "width",     MH_OPT_ARG, "number" },
-  { "notify",    MH_OPT_BOOL },
-  { "quiet" },
-  { "language",  MH_OPT_ARG, "lang" },
-  { "script",    MH_OPT_ARG, "file" },
-  { "debug",     MH_OPT_ARG, "flags" },
-  { NULL }
-};
-
 static char *format_str = mh_list_format;
 static int width = 80;
 static mu_list_t input_file_list;
@@ -99,114 +42,89 @@ static const char *move_to_mailbox;
 static const char *script_file;
 static const char *script_lang;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+add_file (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
   int rc;
-  char *p;
-  
-  switch (key)
+  if (!input_file_list)
     {
-    case ARGP_KEY_FINI:
-      if (!append_folder)
-	append_folder = mh_global_profile_get ("Inbox", "inbox");
-      break;
-
-    case ARG_AUDIT:
-      audit_file = arg;
-      break;
-
-    case ARG_NOAUDIT:
-      audit_file = NULL;
-      break;
-      
-    case ARG_CHANGECUR:
-      changecur = is_true (arg);
-      break;
-
-    case ARG_DEBUG:
-      if (mu_script_debug_flags (arg, &p))
-	argp_error (state, _("invalid debug flag near %s"), p);
-      break;
-
-    case ARG_NOCHANGECUR:
-      changecur = 0;
-      break;
-      
-    case ARG_FOLDER: 
-      append_folder = arg;
-      break;
-      
-    case ARG_FORM:
-      mh_read_formfile (arg, &format_str);
-      break;
-
-    case ARG_FORMAT:
-      format_str = arg;
-      break;
-      
-    case ARG_FILE:
-      if (!input_file_list)
-	{
-	  rc = mu_list_create (&input_file_list);
-	  if (rc)
-	    {
-	      mu_diag_funcall (MU_DIAG_ERROR,
-			       "mu_list_create", "&input_file_list", rc);
-	      exit (1);
-	    }
-	}
-      rc = mu_list_append (input_file_list, arg);
+      rc = mu_list_create (&input_file_list);
       if (rc)
 	{
-	  mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", arg, rc);
-	  exit (1);
-	}
-      break;
-
-    case ARG_TRUNCATE:
-      truncate_source = is_true (arg);
-      break;
-
-    case ARG_NOTRUNCATE:
-      truncate_source = 0;
-      break;
-
-    case ARG_MOVETO:
-      move_to_mailbox = arg;
-      break;
-      
-    case ARG_WIDTH:
-      width = strtoul (arg, NULL, 0);
-      if (!width)
-	{
-	  argp_error (state, _("invalid width"));
+	  mu_diag_funcall (MU_DIAG_ERROR,
+			   "mu_list_create", "&input_file_list", rc);
 	  exit (1);
 	}
-      break;
-
-    case ARG_QUIET:
-      quiet = 1;
-      break;
-
-    case ARG_NOTIFY:
-      notify = is_true (arg);;
-      break;
-
-    case ARG_LANG:
-      script_lang = arg;
-      break;
+    }
+  rc = mu_list_append (input_file_list, mu_strdup (arg));
+  if (rc)
+    {
+      mu_diag_funcall (MU_DIAG_ERROR, "mu_list_append", arg, rc);
+      exit (1);
+    }
+}
 
-    case ARG_SCRIPT:
-      script_file = arg;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
+static void
+set_debug (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  char *p;
+  
+  if (mu_script_debug_flags (arg, &p))
+    {
+      mu_parseopt_error (po, _("invalid debug flag near %s"), p);
+      exit (po->po_exit_error);
     }
-  return 0;
 }
 
+static struct mu_option options[] = {
+  { "file",    0, N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("incorporate mail from named file"),
+    mu_c_string, NULL, add_file },
+  { "folder",  0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify folder to incorporate mail to"),
+    mu_c_string, &append_folder },
+  { "audit",   0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("enable audit"),
+    mu_c_string, &audit_file },
+  { "noaudit", 0, NULL, MU_OPTION_DEFAULT,
+    N_("disable audit"),
+    mu_c_string, &audit_file, mh_opt_clear_string },
+  { "changecur", 0, NULL, MU_OPTION_DEFAULT,
+    N_("mark first incorporated message as current (default)"),
+    mu_c_bool, &changecur },
+  { "form",      0, N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, &format_str, mh_opt_read_formfile },
+  { "format",    0, N_("FORMAT"), MU_OPTION_DEFAULT,
+    N_("use this format string"),
+    mu_c_string, &format_str },
+  { "truncate",  0, NULL, MU_OPTION_DEFAULT,
+    N_("truncate source mailbox after incorporating (default)"),
+    mu_c_bool, &truncate_source },
+  { "moveto",    0, N_("MAILBOX"), MU_OPTION_DEFAULT,
+    N_("move incorporated messages to MAILBOX instead of deleting them"),
+    mu_c_string, &move_to_mailbox },
+  { "width",     0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output width"),
+    mu_c_int, &width },
+  { "quiet",     0, NULL,         MU_OPTION_DEFAULT,
+    N_("be quiet"),
+    mu_c_bool, &quiet },
+  { "notify",    0, NULL,         MU_OPTION_DEFAULT,
+    N_("enable biff notification"),
+    mu_c_bool, &notify },
+  { "language",  0, N_("LANG"),   MU_OPTION_DEFAULT,
+    N_("set language for the --script option"),
+    mu_c_string, &script_lang },
+  { "script",    0, N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("filter incoming messages using script FILE"),
+    mu_c_string, &script_file },
+  { "debug",     0, N_("FLAGS"),  MU_OPTION_DEFAULT,
+    N_("enable debugging"),
+    mu_c_string, 0, set_debug },
+  MU_OPTION_END
+};
+
 void
 list_message (mh_format_t *format, mu_mailbox_t mbox, size_t msgno,
 	      size_t width)
@@ -430,9 +348,10 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
   
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, NULL);
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, extra_doc);
+  if (!append_folder)
+    append_folder = mh_global_profile_get ("Inbox", "inbox");
+
   mu_registrar_set_default_scheme ("mh");
 
   /* Inc sets missing cur to 1 */
diff --git a/mh/install-mh.c b/mh/install-mh.c
index 486f2d5..0432ba2 100644
--- a/mh/install-mh.c
+++ b/mh/install-mh.c
@@ -17,41 +17,17 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH install-mh")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
-
-/* GNU options */
-static struct argp_option options[] = {
-  {"auto",  ARG_AUTO, NULL, 0, N_("do not ask for anything")},
-  {"compat", ARG_COMPAT, NULL, OPTION_HIDDEN, ""},
-  {NULL}
-};
-
-struct mh_option mh_option[] = {
-  { "auto" },
-  { "compat" },
-  { NULL }
-};
+static char prog_doc[] = N_("GNU MH install-mh");
 
 int automode;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_AUTO:
-      automode = 1;
-      break;
-
-    case ARG_COMPAT:
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
+static struct mu_option options[] = {
+  { "auto",   0, NULL, MU_OPTION_DEFAULT,
+    N_("do not ask for anything"),
+    mu_c_bool, &automode },
+  { "compat", 0, NULL, MU_OPTION_HIDDEN, "", mu_c_void },
+  MU_OPTION_END
+};
 
 int
 main (int argc, char **argv)
@@ -62,10 +38,8 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
   mh_auto_install = 0;
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, NULL, doc,
-		 opt_handler, NULL, NULL);
+  mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL);
 
   name = getenv ("MH");
   if (name)
diff --git a/mh/mark.c b/mh/mark.c
index 1add9b0..3c17752 100644
--- a/mh/mark.c
+++ b/mh/mark.c
@@ -17,105 +17,77 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH mark")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH mark");
 static char args_doc[] = N_("[MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  {"sequence", ARG_SEQUENCE, N_("NAME"), 0,
-   N_("specify sequence name to operate upon")},
-  {"add", ARG_ADD, NULL, 0,
-   N_("add messages to the sequence")},
-  {"delete", ARG_DELETE, NULL, 0,
-   N_("delete messages from the sequence")},
-  {"list", ARG_LIST, NULL, 0,
-   N_("list the sequences")},
-  {"public", ARG_PUBLIC, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("create public sequence")},
-  {"nopublic", ARG_NOPUBLIC, NULL, OPTION_HIDDEN, "" },
-  {"zero", ARG_ZERO, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("empty the sequence before adding messages")},
-  {"nozero", ARG_NOZERO, NULL, OPTION_HIDDEN, "" },
-  {NULL}
-};
-
-struct mh_option mh_option[] = {
-  { "sequence" },
-  { "add" }, 
-  { "delete" },
-  { "list" },
-  { "public", MH_OPT_BOOL },
-  { "zero", MH_OPT_BOOL },
-  { NULL }
-};
+enum action_type
+  {
+    action_undef,
+    action_list,
+    action_add,
+    action_delete
+  };
+static enum action_type action = action_undef;  /* Action to perform */
 
-static int action;  /* Action to perform */
 static int seq_flags = 0; /* Create public sequences;
 			     Do not zero the sequence before addition */
 static mu_list_t seq_list;  /* List of sequence names to operate upon */
 
 static const char *mbox_dir;
+static int public_option = -1;
+static int zero_option = -1;
 
 static void
-add_sequence (char *name)
+set_action_add (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  if (!seq_list && mu_list_create (&seq_list))
-    {
-      mu_error (_("cannot create sequence list"));
-      exit (1);
-    }
-  mu_list_append (seq_list, name);
+  action = action_add;
 }
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_action_delete (struct mu_parseopt *po, struct mu_option *opt,
+		   char const *arg)
 {
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_SEQUENCE:
-      add_sequence (arg);
-      break;
+  action = action_delete;
+}
 
-    case ARG_ADD:
-    case ARG_DELETE:
-    case ARG_LIST:
-      action = key;
-      break;
-      
-    case ARG_PUBLIC:
-      if (is_true (arg))
-	seq_flags &= ~SEQ_PRIVATE;
-      else
-	seq_flags |= SEQ_PRIVATE;
-      break;
-      
-    case ARG_NOPUBLIC:
-      seq_flags |= SEQ_PRIVATE;
-      break;
-      
-    case ARG_ZERO:
-      if (is_true (arg))
-	seq_flags |= SEQ_ZERO;
-      else
-	seq_flags &= ~SEQ_ZERO;
-      break;
+static void
+set_action_list (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  action = action_list;
+}
 
-    case ARG_NOZERO:
-      seq_flags &= ~SEQ_ZERO;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
+static void
+add_sequence (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (!seq_list && mu_list_create (&seq_list))
+    {
+      mu_error (_("cannot create sequence list"));
+      exit (1);
     }
-  return 0;
+  mu_list_append (seq_list, mu_strdup (arg));
 }
+
+static struct mu_option options[] = {
+  { "sequence", 0, N_("NAME"), MU_OPTION_DEFAULT,
+    N_("specify sequence name to operate upon"),
+    mu_c_string, NULL, add_sequence },
+  { "add",      0, NULL, MU_OPTION_DEFAULT,
+    N_("add messages to the sequence"),
+    mu_c_string, NULL, set_action_add },
+  { "delete",   0, NULL, MU_OPTION_DEFAULT,
+    N_("delete messages from the sequence"),
+    mu_c_string, NULL, set_action_delete },
+  { "list",     0, NULL, MU_OPTION_DEFAULT,
+    N_("list the sequences"),
+    mu_c_string, NULL, set_action_list },
+  { "public",   0, NULL, MU_OPTION_DEFAULT,
+    N_("create public sequence"),
+    mu_c_bool, &public_option },
+  { "zero", 0, NULL, MU_OPTION_DEFAULT,
+    N_("empty the sequence before adding messages"),
+    mu_c_bool, &zero_option },
+  MU_OPTION_END
+};
 
 
 struct mark_closure
@@ -125,7 +97,7 @@ struct mark_closure
 };
 
 static int
-action_add (void *item, void *data)
+do_add (void *item, void *data)
 {
   struct mark_closure *clos = data;
   mh_seq_add (clos->mbox, (char *)item, clos->msgset, seq_flags);
@@ -133,7 +105,7 @@ action_add (void *item, void *data)
 }
 
 static int
-action_delete (void *item, void *data)
+do_delete (void *item, void *data)
 {
   struct mark_closure *clos = data;
   mh_seq_delete (clos->mbox, (char *)item, clos->msgset, seq_flags);
@@ -141,7 +113,7 @@ action_delete (void *item, void *data)
 }
 
 static int
-action_list (void *item, void *data)
+do_list (void *item, void *data)
 {
   struct mark_closure *clos = data;
   char *name = item;
@@ -190,25 +162,45 @@ list_all (mu_mailbox_t mbox)
 int
 main (int argc, char **argv)
 {
-  int index;
   mu_msgset_t msgset;
   mu_mailbox_t mbox;
   mu_url_t url;
   struct mark_closure clos;
   
   MU_APP_INIT_NLS ();
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
 
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+  if (public_option == -1)
+    /* use default */;
+  else if (public_option)
+    seq_flags &= ~SEQ_PRIVATE;
+  else
+    seq_flags |= SEQ_PRIVATE;
+
+  if (zero_option == -1)
+    /* use default */;
+  else if (zero_option)
+    seq_flags |= SEQ_ZERO;
+  else
+    seq_flags &= ~SEQ_ZERO;
+
+  if (action == action_undef)
+    {
+      /* If no explicit action is given, assume -add if a sequence
+	 was specified, and -list otherwise. */
+      if (mu_list_is_empty (seq_list))
+	action = action_list;
+      else
+	action = action_add;
+    }
+  
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
   mu_mailbox_get_url (mbox, &url);
   mbox_dir = mu_url_to_string (url);
   if (memcmp (mbox_dir, "mh:", 3) == 0)
     mbox_dir += 3;
 	
-  argc -= index;
-  argv += index;
   mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
   
   clos.mbox = mbox;
@@ -216,32 +208,34 @@ main (int argc, char **argv)
   //FIXME: msgset operates on UIDs but there's no way to inform it about that.
   switch (action)
     {
-    case ARG_ADD:
+    case action_add:
       if (!seq_list)
 	{
 	  mu_error (_("--add requires at least one --sequence argument"));
 	  return 1;
 	}
-      mu_list_foreach (seq_list, action_add, (void *) &clos);
+      mu_list_foreach (seq_list, do_add, (void *) &clos);
       mh_global_save_state ();
       break;
       
-    case ARG_DELETE:
+    case action_delete:
       if (!seq_list)
 	{
 	  mu_error (_("--delete requires at least one --sequence argument"));
 	  return 1;
 	}
-      mu_list_foreach (seq_list, action_delete, (void *) &clos);
+      mu_list_foreach (seq_list, do_delete, (void *) &clos);
       mh_global_save_state ();
       break;
       
-    case ARG_LIST:
+    case action_list:
       if (!seq_list)
 	list_all (mbox);
       else
-	mu_list_foreach (seq_list, action_list, &clos);
+	mu_list_foreach (seq_list, do_list, &clos);
       break;
+    default:
+      abort ();
     }
   mu_mailbox_close (mbox);
   mu_mailbox_destroy (&mbox);
diff --git a/mh/mh.h b/mh/mh.h
index 8a441d6..7d3ea0b 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -57,6 +57,7 @@
 #include <mailutils/io.h>
 #include <mailutils/property.h>
 #include <mailutils/prog.h>
+#include <mailutils/opool.h>
 #include <mailutils/mh.h>
 #include <mailutils/stdstream.h>
 #include <mailutils/datetime.h>
@@ -230,7 +231,7 @@ extern int mh_mailbox_cur_default;
 void mh_init (void);
 void mh_init2 (void);
 void mh_read_profile (void);
-int mh_read_formfile (char *name, char **pformat);
+int mh_read_formfile (char const *name, char **pformat);
 mu_message_t mh_file_to_message (const char *folder, const char *file_name);
 mu_message_t mh_stream_to_message (mu_stream_t stream);
 void mh_install (char *name, int automode);
@@ -342,7 +343,7 @@ void mh_set_reply_regex (const char *str);
 int mh_decode_2047 (char *text, char **decoded_text);
 const char *mh_charset (const char *);
 
-int mh_alias_read (char *name, int fail);
+int mh_alias_read (char const *name, int fail);
 int mh_alias_get (const char *name, mu_list_t *return_list);
 int mh_alias_get_address (const char *name, mu_address_t *addr, int *incl);
 int mh_alias_get_alias (const char *uname, mu_list_t *return_list);
diff --git a/mh/mh_alias.l b/mh/mh_alias.l
index e8994c1..82d23cd 100644
--- a/mh/mh_alias.l
+++ b/mh/mh_alias.l
@@ -419,7 +419,7 @@ yywrap ()
 
 /* Parses the named alias file */
 int
-mh_alias_read (char *name, int fail)
+mh_alias_read (char const *name, int fail)
 {
   extern int yydebug;
   char *p = getenv("ALI_YYDEBUG");
diff --git a/mh/mh_argp.c b/mh/mh_argp.c
deleted file mode 100644
index 2ac8ac6..0000000
--- a/mh/mh_argp.c
+++ /dev/null
@@ -1,298 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999-2002, 2005-2007, 2009-2012, 2014-2016 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/>. */
-
-/* Coexistence between GNU long options, traditional UNIX-style short
-   options and traditional MH long options. */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <mh.h>
-#include <string.h>
-#include <mailutils/argcv.h>
-#include "argp.h"
-#ifdef MU_ALPHA_RELEASE
-# include <git-describe.h>
-#endif
-
-static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
-{
-  struct mh_argp_data *data = state->input;
-  error_t ret = ARGP_ERR_UNKNOWN;
-  
-  switch (key)
-    {
-    case ARGP_KEY_ARG:
-      if (arg[0] == '+')
-	ret = data->handler (ARG_FOLDER, arg + 1, state);
-      break;
-      
-    default:
-      ret = data->handler (key, arg, state);
-      if (ret == 0)
-	{
-	  if (key == ARGP_KEY_ERROR)
-	    data->errind = state->next;
-	}
-    }
-
-  return ret;
-}
-
-static int
-my_argp_parse (struct argp *argp, int argc, char **argv, int flags,
-	       int *end_index, struct mh_argp_data *data)
-{
-  int rc;
-  int f = 0;
-  int index = 0;
-
-  if (flags & ARGP_NO_ERRS)
-    {
-      while (argc > 0
-	     && (rc = argp_parse (argp, argc, argv, flags|f, end_index, data))
-	     == EINVAL)
-	{
-	  if (data->errind == -1)
-	    break;
-	  data->errind--;
-	  if (f)
-	    data->errind--;
-	  argc -= data->errind;
-	  argv += data->errind;
-	  index += data->errind;
-	  if (argc < 2 || memcmp (argv[1], "--", 2))
-	    {
-	      if (end_index)
-		*end_index = index + 1;
-	      break;
-	    }
-	  f = ARGP_PARSE_ARGV0;
-	}
-      if (rc == 0 && end_index)
-	*end_index += index;
-      rc = 0;
-    }
-  else
-    rc = argp_parse (argp, argc, argv, flags, end_index, data);
-  return rc;
-}
-
-const char version_etc_copyright[] =
-  /* Do *not* mark this string for translation.  %s is a copyright
-     symbol suitable for this locale, and %d is the copyright
-     year.  */
-  "Copyright %s 2010 Free Software Foundation, inc.";
-
-/* This is almost the same as mu_program_version_hook from muinit.c,
-   except for different formatting of the first line. MH uses:
-
-      progname (GNU Mailutils X.Y.Z)
-
-   where X.Y.Z stands for the version number. Emacs MH-E uses this
-   to determine Mailutils presence and its version number (see
-   lisp/mh-e/mh-e.el, function mh-variant-mu-mh-info). */
-static void
-mh_program_version_hook (FILE *stream, struct argp_state *state)
-{
-#ifdef GIT_DESCRIBE
-  fprintf (stream, "%s (%s %s) [%s]\n",
-	   mu_program_name, PACKAGE_NAME, PACKAGE_VERSION, GIT_DESCRIBE);
-#else
-  fprintf (stream, "%s (%s %s)\n", mu_program_name,
-	   PACKAGE_NAME, PACKAGE_VERSION);
-#endif
-  /* TRANSLATORS: Translate "(C)" to the copyright symbol
-     (C-in-a-circle), if this symbol is available in the user's
-     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
-  fprintf (stream, version_etc_copyright, _("(C)"));
-
-  fputs (_("\
-\n\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
-There is NO WARRANTY, to the extent permitted by law.\n\
-\n\
-"),
-	 stream);
-}
-
-void
-mh_argp_init ()
-{
-  argp_program_bug_address =  "<" PACKAGE_BUGREPORT ">";
-  argp_program_version_hook = mh_program_version_hook;
-}
-
-
-enum
-  {
-    OPT_DEBUG_LEVEL = 256,
-    OPT_DEBUG_LINE_INFO,
-  };
-
-static struct argp_option mu_debug_argp_options[] = 
-{
-  { "debug-level", OPT_DEBUG_LEVEL, N_("LEVEL"), 0,
-    N_("set Mailutils debugging level"), 0 },
-  { "debug-line-info", OPT_DEBUG_LINE_INFO, NULL, 0,
-    N_("show source info with debugging messages"), 0 },
-  { NULL }
-};
-
-static error_t
-mu_debug_argp_parser (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case OPT_DEBUG_LEVEL:
-      mu_debug_parse_spec (arg);
-      break;
-
-    case OPT_DEBUG_LINE_INFO:
-      mu_debug_line_info = 1;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-struct argp mu_debug_argp = {
-  mu_debug_argp_options,
-  mu_debug_argp_parser,
-};
-
-struct argp_child mh_argp_children[] = {
-  { &mu_debug_argp, 0, N_("Global debugging settings"), -2 },
-  { NULL }
-};
-
-int
-mh_argp_parse (int *pargc, char **pargv[],
-	       int flags,
-	       struct argp_option *option,
-	       struct mh_option *mh_option,
-	       char *argp_doc, char *doc,
-	       argp_parser_t handler,
-	       void *closure, int *pindex)
-{
-  struct argp argp;
-  struct mh_argp_data data;
-  const char *val;
-  int index;
-  int extra  = 0;
-
-  mu_set_program_name ((*pargv)[0]);
-  mh_init ();
-
-  mh_option_init (mh_option);
-  memset (&argp, 0, sizeof (argp));
-  argp.options = option;
-  argp.parser = parse_opt;
-  argp.args_doc = argp_doc;
-  argp.doc = doc;
-  argp.children = mh_argp_children;
-  data.mh_option = mh_option;
-  data.closure = closure;
-  data.handler = handler;
-  data.doc = argp_doc;
-  data.errind = -1;
-  
-  val = mh_global_profile_get (mu_program_name, NULL);
-  if (val)
-    {
-      int argc;
-      char **argv;
-      int i, j;
-      struct mu_wordsplit ws;
-      
-      if (mu_wordsplit (val, &ws, MU_WRDSF_DEFFLAGS))
-	{
-	  mu_error (_("cannot split line `%s': %s"), val,
-		    mu_wordsplit_strerror (&ws));
-	  exit (1);
-	}
-
-      argc = *pargc + ws.ws_wordc;
-      argv = calloc (argc + 1, sizeof *argv);
-      if (!argv)
-        mh_err_memory (1);
-
-      i = 0;
-      argv[i++] = (*pargv)[0];
-      for (j = 0; j < ws.ws_wordc; i++, j++)
-	argv[i] = ws.ws_wordv[j];
-      for (j = 1; i < argc; i++, j++)
-	argv[i] = (*pargv)[j];
-      argv[i] = NULL;
-
-      ws.ws_wordc = 0;
-      mu_wordsplit_free (&ws);
-      
-      mh_argv_preproc (argc, argv, &data);
-
-      my_argp_parse (&argp, argc, argv, flags, &index, &data);
-
-      extra = index < argc;
-
-      *pargc = argc;
-      *pargv = argv;
-    }
-  else
-    {
-      mh_argv_preproc (*pargc, *pargv, &data);
-      my_argp_parse (&argp, *pargc, *pargv, flags, &index, &data);
-      extra = index < *pargc;
-    }
-  if (pindex)
-    *pindex = index;
-  else if (extra)
-    {
-      mu_error (_("Extra arguments"));
-      exit (1);
-    }
-  mh_init2 ();
-  return 0;
-}
-
-void
-mh_license (const char *name)
-{
-  printf (_("This is %s\n\n"), name);
-  printf (
-  _("   GNU Mailutils is free software; you can redistribute it and/or modify\n"
-    "   it under the terms of the GNU General Public License as published by\n"
-    "   the Free Software Foundation; either version 3 of the License, or\n"
-    "   (at your option) any later version.\n"
-    "\n"
-    "   GNU Mailutils is distributed in the hope that it will be useful,\n"
-    "   but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
-    "   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
-    "   GNU General Public License for more details.\n"
-    "\n"
-    "   You should have received a copy of the GNU General Public License along\n"
-    "   with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.\n"
-    "\n"
-    "\n"
-));
-
-  exit (0);
-}
-
diff --git a/mh/mh_format.c b/mh/mh_format.c
index eb31305..77e4e85 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -20,11 +20,10 @@
 #include <mh.h>
 #include <mh_format.h>
 #include <mailutils/mime.h>
+#include <mailutils/opool.h>
 
-#ifdef HAVE_STRINGS_H
-# include <strings.h>
-#endif
 #include <string.h>
+#include <ctype.h>
 #include "mbiter.h"
 #include "mbchar.h"
 #include "mbswidth.h"
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 217261f..b4d92fb 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -15,8 +15,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/>. */
 
-/* Parse traditional MH options. */
-
 #ifdef HAVE_CONFIG_H
 # include <config.h>
 #endif
@@ -24,197 +22,224 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <mh_getopt.h>
+#include "mh.h"
+#include <mailutils/stream.h>
+#include <mailutils/wordsplit.h>
 #include <mailutils/io.h>
 
-static int mh_optind = 1;
-static char *mh_optarg;
-static char *mh_optptr;
-
-void (*mh_help_hook) ();
+struct getopt_data
+{
+  char *extra_doc;
+};
 
-int
-mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc)
+static void
+mh_extra_help_hook (struct mu_parseopt *po, mu_stream_t stream)
 {
-  struct mh_option *p;
-  int optlen;
-  
-  if (mh_optind >= argc || argv[mh_optind] == NULL)
-    return EOF;
-  mh_optptr = argv[mh_optind];
+  struct getopt_data *data = po->po_data;
+  mu_stream_printf (stream, "%s\n", _(data->extra_doc));
+}
 
-  if (mh_optptr[0] == '+')
+static void
+augment_argv (int *pargc, char ***pargv)
+{
+  int argc;
+  char **argv;
+  int i, j;
+  struct mu_wordsplit ws;
+  char const *val = mh_global_profile_get (mu_program_name, NULL);
+
+  if (!val)
+    return;
+      
+  if (mu_wordsplit (val, &ws, MU_WRDSF_DEFFLAGS))
     {
-      mh_optarg = mh_optptr + 1;
-      mh_optind++;
-      return '+';
+      mu_error (_("cannot split line `%s': %s"), val,
+		mu_wordsplit_strerror (&ws));
+      exit (1);
     }
+
+  argc = *pargc + ws.ws_wordc;
+  argv = calloc (argc + 1, sizeof *argv);
+  if (!argv)
+    mh_err_memory (1);
+
+  i = 0;
+  argv[i++] = (*pargv)[0];
+  for (j = 0; j < ws.ws_wordc; i++, j++)
+    argv[i] = ws.ws_wordv[j];
+  for (j = 1; i < argc; i++, j++)
+    argv[i] = (*pargv)[j];
+  argv[i] = NULL;
   
-  if (mh_optptr[0] != '-' || mh_optptr[1] == '-')
+  ws.ws_wordc = 0;
+  mu_wordsplit_free (&ws);
+
+  *pargc = argc;
+  *pargv = argv;
+}
+
+static void
+process_folder_arg (int *pargc, char **argv, struct mu_parseopt *po)
+{
+  int i, j;
+  int argc = *pargc;
+  struct mu_option *opt;
+  
+  /* Find folder option */
+  for (i = 0; ; i++)
     {
-      mh_optind++;
-      return 0;
+      if (!po->po_optv[i])
+	return; /* Nothing to do */
+      if (MU_OPTION_IS_VALID_LONG_OPTION (po->po_optv[i])
+	  && strcmp (po->po_optv[i]->opt_long, "folder") == 0)
+	break;
     }
-
-  if (strcmp (mh_optptr, "-version") == 0)
-    mu_asprintf (&argv[mh_optind], "--version");
-  else
+  opt = po->po_optv[i];
+    
+  for (i = j = 0; i < argc; i++)
     {
-      int negation = 0;
-      
-      optlen = strlen (mh_optptr+1);
-      for (p = mh_opt; p->opt; p++)
+      if (argv[i][0] == '+')
 	{
-	  if (p->match_len <= optlen
-	      && memcmp (mh_optptr+1, p->opt, optlen) == 0)
-	    break;
-	  if (p->flags == MH_OPT_BOOL
-	      && optlen > 2
-	      && memcmp (mh_optptr+1, "no", 2) == 0
-	      && strlen (p->opt) >= optlen-2
-	      && memcmp (mh_optptr+3, p->opt, optlen-2) == 0)
-	    {
-	      negation = 1;
-	      break;
-	    }
-	}
-      
-      if (p->opt)
-	{
-	  char *longopt = p->opt;
-	  switch (p->flags)
-	    {
-	    case MH_OPT_BOOL:
-	      mh_optarg = negation ? "no" : "yes";
-	      mu_asprintf (&argv[mh_optind], "--%s=%s", longopt, mh_optarg);
-	      break;
-	      
-	    case MH_OPT_ARG:
-	      mu_asprintf (&argv[mh_optind], "--%s", longopt);
-	      mh_optarg = argv[++mh_optind];
-	      break;
-	      
-	    default:
-	      mu_asprintf (&argv[mh_optind], "--%s", longopt);
-	      mh_optarg = NULL;
-	    }
-	  mh_optind++;
-	  return 1;
-	}
-      else if (!strcmp (mh_optptr+1, "help"))
-	{
-	  mh_help (mh_opt, doc);
-	  exit (1);
+	  opt->opt_set (po, opt, argv[i] + 1);
 	}
       else
-	mh_optind++;
+	argv[j++] = argv[i];
     }
-  return '?';
+  argv[j] = NULL;
+  *pargc = j;
 }
-
-void
-mh_argv_preproc (int argc, char **argv, struct mh_argp_data *data)
+
+static void
+set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  mh_optind = 1;
-  while (mh_getopt (argc, argv, data->mh_option, data->doc) != EOF)
-    ;
+  mh_set_current_folder (arg);
 }
 
+static struct mu_option folder_option[] = {
+  { "folder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("set current folder"),
+    mu_c_string, NULL, set_folder },
+  MU_OPTION_END
+};
+
 void
-mh_help (struct mh_option *mh_opt, const char *doc)
+mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
+	   int mhflags,
+	   char *argdoc, char *progdoc, char *extradoc)
 {
-  struct mh_option *p;
+  int argc = *pargc;
+  char **argv = *pargv;
+  struct mu_parseopt po;
+  struct mu_option *optv[3];
+  struct getopt_data getopt_data;
+  char const *args[2];
+  int flags = MU_PARSEOPT_SINGLE_DASH | MU_PARSEOPT_IMMEDIATE;
+  int i;
+  
+  po.po_negation = "no";
+  flags |= MU_PARSEOPT_NEGATION;
 
-  printf (_("Compatibility syntax:\n"));
-  printf (_("%s [switches] %s\n"), mu_program_name, doc);
-  printf (_("  switches are:\n"));
+  if (argdoc)
+    {
+      args[0] = argdoc;
+      args[1] = NULL;
+      po.po_prog_args = args;
+      flags |= MU_PARSEOPT_PROG_ARGS;
+    }
+  if (progdoc)
+    {
+      po.po_prog_doc = progdoc;
+      flags |= MU_PARSEOPT_PROG_DOC;
+    }
+
+  getopt_data.extra_doc = extradoc;
+  if (extradoc)
+    {
+      po.po_help_hook = mh_extra_help_hook;
+      flags |= MU_PARSEOPT_HELP_HOOK;
+    }
+
+  po.po_data = &getopt_data;
+  flags |= MU_PARSEOPT_DATA;
   
-  for (p = mh_opt; p->opt; p++)
+  po.po_exit_error = 1;
+  flags |= MU_PARSEOPT_EXIT_ERROR;
+  
+  po.po_package_name = PACKAGE_NAME;
+  flags |= MU_PARSEOPT_PACKAGE_NAME;
+
+  po.po_package_url = PACKAGE_URL;
+  flags |= MU_PARSEOPT_PACKAGE_URL;
+
+  po.po_bug_address = PACKAGE_BUGREPORT;
+  flags |= MU_PARSEOPT_BUG_ADDRESS;
+
+  //po.po_extra_info = gnu_general_help_url;
+  //flags |= MU_PARSEOPT_EXTRA_INFO;
+
+  mu_set_program_name (argv[0]);
+  mh_init ();
+  augment_argv (&argc, &argv);
+
+  i = 0;
+  if (mhflags & MH_GETOPT_DEFAULT_FOLDER)
+    optv[i++] = folder_option;
+  optv[i++] = options;
+  optv[i] = NULL;
+  
+  if (mu_parseopt (&po, argc, argv, optv, flags))
+    exit (po.po_exit_error);
+
+  argc -= po.po_arg_start;
+  argv += po.po_arg_start;
+
+  process_folder_arg (&argc, argv, &po);
+
+  if (!argdoc && argc)
     {
-      int len = strlen (p->opt);
-      
-      printf ("  -");
-      if (p->flags == MH_OPT_BOOL)
-	printf ("[no]");
-      if (len > p->match_len)
-	printf ("(%*.*s)%s",
-		(int) p->match_len, (int) p->match_len, p->opt,
-		p->opt + p->match_len);
-      else
-	printf ("%s", p->opt);
-      
-      if (p->flags == MH_OPT_ARG)
-	printf (" %s", p->arg);
-      printf ("\n");
+      mu_error (_("Extra arguments"));
+      exit (1);
     }
-  if (mh_help_hook)
-    mh_help_hook ();
-  printf ("  -help\n");
-  printf ("  -version\n");
-  printf (_("\nPlease use GNU long options instead.\n"
-            "Run %s --help for more info on these.\n"),
-            mu_program_name);
+
+  *pargc = argc;
+  *pargv = argv;
+  
+  mh_init2 ();
 }
 
-
-static int
-optcmp (const void *a, const void *b)
+void
+mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  struct mh_option const *opta = a, *optb = b;
-  return strcmp (opta->opt, optb->opt);
+  mu_error (_("option is not yet implemented: %s"), opt->opt_long);
+  exit (1);
 }
 
 void
-mh_option_init (struct mh_option *opt)
+mh_opt_notimpl_warning (struct mu_parseopt *po, struct mu_option *opt,
+			char const *arg)
 {
-  size_t count, i;
-
-  /* Count number of elements and initialize minimum abbreviation
-     lengths to 1. */
-  for (count = 0; opt[count].opt; count++)
-    opt[count].match_len = 1;
-  /* Sort them alphabetically */
-  qsort (opt, count, sizeof (opt[0]), optcmp);
-  /* Determine minimum abbreviations */
-  for (i = 0; i < count; i++)
-    {
-      const char *sample = opt[i].opt;
-      size_t sample_len = strlen (sample);
-      size_t minlen = opt[i].match_len;
-      size_t j;
-      
-      for (j = i + 1; j < count; j++)
-	{
-	  size_t len = strlen (opt[j].opt);
-	  if (len >= minlen && memcmp (opt[j].opt, sample, minlen) == 0)
-	    do
-	      {
-		minlen++;
-		if (minlen <= strlen (opt[j].opt))
-		  opt[j].match_len = minlen;
-		if (minlen == sample_len)
-		  break;
-	      }
-	    while (len >= minlen && memcmp (opt[j].opt, sample, minlen) == 0);
-	  else if (opt[j].opt[0] == sample[0])
-	    opt[j].match_len = minlen;
-	  else
-	    break;
-	}
-      if (minlen <= sample_len)
-	opt[i].match_len = minlen;
-    }
+  mu_error (_("ignoring not implemented option %s"), opt->opt_long);
 }
 
 void
-mh_opt_notimpl (const char *name)
+mh_opt_clear_string (struct mu_parseopt *po, struct mu_option *opt,
+		     char const *arg)
 {
-  mu_error (_("option is not yet implemented: %s"), name);
-  exit (1);
+  char **sptr = opt->opt_ptr;
+  free (*sptr);
+  *sptr = NULL;
+}
+
+void
+mh_opt_find_file (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  mh_find_file (arg, opt->opt_ptr);
 }
 
 void
-mh_opt_notimpl_warning (const char *name)
+mh_opt_read_formfile (struct mu_parseopt *po, struct mu_option *opt,
+		      char const *arg)
 {
-  mu_error (_("ignoring not implemented option %s"), name);
+  mh_read_formfile (arg, opt->opt_ptr);
 }
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index 4823dd2..b361653 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -16,198 +16,24 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <mailutils/nls.h>
-#include "argp.h"
-#include "mailutils/libargp.h"
+#include <mailutils/opt.h>
 
-#define MH_OPT_BOOL 1
-#define MH_OPT_ARG  2
+#define MH_GETOPT_DEFAULT_FOLDER 0x1
 
-struct mh_option
-{
-  char *opt;
-  int flags;
-  char *arg;
-  size_t match_len;
-};
+void mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
+		int flags,
+		char *argdoc, char *progdoc, char *extradoc);
 
-struct mh_argp_data
-{
-  struct mh_option *mh_option;
-  argp_parser_t handler;
-  int errind;
-  void *closure;
-  char *doc;
-};
+void mh_opt_notimpl (struct mu_parseopt *po, struct mu_option *opt,
+		     char const *arg);
+void mh_opt_notimpl_warning (struct mu_parseopt *po, struct mu_option *opt,
+			     char const *arg);
+void mh_opt_clear_string (struct mu_parseopt *po, struct mu_option *opt,
+			  char const *arg);
 
-enum mh_arg {
-  ARG_ADD = 256,		
-  ARG_AFTER,		
-  ARG_ALIAS,		
-  ARG_ALL,		
-  ARG_AND,		
-  ARG_ANNOTATE,		
-  ARG_APOP,
-  ARG_AUDIT,		
-  ARG_AUTO,		
-  ARG_BEFORE,		
-  ARG_BELL,		
-  ARG_BUILD,		
-  ARG_CC,	        
-  ARG_CFLAGS,		
-  ARG_CHANGECUR,
-  ARG_CHARSET,
-  ARG_CHECK,
-  ARG_CHUNKSIZE,
-  ARG_CLEAR,		
-  ARG_COMPAT,		
-  ARG_COMPONENT,		
-  ARG_COMPOSE,		
-  ARG_CREATE,		
-  ARG_DATE,		
-  ARG_DATEFIELD,		
-  ARG_DEBUG,		
-  ARG_DELETE,		
-  ARG_DRAFT,		
-  ARG_DRAFTFOLDER,	
-  ARG_DRAFTMESSAGE,	
-  ARG_DRY_RUN,		
-  ARG_DUMP,		
-  ARG_EDITOR,		
-  ARG_FAST,		
-  ARG_FCC,		
-  ARG_FILE,		
-  ARG_FILTER,		
-  ARG_FOLDER,		
-  ARG_FORM,		
-  ARG_FORMAT,		
-  ARG_FORWARD,		
-  ARG_FROM,		
-  ARG_GROUP,              
-  ARG_HEADER,		
-  ARG_HOST,
-  ARG_INPLACE,		
-  ARG_INTERACTIVE,	
-  ARG_LANG,
-  ARG_LBRACE,		
-  ARG_LENGTH,		
-  ARG_LIMIT,		
-  ARG_LINK,		
-  ARG_LIST,		
-  ARG_MIME,		
-  ARG_MOREPROC,
-  ARG_MOVETO,
-  ARG_MSGID,		
-  ARG_NOALIAS,            
-  ARG_NOAPOP,
-  ARG_NOAUDIT,		
-  ARG_NOAUTO,		
-  ARG_NOBELL,		
-  ARG_NOCC,		
-  ARG_NOCHANGECUR,	
-  ARG_NOCHECK,		
-  ARG_NOCLEAR,		
-  ARG_NOCOMPOSE,		
-  ARG_NOCREATE,		
-  ARG_NODATE,		
-  ARG_NODATEFIELD,	
-  ARG_NODRAFTFOLDER,	
-  ARG_NOEDIT,		
-  ARG_NOFAST,		
-  ARG_NOFILTER,		
-  ARG_NOFORMAT,		
-  ARG_NOFORWARD,		
-  ARG_NOHEADER,		
-  ARG_NOHEADERS,		
-  ARG_NOINPLACE,		
-  ARG_NOINTERACTIVE,      
-  ARG_NOLIMIT,		
-  ARG_NOLIST,		
-  ARG_NOMIME,		
-  ARG_NOMOREPROC,		
-  ARG_NOMSGID,		
-  ARG_NONOTIFY,
-  ARG_NOPAUSE,		
-  ARG_NOPUBLIC,		
-  ARG_NOPUSH,		
-  ARG_NOQUIET,            
-  ARG_NOREALSIZE,		
-  ARG_NORECURSIVE,        
-  ARG_NOREVERSE,	
-  ARG_NORMALIZE,          
-  ARG_NOSERIALONLY,	
-  ARG_NOSHOW,		
-  ARG_NOSHOWPROC,
-  ARG_NOSTORE,		
-  ARG_NOT,		
-  ARG_NOTEXTFIELD,	
-  ARG_NOTIFY,
-  ARG_NOTOTAL,		
-  ARG_NOTRUNCATE,		
-  ARG_NOUSE,		
-  ARG_NOVERBOSE,		
-  ARG_NOWATCH,		
-  ARG_NOWHATNOWPROC,	
-  ARG_NOZERO,		
-  ARG_NUMFIELD,		
-  ARG_OR,		        
-  ARG_PACK,               
-  ARG_PART,		
-  ARG_PATTERN,		
-  ARG_PAUSE,		
-  ARG_POP,		
-  ARG_PRESERVE,		
-  ARG_PRINT,		
-  ARG_PROMPT,		
-  ARG_PUBLIC,		
-  ARG_PUSH,		
-  ARG_QUERY,		
-  ARG_QUIET,		
-  ARG_RBRACE,		
-  ARG_REALSIZE,		
-  ARG_RECURSIVE,		
-  ARG_REORDER,		
-  ARG_REVERSE,		
-  ARG_SCRIPT,
-  ARG_SEQUENCE,		
-  ARG_SERIALONLY,		
-  ARG_SHOW,		
-  ARG_SHOWPROC,
-  ARG_SOURCE,		
-  ARG_SPLIT,		
-  ARG_STORE,		
-  ARG_SUBJECT,		
-  ARG_TEXT,		
-  ARG_TEXTFIELD,		
-  ARG_TO,		        
-  ARG_TOTAL,		
-  ARG_TRUNCATE,		
-  ARG_TYPE,		
-  ARG_USE,		
-  ARG_USER,               
-  ARG_VERBOSE,		
-  ARG_WATCH,		
-  ARG_WHATNOWPROC,	
-  ARG_WIDTH,	
-  ARG_ZERO
-};
+void mh_opt_find_file (struct mu_parseopt *po, struct mu_option *opt,
+		       char const *arg);
+void mh_opt_read_formfile (struct mu_parseopt *po, struct mu_option *opt,
+			   char const *arg);
 
-extern void (*mh_help_hook) (void);
 
-void mh_option_init (struct mh_option *opt);
-
-void mh_argp_init (void);
-void mh_argv_preproc (int argc, char **argv, struct mh_argp_data *data);
-int mh_getopt (int argc, char **argv, struct mh_option *mh_opt, const char *doc);
-int mh_argp_parse (int *argc, char **argv[],
-		   int flags,
-		   struct argp_option *option,
-		   struct mh_option *mh_option,
-		   char *argp_doc, char *doc,
-		   argp_parser_t handler,
-		   void *closure, int *index);
-
-void mh_help (struct mh_option *mh_option, const char *doc);
-void mh_license (const char *name);
-
-void mh_opt_notimpl (const char *name);
-void mh_opt_notimpl_warning (const char *name);
diff --git a/mh/mh_init.c b/mh/mh_init.c
index ccf481e..b624ad2 100644
--- a/mh/mh_init.c
+++ b/mh/mh_init.c
@@ -59,7 +59,7 @@ mh_init2 ()
 }
 
 int
-mh_read_formfile (char *name, char **pformat)
+mh_read_formfile (char const *name, char **pformat)
 {
   FILE *fp;
   struct stat st;
diff --git a/mh/mhl.c b/mh/mhl.c
index fad26ee..3b6ca6e 100644
--- a/mh/mhl.c
+++ b/mh/mhl.c
@@ -21,48 +21,15 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-static char doc[] = N_("GNU MH mhl")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH mhl");
 static char args_doc[] = N_("[FILE [FILE...]]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",     ARG_FOLDER,     N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  { "bell",      ARG_BELL,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("ring the bell at the end of each output page") },
-  {"nobell",     ARG_NOBELL,     NULL, OPTION_HIDDEN, "" },
-  { "clear",     ARG_CLEAR,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("clear the screen after each page of output")},
-  {"noclear",    ARG_NOCLEAR,    NULL, OPTION_HIDDEN, "" },
-  {"form",       ARG_FORM,       N_("FILE"), 0,
-   N_("read format from given file")},
-  {"width",      ARG_WIDTH,      N_("NUMBER"), 0,
-   N_("set output width")},
-  {"length",     ARG_LENGTH,     N_("NUMBER"), 0,
-   N_("set output screen length")},
-  {"moreproc",   ARG_MOREPROC,   N_("PROG"), 0,
-   N_("use given PROG instead of the default") },
-  {"nomoreproc", ARG_NOMOREPROC, NULL, 0,
-   N_("disable use of moreproc program") },
-  { NULL }
-};
-   
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "bell",       MH_OPT_BOOL },
-  { "clear",      MH_OPT_BOOL },
-  { "form",       MH_OPT_ARG, "formatfile"},
-  { "width",      MH_OPT_ARG, "number"},
-  { "length",     MH_OPT_ARG, "number"},
-  { "moreproc",   MH_OPT_ARG, "program"},
-  { "nomoreproc" },
-  { NULL }
-};
+static int bell_option;
+static int clear_option;
 
 static int interactive;  /* Using interactive output */
-static int mhl_fmt_flags; /* MHL format flags. Controlled by --bell 
-                             and --clear */
+static int mhl_fmt_flags; /* MHL format flags. Controlled by -bell 
+                             and -clear */
 static int length = 40;  /* Length of output page */
 static int width = 80;   /* Width of output page */
 static char *formfile = MHLIBDIR "/mhl.format";
@@ -71,69 +38,31 @@ static int nomoreproc;
 
 static mu_list_t format;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER:
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_BELL:
-      if (is_true (arg))
-        mhl_fmt_flags |= MHL_BELL;
-      break;
-      
-    case ARG_NOBELL:
-      mhl_fmt_flags &= ~MHL_BELL;
-      break;
-      
-    case ARG_CLEAR:
-      if (is_true (arg))
-        mhl_fmt_flags |= MHL_CLEARSCREEN;
-      break;
-      
-    case ARG_NOCLEAR:
-      mhl_fmt_flags &= ~MHL_CLEARSCREEN;
-      break;
-      
-    case ARG_FORM:
-      mh_find_file (arg, &formfile);
-      break;
-      
-    case ARG_WIDTH:
-      width = strtoul (arg, NULL, 0);
-      if (!width)
-	{
-	  argp_error (state, _("invalid width"));
-	  exit (1);
-	}
-      break;
-      
-    case ARG_LENGTH:
-      length = strtoul (arg, NULL, 0);
-      if (!length)
-	{
-	  argp_error (state, _("invalid length"));
-	  exit (1);
-	}
-      break;
-
-    case ARG_MOREPROC:
-      moreproc = arg;
-      break;
-      
-    case ARG_NOMOREPROC:
-      nomoreproc = 1;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+static struct mu_option options[] = {
+  { "bell",      0,       NULL, MU_OPTION_DEFAULT,
+    N_("ring the bell at the end of each output page"),
+    mu_c_bool, &bell_option },
+  { "clear",     0,       NULL, MU_OPTION_DEFAULT,
+    N_("clear the screen after each page of output"),
+    mu_c_bool, &clear_option },
+  { "form",      0,       N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, &formfile, mh_opt_find_file },
+  { "width",     0,       N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output width"),
+    mu_c_int, &width },
+  { "length",    0,       N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output screen length"),
+    mu_c_int, &length },
+  { "moreproc",  0,       N_("PROG"), MU_OPTION_DEFAULT,
+    N_("use given PROG instead of the default"),
+    mu_c_string, &moreproc },
+  { "nomoreproc", 0, NULL, MU_OPTION_DEFAULT,
+    N_("disable use of moreproc program"),
+    mu_c_bool, &nomoreproc },
+  MU_OPTION_END
+};
+   
 static mu_stream_t
 open_output ()
 {
@@ -205,23 +134,33 @@ list_message (char *name, mu_stream_t output)
 int
 main (int argc, char **argv)
 {
-  int index;
   mu_stream_t output;
   
   interactive = isatty (1) && isatty (0);
   
   MU_APP_INIT_NLS ();
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
 
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);  
+
+  if (bell_option == -1)
+    /* use default */;
+  else if (bell_option)
+    mhl_fmt_flags |= MHL_BELL;
+  else
+    mhl_fmt_flags &= ~MHL_BELL;
+
+  if (clear_option == -1)
+    /* use default */;
+  else if (clear_option)
+    mhl_fmt_flags |= MHL_CLEARSCREEN;
+  else
+    mhl_fmt_flags &= ~MHL_CLEARSCREEN;
+  
   format = mhl_format_compile (formfile);
   if (!format)
     exit (1);
   
-  argc -= index;
-  argv += index;
-
   if (argc == 0)
     nomoreproc = 1;
 
diff --git a/mh/scan.c b/mh/scan.c
index 6a14792..a938aa0 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -26,46 +26,9 @@
 #include <time.h>
 #include <mailutils/observer.h>
 
-static char doc[] = N_("GNU MH scan")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char progdoc[] = N_("GNU MH scan");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to scan")},
-  {"clear",   ARG_CLEAR, N_("BOOL"),   OPTION_ARG_OPTIONAL,
-   N_("clear screen after displaying the list")},
-  {"noclear", ARG_NOCLEAR, NULL, OPTION_HIDDEN, ""},
-  {"form",    ARG_FORM, N_("FILE"),   0,
-   N_("read format from given file")},
-  {"format",  ARG_FORMAT, N_("FORMAT"), 0,
-   N_("use this format string")},
-  {"header",  ARG_HEADER, N_("BOOL"),   OPTION_ARG_OPTIONAL,
-   N_("display header")},
-  {"width",   ARG_WIDTH, N_("NUMBER"), 0,
-   N_("set output width")},
-  {"reverse", ARG_REVERSE, N_("BOOL"),   OPTION_ARG_OPTIONAL,
-   N_("list messages in reverse order")},
-  {"noreverse", ARG_NOREVERSE, NULL, OPTION_HIDDEN, ""},
-  {"file",    ARG_FILE, N_("FILE"),   0,
-   N_("[not yet implemented]")},
-  
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "clear",   MH_OPT_BOOL },
-  { "form",    MH_OPT_ARG, "formatfile" },
-  { "format",  MH_OPT_ARG, "string" },
-  { "header",  MH_OPT_BOOL },
-  { "width",   MH_OPT_ARG, "number" },
-  { "reverse", MH_OPT_BOOL },
-  { "file",    MH_OPT_ARG, "file" },
-  { NULL }
-};
-
 static int clear;
 static char *format_str = mh_list_format;
 
@@ -77,66 +40,41 @@ static mh_format_t format;
 
 static mu_msgset_t msgset;
 
-static int list_message (size_t num, mu_message_t msg, void *data);
-void print_header (mu_mailbox_t mbox);
-void clear_screen (void);
-
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+form_handler (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-      
-    case ARG_CLEAR:
-      clear = is_true(arg);
-      break;
+  if (mh_read_formfile (arg, &format_str))
+    exit (1);
+}
 
-    case ARG_NOCLEAR:
-      clear = 0;
-      break;
-      
-    case ARG_FORM:
-      if (mh_read_formfile (arg, &format_str))
-	exit (1);
-      break;
-      
-    case ARG_FORMAT:
-      format_str = arg;
-      break;
-      
-    case ARG_HEADER:
-      header = is_true(arg);
-      break;
-      
-    case ARG_WIDTH:
-      width = strtoul (arg, NULL, 0);
-      if (!width)
-	{
-	  argp_error (state, _("invalid width"));
-	  exit (1);
-	}
-      break;
-      
-    case ARG_REVERSE:
-      reverse = is_true(arg);
-      break;
+static struct mu_option options[] = {
+  { "clear",   0, NULL, MU_OPTION_DEFAULT,
+    N_("clear screen after displaying the list"),
+    mu_c_bool, &clear },
+  { "form",    0, N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, NULL, form_handler },
+  { "format",  0, N_("FORMAT"), MU_OPTION_DEFAULT,
+    N_("use this format string"),
+    mu_c_string, &format_str },
+  { "header",  0, NULL,   MU_OPTION_DEFAULT,
+    N_("display header"),
+    mu_c_bool, &header },
+  { "width",   0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output width"),
+    mu_c_int, &width },
+  { "reverse",  0, NULL,   MU_OPTION_DEFAULT,
+    N_("list messages in reverse order"),
+    mu_c_bool, &reverse },
+  { "file",     0, N_("FILE"),   MU_OPTION_HIDDEN,
+    N_("[not yet implemented]"),
+    mu_c_string, NULL, mh_opt_notimpl },
+  MU_OPTION_END
+};
 
-    case ARG_NOREVERSE:
-      reverse = 0;
-      break;
-      
-    case ARG_FILE:
-      mh_opt_notimpl ("-file");
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
+static int list_message (size_t num, mu_message_t msg, void *data);
+void print_header (mu_mailbox_t mbox);
+void clear_screen (void);
 
 /* Observable Action this is called at every message discover.  */
 static int
@@ -161,7 +99,6 @@ action (mu_observer_t o, size_t type, void *data, void *action_data)
 int
 main (int argc, char **argv)
 {
-  int index;
   mu_mailbox_t mbox;
   int status;
   size_t total = 0;
@@ -169,9 +106,8 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, progdoc, NULL);
 
   if (mh_format_parse (format_str, &format))
     {
@@ -181,8 +117,6 @@ main (int argc, char **argv)
 
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
 
-  argc -= index;
-  argv += index;
   if ((argc == 0 || strcmp (argv[0], "all") == 0) && !reverse)
     {
       /* Fast approach */
diff --git a/mh/tests/burst.at b/mh/tests/burst.at
index 37a5c26..0ce3b26 100644
--- a/mh/tests/burst.at
+++ b/mh/tests/burst.at
@@ -90,7 +90,7 @@ Regards,
 Sergey
 ])
 
-burst +inbox --length=7 1 || exit $?
+burst +inbox -length 7 1 || exit $?
 grep -v ^X-Envelope- Mail/inbox/2
 grep -v ^X-Envelope- Mail/inbox/3
 grep -v ^X-Envelope- Mail/inbox/4
@@ -140,7 +140,7 @@ With gently smiling jaws!
 
 MH_CHECK([burst mime recursive],[burst03 burst-mime-recursive],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
-burst +inbox --recursive 4 || exit $?
+burst +inbox -recursive 4 || exit $?
 grep -v ^X-Envelope- Mail/inbox/6
 grep -v ^X-Envelope- Mail/inbox/7
 grep -v ^X-Envelope- Mail/inbox/8
diff --git a/mh/tests/folder.at b/mh/tests/folder.at
index 44d2d28..dcad899 100644
--- a/mh/tests/folder.at
+++ b/mh/tests/folder.at
@@ -99,13 +99,13 @@ Mail/inbox/4
 Mail/inbox/5
 ])
 
-MH_CHECK([folder --pack=N],[folder06 folder--pack=N],[
+MH_CHECK([folder -pack=N],[folder06 folder-pack=N],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 for i in 1 2 3 4 5
 do
   mv Mail/inbox/$i Mail/inbox/${i}0
 done
-folder --pack=1 || exit $?
+folder -pack=1 || exit $?
 find Mail/inbox -not -name '.mu-prop' | sort
 ],
 [0],


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 22 05:12:12 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bxsLc-00059J-90
	for mharc-commit-mailutils@gnu.org; Sat, 22 Oct 2016 05:12:12 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:59202)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxsLQ-00051J-2n
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 05:12:11 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxsLE-00064F-Ln
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 05:12:00 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:51265)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxsLE-000648-Do
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 05:11:48 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 1CCE922015E; Sat, 22 Oct 2016 09:11:48 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-789-ge267ac8
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: f434857b8318b05b7036025605ab18cdf3e7c238
X-Git-Newrev: e267ac86e2c3a78979fe12bdd16392f30f8d1725
Message-Id: <20161022091148.1CCE922015E@vcs.savannah.gnu.org>
Date: Sat, 22 Oct 2016 09:11:47 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Oct 2016 09:12:11 -0000

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

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

The branch, master has been updated
       via  e267ac86e2c3a78979fe12bdd16392f30f8d1725 (commit)
      from  f434857b8318b05b7036025605ab18cdf3e7c238 (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 e267ac86e2c3a78979fe12bdd16392f30f8d1725
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 22 11:48:24 2016 +0300

    Finish conversion of MH utilities to mh_parseopt
    
    This finishes work started at commit bc73fc65.
    
    * include/mailutils/opt.h (mu_option_cache) <cache_arg>: Made const.
    * libmailutils/opt/opt.c (mu_option_cache_destroy): Don't free cache_arg.
    * doc/texinfo/mu-mh.texi: Update.
    
    * po/POTFILES.in: Remove obsolete files.
    * mh/tests/refile.at: Don't use double-dash options.
    
    * mh/mh_getopt.c (mh_opt_set_folder): New function.
    * mh/mh_getopt.h: Likewise.
    
    * mh/mhn.c: Convert to mh_getopt.
    * mh/mhparam.c: Likewise.
    * mh/mhpath.c: Likewise.
    * mh/mhseq.c: Likewise.
    * mh/msgchk.c: Likewise.
    * mh/pick.c: Likewise.
    * mh/pick.h: Likewise.
    * mh/pick.y: Likewise.
    * mh/prompter.c: Likewise.
    * mh/refile.c: Likewise.
    * mh/repl.c: Likewise.
    * mh/rmf.c: Likewise.
    * mh/rmm.c: Likewise.
    * mh/scan.c: Likewise.
    * mh/send.c: Likewise.
    * mh/show.c: Likewise.
    * mh/sortm.c: Likewise.
    * mh/whatnow.c: Likewise.
    * mh/whom.c: Likewise.

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

Summary of changes:
 doc/texinfo/mu-mh.texi  |  108 +++++-----
 include/mailutils/opt.h |    2 +-
 libmailutils/opt/opt.c  |    5 +-
 mh/mh_getopt.c          |   73 ++++++-
 mh/mh_getopt.h          |    2 +
 mh/mhn.c                |  435 ++++++++++++-----------------------------
 mh/mhparam.c            |   65 ++----
 mh/mhpath.c             |   42 +---
 mh/mhseq.c              |   60 ++----
 mh/msgchk.c             |  129 +++++-------
 mh/pick.c               |  500 +++++++++++++++++++----------------------------
 mh/pick.h               |    2 +-
 mh/pick.y               |   18 +-
 mh/prompter.c           |  123 +++---------
 mh/refile.c             |  112 ++++-------
 mh/repl.c               |  358 +++++++++++++--------------------
 mh/rmf.c                |   76 ++-----
 mh/rmm.c                |   38 +---
 mh/scan.c               |    4 +-
 mh/send.c               |  323 ++++++++++--------------------
 mh/show.c               |  177 +++++++----------
 mh/sortm.c              |  305 ++++++++++++++---------------
 mh/tests/refile.at      |    4 +-
 mh/whatnow.c            |   95 +++------
 mh/whom.c               |  113 ++++-------
 po/POTFILES.in          |    1 -
 26 files changed, 1144 insertions(+), 2026 deletions(-)

diff --git a/doc/texinfo/mu-mh.texi b/doc/texinfo/mu-mh.texi
index 406871a..1b840f9 100644
--- a/doc/texinfo/mu-mh.texi
+++ b/doc/texinfo/mu-mh.texi
@@ -27,9 +27,6 @@ distribution directory.
 @subsection Major differences between Mailutils MH and other MH implementations
 
 @enumerate 1
-@item All programs use usual GNU long options.  The support for MH single-dash
-options is provided for backward compatibility;
-
 @item UUCP addresses are not supported;
 
 @item Mailutils supports a set of new format specifications
@@ -38,6 +35,12 @@ options is provided for backward compatibility;
 @item Mailutils provides a set of new profile variables
 (@pxref{Profile Variable Diffs});
 
+@item All programs recognize @option{--help} and @option{--version} options
+
+These options are recognized only if no other arguments are present in
+the command line.  Abbreviations are not recognized.  This makes Mailutils
+MH implementation compatible with the standard usage for GNU tools.
+
 @item Several programs behave differently (@pxref{Program
 Diffs});
 
@@ -150,7 +153,7 @@ This expression is used in default @file{replcomps} and
 @deftypefn {MH Format} boolean rcpt (@samp{to} | @samp{cc} | @samp{me} | @samp{all})
 
 This function returns true if the given element is present in the
-recipient mask (as modified by @option{--cc} or @option{--nocc} options) and
+recipient mask (as modified by @option{-cc} or @option{-nocc} options) and
 false otherwise.  It is used in default formats for @command{repl} and
 @command{comp}, e.g.: 
 
@@ -159,7 +162,7 @@ false otherwise.  It is used in default formats for @command{repl} and
 @end smallexample
 
 Notice that this means that usual @file{replcomps} file will be ignoring
-@option{--cc} and @option{--nocc} options, unless it has been modified
+@option{-cc} and @option{-nocc} options, unless it has been modified
 as shown above. 
 @end deftypefn
 
@@ -226,12 +229,12 @@ RAND @command{anno} displays the prompt anyway.
 
 The utility is able to burst both RFC 934 digest messages and MIME
 multipart messages.  It provides two additional command line options:
-@option{--recurse} and @option{--length}.
+@option{-recurse} and @option{-length}.
 
-The @option{--recurse} option instructs the utility to recursively
+The @option{-recurse} option instructs the utility to recursively
 expand the digest.
 
-The @option{--length} option can be used to set the minimal encapsulation
+The @option{-length} option can be used to set the minimal encapsulation
 boundary length for RFC 934 digests.  Default length is 1,
 i.e. encountering one dash immediately following a newline triggers
 digest decoding.  It is OK for messages that follow RFC 934
@@ -239,12 +242,12 @@ specification.  However, many user agents do not precisely follow it,
 in particular, they often do not escape lines starting with a dash by
 @samp{- } sequence.  @command{Mailman} is one of such agents.  To cope
 with such digests you can set encapsulation boundary length to a higher
-value.  For example, @command{bounce --length=8} has been found to be
+value.  For example, @command{bounce -length 8} has been found to be
 sufficient for most Mailman-generated digests.
 
 @item comp
 
-Understands @option{--build} option.
+Understands @option{-build} option.
 
 @item fmtdump
 
@@ -252,24 +255,24 @@ This command is not provided.  Use @option{fmtcheck} instead.
 
 @item inc
 @itemize @bullet
-@item The @option{--moveto} option.
-The @option{--moveto} option instructs @command{inc} to move
+@item The @option{-moveto} option.
+The @option{-moveto} option instructs @command{inc} to move
 messages into another folder after incorporating them.  This option
-has effect only if the @option{--truncate} option has also been
+has effect only if the @option{-truncate} option has also been
 specified and the underlying mailbox supports the @samp{move}
 operation.  Currently only @samp{imap} and @samp{imaps} mailboxes
 support it.  For example, the following command moves incorporated
 messages into the @samp{archive} folder:
 
 @example
-inc --file imaps://imap.gmail.com --moveto=archive
+inc -file imaps://imap.gmail.com -moveto=archive
 @end example
 
 The @samp{moveto} URL parameter can be used instead of this option,
 e.g.:
 
 @example
-inc --file 'imaps://imap.gmail.com;moveto=archive'
+inc -file 'imaps://imap.gmail.com;moveto=archive'
 @end example
 
 @item Multiple sources
@@ -294,7 +297,7 @@ Moves incorporated messages into another folder.  This was discussed
 above.
 
 @item nomoveto
-Disables the previous @option{--moveto} option.
+Disables the previous @option{-moveto} option.
 
 @item truncate[=@var{bool}]
 Controls source mailbox truncation.  If @var{bool} is not given or it is
@@ -333,13 +336,13 @@ The following format variables are silently ignored: @samp{center},
 @itemize @bullet
 
 @item New option
-New option @option{--compose} forces @command{mhn} editing mode.  This
+New option @option{-compose} forces @command{mhn} editing mode.  This
 is also the default mode.  This differs from the standard
 @command{mhn}, which switches to the editing mode only if no other
 options were given and the input file name coincides with the value of
 @env{mhdraft} environment variable.  
 
-@item Show mode (@option{--show})
+@item Show mode (@option{-show})
 If an appropriate mhn-show-type[/subtype] was not found, GNU @command{mhn}
 prints the decoded message content using @code{moreproc}
 variable.  Standard @command{mhn} in this case used to print @samp{don't
@@ -349,47 +352,28 @@ The default behaviour is to pipe the content to the standard input
 of the mhn-show-type[/subtype] command.  This is altered to using a
 temporary file if the command contains @code{%f} or @code{%F} escapes.
 
-@item Store mode (@option{--store})
+@item Store mode (@option{-store})
 If the @code{Content-Disposition} header contains @samp{filename=},
-and @command{mhn} is invoked with @option{--auto} switch, it
+and @command{mhn} is invoked with @option{-auto} switch, it
 transforms the file name into the absolute notation and uses it only
 if it lies below the current mhn-storage directory.  Standard
 @command{mhn} only requires that the file name do not begin with @samp{/}.
 
 Before saving a message part, GNU @command{mhn} checks if the file already
 exists.  If so, it asks whether the user wishes to rewrite it.  This
-behaviour is disabled when @option{--quiet} option was given.
+behaviour is disabled when @option{-quiet} option was given.
 @end itemize
 
 @item mhparam
 
-The @option{--all} mode does not display commented out entries.
+The @option{-all} mode does not display commented out entries.
 
 @item pick
 
-The command line syntax @option{--@var{component} @var{string}}) is
-recognized only if at least one of the following conditions is met:
-
-@itemize @bullet
-@item The word @var{component} contains at least one capital letter.
-E.g.  @option{--User-Agent Mailutils}.
-
-@item The word @var{component} ends with a colon, as in
-@option{user-agent: Mailutils}.
-
-@item Standard input is not connected to a terminal.
-@end itemize
-
-The GNU syntax for component matching is:
-
-@smallexample
-pick --component @var{field} --pattern @var{string}
-@end smallexample
-
-New command line option @option{--cflags} allows to control the type of 
+New command line option @option{-cflags} allows to control the type of 
 regular expressions used.  The option must occur right before
-@option{--pattern} or @option{--component} option (or one of its
-aliases, like @option{--cc}, @option{--from}, etc.)
+@option{--@var{component} @var{pattern}} or equivalent construct (like
+@option{-cc}, @option{-from}, etc.) 
 
 The argument to this option is a string of type specifications:
 
@@ -402,24 +386,24 @@ The argument to this option is a string of type specifications:
 
 Default is @samp{EI}.
 
-The flags remain in effect until the next occurrence of @option{--cflags}
+The flags remain in effect until the next occurrence of @option{-cflags}
 option.
 
 Sample usage:
 
 @smallexample
-pick --cflag BC --subject '*a string' 
+pick -cflag BC -subject '*a string' 
 @end smallexample
 
-The date comparison options (@option{--before} and @option{--after}
+The date comparison options (@option{-before} and @option{-after}
 accept date specifications in a wide variety of formats, e.g.:
 
 @smallexample
-pick --after 20030301
-pick --after 2003-03-01
-pick --after 01-mar-2003
-pick --after 2003-mar-01
-pick --before '1 year ago'
+pick -after 20030301
+pick -after 2003-03-01
+pick -after 01-mar-2003
+pick -after 2003-mar-01
+pick -before '1 year ago'
 etc...
 @end smallexample
 
@@ -454,11 +438,11 @@ will add it automatically.
 @item
 Linking messages between folders goes against the logic of Mailutils,
 so @command{refile} never makes links even if called with
-@option{--link} option.  The latter is actually a synonym for @option{--copy},
+@option{-link} option.  The latter is actually a synonym for @option{-copy},
 which preserves the original message.
 
 @item
-The @option{--preserve} option is not implemented.  It is retained for backward
+The @option{-preserve} option is not implemented.  It is retained for backward
 compatibility only.
 
 @item
@@ -467,7 +451,7 @@ Message specs and folder names may be interspersed.
 
 @item repl
 
-Understands @option{--use} option.  Disposition shell provides
+Understands @option{-use} option.  Disposition shell provides
 @code{use} command. 
 
 @item rmm
@@ -491,14 +475,14 @@ rmmproc:
 
 @item sortm
 
-New option @option{--numfield} specifies numeric comparison for the
+New option @option{-numfield} specifies numeric comparison for the
 given field. 
 
-Any number of @option{--datefield}, @option{--textfield} and
-@option{--numfield} options may be given, thus allowing to build sort
+Any number of @option{-datefield}, @option{-textfield} and
+@option{-numfield} options may be given, thus allowing to build sort
 criteria of arbitrary complexity. 
 
-The order of @option{--.*field} options sets the ordering priority.  This
+The order of @option{-.*field} options sets the ordering priority.  This
 differs from the behaviour of the standard @command{sortm}, which
 always orders datefield-major, textfield-minor.
 
@@ -506,11 +490,11 @@ Apart from sorting the mailfolder the following actions may be
 specified:
 
 @table @option
-@item --list
+@item -list
 List the ordered messages using a format string given by
-@option{--form} or @option{--format} option.
+@option{-form} or @option{-format} option.
 
-@item --dry-run
+@item -dry-run
 Do not actually sort messages, rather print what would have been
 done.  This is useful for debugging purposes.
 @end table
diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index efecd8f..6a7f2dc 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -71,7 +71,7 @@ typedef struct mu_option_cache *mu_option_cache_ptr_t;
 struct mu_option_cache
 {
   struct mu_option *cache_opt;
-  char *cache_arg;
+  char const *cache_arg;
 };
 
 #define MU_PARSEOPT_DEFAULT        0
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index fbe2868..3a34a7f 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -136,7 +136,6 @@ static void
 mu_option_cache_destroy (void *ptr)
 {
   struct mu_option_cache *cache = ptr;
-  free (cache->cache_arg);
   free (cache);
 }
 
@@ -150,7 +149,7 @@ add_option_cache (struct mu_parseopt *po, struct mu_option *opt,
 {
   struct mu_option_cache *cache = mu_alloc (sizeof (*cache));
   cache->cache_opt = opt;
-  cache->cache_arg = arg ? mu_strdup (arg) : NULL;
+  cache->cache_arg = arg;
 
   if ((po->po_flags & MU_PARSEOPT_IMMEDIATE)
        || (opt->opt_flags & MU_OPTION_IMMEDIATE))
@@ -774,7 +773,7 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
 	  free (errmsg);
 
 	  if (!(po->po_flags & MU_PARSEOPT_NO_ERREXIT))
-	    exit (EXIT_ERROR);
+	    exit (po->po_exit_error);
 	}
     }
 }
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index b4d92fb..50a034c 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -79,6 +79,23 @@ augment_argv (int *pargc, char ***pargv)
 }
 
 static void
+process_std_options (int argc, char **argv, struct mu_parseopt *po)
+{
+  if (argc != 1)
+    return;
+  if (strcmp (argv[0], "--help") == 0)
+    {
+      mu_program_help (po, mu_strout);
+      exit (0);
+    }
+  if (strcmp (argv[0], "--version") == 0)
+    {
+      mu_program_version (po, mu_strout);
+      exit (0);
+    }
+}
+  
+static void
 process_folder_arg (int *pargc, char **argv, struct mu_parseopt *po)
 {
   int i, j;
@@ -109,8 +126,9 @@ process_folder_arg (int *pargc, char **argv, struct mu_parseopt *po)
   *pargc = j;
 }
 
-static void
-set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+void
+mh_opt_set_folder (struct mu_parseopt *po, struct mu_option *opt,
+		   char const *arg)
 {
   mh_set_current_folder (arg);
 }
@@ -118,7 +136,45 @@ set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 static struct mu_option folder_option[] = {
   { "folder", 0, NULL, MU_OPTION_DEFAULT,
     N_("set current folder"),
-    mu_c_string, NULL, set_folder },
+    mu_c_string, NULL, mh_opt_set_folder },
+  MU_OPTION_END
+};
+
+void
+mh_version_hook (struct mu_parseopt *po, mu_stream_t stream)
+{
+  extern const char mu_version_copyright[];
+#ifdef GIT_DESCRIBE
+  mu_stream_printf (stream, "%s (GNU MH, %s) %s [%s]\n",
+		    mu_program_name, PACKAGE_NAME, PACKAGE_VERSION,
+		    GIT_DESCRIBE);
+#else
+  mu_stream_printf (stream, "%s (GNU MH, %s) %s\n", mu_program_name,
+		    PACKAGE_NAME, PACKAGE_VERSION);
+#endif
+  /* TRANSLATORS: Translate "(C)" to the copyright symbol
+     (C-in-a-circle), if this symbol is available in the user's
+     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
+  mu_stream_printf (stream, mu_version_copyright, _("(C)"));
+  mu_stream_printf (stream, _("\
+\n\
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\n\
+\n\
+"));
+}
+
+static void
+fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
+{
+  mu_program_version (po, mu_strout);
+  exit (0);
+}
+
+static struct mu_option version_option[] = {
+  { "version", 0, NULL, MU_OPTION_DEFAULT,
+    N_("print program version"),
+    mu_c_string, NULL, fn_version },
   MU_OPTION_END
 };
 
@@ -132,7 +188,7 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   struct mu_parseopt po;
   struct mu_option *optv[3];
   struct getopt_data getopt_data;
-  char const *args[2];
+  char const *args[3];
   int flags = MU_PARSEOPT_SINGLE_DASH | MU_PARSEOPT_IMMEDIATE;
   int i;
   
@@ -177,6 +233,9 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   //po.po_extra_info = gnu_general_help_url;
   //flags |= MU_PARSEOPT_EXTRA_INFO;
 
+  po.po_version_hook = mh_version_hook;
+  flags |= MU_PARSEOPT_VERSION_HOOK;
+  
   mu_set_program_name (argv[0]);
   mh_init ();
   augment_argv (&argc, &argv);
@@ -184,7 +243,9 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   i = 0;
   if (mhflags & MH_GETOPT_DEFAULT_FOLDER)
     optv[i++] = folder_option;
-  optv[i++] = options;
+  if (options)
+    optv[i++] = options;
+  optv[i++] = version_option;
   optv[i] = NULL;
   
   if (mu_parseopt (&po, argc, argv, optv, flags))
@@ -193,6 +254,8 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   argc -= po.po_arg_start;
   argv += po.po_arg_start;
 
+  process_std_options (argc, argv, &po);
+  
   process_folder_arg (&argc, argv, &po);
 
   if (!argdoc && argc)
diff --git a/mh/mh_getopt.h b/mh/mh_getopt.h
index b361653..2dcd57a 100644
--- a/mh/mh_getopt.h
+++ b/mh/mh_getopt.h
@@ -35,5 +35,7 @@ void mh_opt_find_file (struct mu_parseopt *po, struct mu_option *opt,
 		       char const *arg);
 void mh_opt_read_formfile (struct mu_parseopt *po, struct mu_option *opt,
 			   char const *arg);
+void mh_opt_set_folder (struct mu_parseopt *po, struct mu_option *opt,
+			char const *arg);
 
 
diff --git a/mh/mhn.c b/mh/mhn.c
index 04f713c..1f04c6f 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -22,99 +22,9 @@
 #include <mailutils/mime.h>
 #include <setjmp.h>
 
-static char doc[] = N_("GNU MH mhn")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH mhn");
 static char args_doc[] = N_("[MSGLIST]");
 
-static struct argp_option options[] = {
-  {"folder",       ARG_FOLDER,       N_("FOLDER"), 0,
-   N_("specify folder to operate upon"), 0},
-  {"file",         ARG_FILE,         N_("FILE"),   0,
-   N_("specify file to operate upon"), 0},
-
-#define GRID 10
-  {N_("MIME editing options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
-  {"compose",      ARG_COMPOSE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("compose the MIME message (default)"), GRID+1},
-  {"build",        0,                NULL,       OPTION_ALIAS,
-   NULL, GRID+1 },
-  {"nocompose",    ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN, NULL, GRID+1},
-  {"nobuild",      ARG_NOCOMPOSE,    NULL, OPTION_HIDDEN|OPTION_ALIAS,
-   NULL, GRID+1},
-#undef GRID
-#define GRID 20  
-  {N_("Listing options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
-  {"list",         ARG_LIST,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("list the table of contents"), GRID+1 },
-  {"nolist",       ARG_NOLIST,       NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"headers",      ARG_HEADER,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print the banner above the listing"), GRID+1 },
-  {"noheaders",    ARG_NOHEADERS,    NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"realsize",     ARG_REALSIZE,     N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("list the decoded sizes"), GRID+1 },
-  {"norealsize",   ARG_NOREALSIZE,   NULL, OPTION_HIDDEN, "", GRID+1 },
-#undef GRID
-#define GRID 40
-  {N_("Display options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
-  {"show",         ARG_SHOW,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("display the contents of the messages"), GRID+1},
-  {"noshow",       ARG_NOSHOW,       NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"serialonly",   ARG_SERIALONLY,   N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* display messages serially"), GRID+1},
-  {"noserialonly", ARG_NOSERIALONLY, NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"form",         ARG_FORM,         N_("FILE"), 0,
-   N_("read mhl format from FILE"), GRID+1},
-  {"pause",        ARG_PAUSE,        N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("pause prior to displaying content"), GRID+1},
-  {"nopause",      ARG_NOPAUSE,      NULL, OPTION_HIDDEN, "", GRID+1 },
-#undef GRID
-#define GRID 50
-  {N_("Saving options"),   0,  NULL, OPTION_DOC,  NULL, GRID},
-  {"store",        ARG_STORE,        N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("write extracted message parts to disk"), GRID+1},
-  {"nostore",      ARG_NOSTORE,      NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"auto",         ARG_AUTO,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("use filenames from the content headers"), GRID+1},
-  {"noauto",       ARG_NOAUTO,       NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"charset",      ARG_CHARSET,      N_("NAME"), 0,
-   N_("use this charset to represent attachment file names"), GRID+1},
-#undef GRID
-#define GRID 60
-  {N_("Other options"),    0,  NULL, OPTION_DOC,  NULL, GRID},
-  {"part",         ARG_PART,         N_("PART"), 0,
-   N_("limit the scope of the operation to the given part"), GRID+1},
-  {"type",         ARG_TYPE,         N_("CONTENT"), 0,
-   N_("operate on message part with given multipart content"), GRID+1 },
-  {"verbose",      ARG_VERBOSE,     N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print additional information"), GRID+1 },
-  {"noverbose",    ARG_NOVERBOSE,   NULL, OPTION_HIDDEN, "", GRID+1 },
-  {"quiet",        ARG_QUIET, 0, 0,
-   N_("be quiet"), GRID+1},
-#undef GRID
-  {NULL}
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "file",          MH_OPT_ARG, "filename" },
-  { "compose" },
-  { "build" },
-  { "list",          MH_OPT_BOOL },
-  { "headers",       MH_OPT_BOOL },
-  { "realsize",      MH_OPT_BOOL },
-  { "show",          MH_OPT_BOOL },
-  { "serialonly",    MH_OPT_BOOL },
-  { "form",          MH_OPT_ARG, "formfile" },
-  { "pause",         MH_OPT_BOOL },
-  { "store",         MH_OPT_BOOL },
-  { "auto",          MH_OPT_BOOL },
-  { "part",          MH_OPT_ARG, "part" },
-  { "type",          MH_OPT_ARG, "type" },
-  { "verbose",       MH_OPT_BOOL },
-  { NULL }
-};
-
 typedef struct _msg_part *msg_part_t;
 
 static msg_part_t msg_part_create (size_t num);
@@ -124,28 +34,22 @@ static void msg_part_incr (msg_part_t p);
 static void msg_part_decr (msg_part_t p);
 static void msg_part_set_subpart (msg_part_t p, size_t subpart);
 static void msg_part_print (msg_part_t p, int width);
-static msg_part_t msg_part_parse (char *str);
+static msg_part_t msg_part_parse (char const *str);
 static int msg_part_level (msg_part_t p);
 static size_t msg_part_subpart (msg_part_t p, int level);
 
-enum mhn_mode
-  {
-    mode_compose,
-    mode_list,
-    mode_show,
-    mode_store,
-  };
-
-static enum mhn_mode mode = mode_compose;
+static int compose_option;
+static int list_option; 
+static int show_option;
+static int store_option;
 
-#define OPT_HEADERS    001
-#define OPT_REALSIZE   002
-#define OPT_AUTO       004
-#define OPT_SERIALONLY 010
-#define OPT_VERBOSE    020
-#define OPT_QUIET      040
+static int headers_option = 1;
+static int realsize_option;
+static int auto_option;
+/*static int serialonly_option;*/
+static int verbose_option;
+static int quiet_option;
 
-static int mode_options = OPT_HEADERS;
 static int pause_option = -1; /* -pause option. -1 means "not given" */
 static char *formfile;
 static char *content_type;
@@ -260,173 +164,88 @@ _get_content_encoding (mu_header_t hdr, char **value)
   *value = encoding;
   return 0;
 }
-
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+
+static void
+set_part (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_FILE:
-      input_file = arg;
-      break;
-      
-      /* Operation mode */
-    case ARG_COMPOSE:
-      if (is_true (arg))
-	{
-	  mode = mode_compose;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOCOMPOSE:
-      if (mode == mode_compose)
-	mode = mode_compose;
-      break;
-
-    case ARG_LIST:
-      if (is_true (arg))
-	{
-	  mode = mode_list;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOLIST:
-      if (mode == mode_list)
-	mode = mode_compose;
-      break;
-
-    case ARG_SHOW:
-      if (is_true (arg))
-	{
-	  mode = mode_show;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOSHOW:
-      if (mode == mode_show)
-	mode = mode_compose;
-      break;
-
-    case ARG_STORE:
-      if (is_true (arg))
-	{
-	  mode = mode_store;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOSTORE:
-      if (mode == mode_store)
-	mode = mode_compose;
-      break;
-
-      /* List options */
-    case ARG_HEADER:
-      if (is_true (arg))
-	{
-	  mode_options |= OPT_HEADERS;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOHEADERS:
-      mode_options &= ~OPT_HEADERS;
-      break;
-      
-    case ARG_REALSIZE:
-      if (is_true (arg))
-	{
-	  mode_options |= OPT_REALSIZE;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOREALSIZE:
-      mode_options &= ~OPT_REALSIZE;
-      break;
-
-      /* Display options */
-
-    case ARG_SERIALONLY:
-      mh_opt_notimpl_warning ("-[no]serialonly");
-      if (is_true (arg))
-	{
-	  mode_options |= OPT_SERIALONLY;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOSERIALONLY:
-      mode_options &= ~OPT_SERIALONLY;
-      break;
-
-    case ARG_PAUSE:
-      pause_option = is_true (arg);
-      break;
-      
-    case ARG_NOPAUSE:
-      pause_option = 0;
-      break;
-
-      /* Store options */
-    case ARG_AUTO:
-      if (is_true (arg))
-	{
-	  mode_options |= OPT_AUTO;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOAUTO:
-      mode_options &= ~OPT_AUTO;
-      break;
-
-    case ARG_FORM:
-      mh_find_file (arg, &formfile);
-      break;
-
-      /* Common options */
-    case ARG_VERBOSE:
-      if (is_true (arg))
-	{
-	  mode_options |= OPT_VERBOSE;
-	  break;
-	}
-      /*FALLTHRU*/
-    case ARG_NOVERBOSE:
-      mode_options &= ~OPT_VERBOSE;
-      break;
-
-    case ARG_TYPE:
-      sfree (&content_type);
-      sfree (&content_subtype);
-      split_content (arg, &content_type, &content_subtype);
-      break;
-      
-    case ARG_PART:
-      req_part = msg_part_parse (arg);
-      break;
-
-    case ARG_QUIET:
-      mode_options |= OPT_QUIET;
-      break;
-	
-    case ARG_CHARSET:
-      charset = arg;
-      break;
-      
-    case ARGP_KEY_FINI:
-      if (!formfile)
-	mh_find_file ("mhl.headers", &formfile);
-      if (!isatty (0))
-	pause_option = 0;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+  req_part = msg_part_parse (arg);
 }
 
+static void
+set_type (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  sfree (&content_type);
+  sfree (&content_subtype);
+  split_content (arg, &content_type, &content_subtype);
+}
+
+static struct mu_option options[] = {
+  { "folder",      0,       N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify folder to operate upon"),
+    mu_c_string, NULL, mh_opt_set_folder },
+  { "file",        0,       N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("specify file to operate upon"),
+    mu_c_string, &input_file },
+
+  MU_OPTION_GROUP (N_("MIME editing options")),
+  { "compose",     0,       NULL, MU_OPTION_DEFAULT,
+    N_("compose the MIME message (default)"),
+    mu_c_bool, &compose_option },
+  { "build",       0,       NULL, MU_OPTION_ALIAS },
+
+  MU_OPTION_GROUP (N_("Listing options")),
+  { "list",        0,       NULL, MU_OPTION_DEFAULT,
+    N_("list the table of contents"),
+    mu_c_bool, &list_option },
+  { "headers",     0,       NULL, MU_OPTION_DEFAULT,
+    N_("print the banner above the listing"),
+    mu_c_bool, &headers_option },
+  { "realsize",    0,       NULL, MU_OPTION_DEFAULT,
+    N_("list the decoded sizes"),
+    mu_c_bool, &realsize_option },
+
+  MU_OPTION_GROUP (N_("Display options")),
+  { "show",        0,       NULL, MU_OPTION_DEFAULT,
+    N_("display the contents of the messages"),
+    mu_c_bool, &show_option },
+  { "serialonly",  0,       NULL, MU_OPTION_HIDDEN,
+    "",
+    mu_c_bool, NULL, mh_opt_notimpl_warning },
+  { "form",        0,       N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read mhl format from FILE"),
+    mu_c_string, &formfile, mh_opt_find_file },
+  { "pause",       0,       NULL, MU_OPTION_DEFAULT,
+    N_("pause prior to displaying content"),
+    mu_c_bool, &pause_option },
+
+  MU_OPTION_GROUP (N_("Saving options")),
+  { "store",        0,       NULL, MU_OPTION_DEFAULT,
+    N_("write extracted message parts to disk"),
+    mu_c_bool, &store_option },
+  { "auto",         0,       NULL, MU_OPTION_DEFAULT,
+    N_("use filenames from the content headers"),
+    mu_c_bool, &auto_option },
+  { "charset",      0,       N_("NAME"), MU_OPTION_DEFAULT,
+    N_("use this charset to represent attachment file names"),
+    mu_c_string, &charset },
+
+  MU_OPTION_GROUP (N_("Other options")),
+  { "part",         0,       N_("PART"), MU_OPTION_DEFAULT,
+    N_("limit the scope of the operation to the given part"),
+    mu_c_string, NULL, set_part },
+  { "type",         0,       N_("CONTENT"), MU_OPTION_DEFAULT,
+    N_("operate on message part with given multipart content"),
+    mu_c_string, NULL, set_type },
+  { "verbose",      0,       NULL, MU_OPTION_DEFAULT,
+    N_("print additional information"),
+    mu_c_bool, &verbose_option },
+  { "quiet",        0,       NULL, MU_OPTION_DEFAULT,
+    N_("be quiet"),
+    mu_c_bool, &quiet_option },
+
+  MU_OPTION_END
+};
+
 
 /* *********************** Message part functions ************************* */
 
@@ -555,7 +374,7 @@ msg_part_format_pool (mu_opool_t pool, msg_part_t p)
 }
 
 msg_part_t
-msg_part_parse (char *str)
+msg_part_parse (char const *str)
 {
   msg_part_t p = msg_part_create (0);
 
@@ -1267,7 +1086,7 @@ mhn_message_size (mu_message_t msg, mu_off_t *psize)
   
   *psize = 0;
   mu_message_get_body (msg, &body);
-  if (mode_options & OPT_REALSIZE)
+  if (realsize_option)
     {
       mu_stream_t dstr = NULL, bstr = NULL;
 
@@ -1389,7 +1208,7 @@ mhn_list ()
 {
   int rc; 
 
-  if (mode_options & OPT_HEADERS)
+  if (headers_option)
     printf (_(" msg part type/subtype              size  description\n"));
 
   if (message)
@@ -1672,7 +1491,7 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
   if (mu_message_is_multipart (msg, &ismime) == 0 && ismime)
     return 0;
   
-  if (mode_options & OPT_AUTO)
+  if (auto_option)
     {
       char *val;
       int rc = mu_message_aget_decoded_attachment_name (msg, charset,
@@ -1773,7 +1592,7 @@ store_handler (mu_message_t msg, msg_part_t part, char *type, char *encoding,
       printf (_("storing message %s part %s as file %s\n"),
 	      prefix, partstr, name);
 
-      if (!(mode_options & OPT_QUIET) && access (name, R_OK) == 0)
+      if (!quiet_option && access (name, R_OK) == 0)
 	{
 	  int ok;
 	  
@@ -2939,17 +2758,18 @@ int
 main (int argc, char **argv)
 {
   int rc;
-  int index;
   
   MU_APP_INIT_NLS ();
   
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
-  argc -= index;
-  argv += index;
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
+  if (!formfile)
+    mh_find_file ("mhl.headers", &formfile);
+  if (!isatty (0))
+    pause_option = 0;
 
+  if (!compose_option && !list_option && !show_option && !store_option)
+    show_option = 1;
+  
   signal (SIGPIPE, SIG_IGN);
 
   if (input_file)
@@ -2966,45 +2786,36 @@ main (int argc, char **argv)
       if (!message)
 	return 1;
     }
-  else if (mode == mode_compose)
+  
+  if (compose_option)
     {
       if (argc > 1)
 	{
 	  mu_error (_("extra arguments"));
 	  return 1;
 	}
-      input_file = mh_expand_name (mu_folder_directory (),
-				   argc == 1 ? argv[0] : "draft", NAME_ANY);
-      message = mh_file_to_message (NULL, input_file);
-      if (!message)
-	return 1;
+      if (!input_file)
+	{
+	  input_file = mh_expand_name (mu_folder_directory (),
+				       argc == 1
+				         ? argv[0] : "draft", NAME_ANY);
+	  message = mh_file_to_message (NULL, input_file);
+	  if (!message)
+	    return 1;
+	}
+      rc = mhn_compose ();
     }
   else
     {
       mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
       mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
-    }
-  
-  switch (mode)
-    {
-    case mode_compose:
-      rc = mhn_compose ();
-      break;
-      
-    case mode_list:
-      rc = mhn_list ();
-      break;
-      
-    case mode_show:
-      rc = mhn_show ();
-      break;
-      
-    case mode_store:
-      rc = mhn_store ();
-      break;
-      
-    default:
-      abort ();
+      /* FIXME: Combine the three */
+      if (list_option)
+	rc = mhn_list ();
+      if (show_option)
+	rc |= mhn_show ();
+      if (store_option)
+	rc |= mhn_store ();
     }
   return rc ? 1 : 0;
 }
diff --git a/mh/mhparam.c b/mh/mhparam.c
index b08b5d3..12733de 100644
--- a/mh/mhparam.c
+++ b/mh/mhparam.c
@@ -19,48 +19,22 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH mhparam")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH mhparam");
 static char args_doc[] = N_("[COMPONENT [COMPONENT...]]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"all",  ARG_ALL, NULL, 0,
-   N_("display all components from the MH profile. All other arguments are ignored")},
-  {"component", ARG_COMPONENT, N_("BOOL"),   OPTION_ARG_OPTIONAL,
-   N_("always display the component name") },
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "all" },
-  { "component", MH_OPT_BOOL },
-  { NULL }
-};
-
 static int display_all;
 static int display_comp_name = -1;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_ALL:
-      display_all = 1;
-      break;
-      
-    case ARG_COMPONENT:
-      display_comp_name = is_true (arg);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+static struct mu_option options[] = {
+  { "all",  0, NULL, MU_OPTION_DEFAULT,
+    N_("display all components from the MH profile. All other arguments are ignored"),
+    mu_c_bool, &display_all },
+  { "component", 0, NULL, MU_OPTION_DEFAULT,
+    N_("always display the component name"),
+    mu_c_bool, &display_comp_name },
+  MU_OPTION_END
+};
+
 static struct {
   char *comp;
   char *val;
@@ -81,7 +55,8 @@ mhparam_defval (char *comp)
 }
 
 int
-mhparam_iterator (const char *comp, const char *value, void *data MU_ARG_UNUSED)
+mhparam_iterator (const char *comp, const char *value,
+		  void *data MU_ARG_UNUSED)
 {
   if (display_comp_name)
     printf("%s:\t", comp);
@@ -112,14 +87,10 @@ mhparam (char *comp)
 int
 main (int argc, char **argv)
 {
-  int index;
-  
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (display_all)
     {
@@ -129,11 +100,13 @@ main (int argc, char **argv)
     }
   else
     {
+      int i;
+      
       if (display_comp_name == -1)
-	display_comp_name = argc - index > 1;
+	display_comp_name = argc > 1;
 	
-      for (; index < argc; index++)
-	mhparam (argv[index]);
+      for (i = 0; i < argc; i++)
+	mhparam (argv[i]);
     }
   return 0;
 }
diff --git a/mh/mhpath.c b/mh/mhpath.c
index 4da5da3..9ef8b6c 100644
--- a/mh/mhpath.c
+++ b/mh/mhpath.c
@@ -19,37 +19,9 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH mhpath")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH mhpath");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { NULL }
-};
-
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER:
-      mh_set_current_folder (arg);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
 static int
 mhpath (size_t num, mu_message_t msg, void *data)
 {
@@ -63,7 +35,6 @@ mhpath (size_t num, mu_message_t msg, void *data)
 int
 main (int argc, char **argv)
 {
-  int index = 0;
   mu_mailbox_t mbox = NULL;
   mu_url_t url = NULL;
   char *mhdir;
@@ -75,9 +46,8 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
 
   current_folder = mh_current_folder ();
   /* If  the  only argument  is `+', your MH Path is output; this
@@ -98,7 +68,7 @@ main (int argc, char **argv)
 
   /* If no `msgs' are specified, mhpath outputs the folder pathname
      instead.  */
-  if (index == argc)
+  if (argc == 0)
     {
       printf ("%s\n", mhdir);
       exit (0);
@@ -112,7 +82,7 @@ main (int argc, char **argv)
      The  "new"  message  may  not be used as part of a message
      range. */
   
-  if (argc - index == 1 && strcmp (argv[index], "new") == 0)
+  if (argc == 1 && strcmp (argv[0], "new") == 0)
     {
       mu_message_t msg = NULL;
       size_t num;
@@ -126,7 +96,7 @@ main (int argc, char **argv)
   /* Mhpath  expands  and  sorts  the  message  list `msgs' and
      writes the full pathnames of the messages to the  standard
      output separated by newlines. */
-  mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur");
+  mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
   status = mu_msgset_foreach_message (msgset, mhpath, mhdir);
   mu_mailbox_close (mbox);
   mu_mailbox_destroy (&mbox);
diff --git a/mh/mhseq.c b/mh/mhseq.c
index d9c4d1d..142903c 100644
--- a/mh/mhseq.c
+++ b/mh/mhseq.c
@@ -18,51 +18,21 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH mhseq")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH mhseq");
 static char args_doc[] = N_("[SEQUENCE]");
 
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify the folder to use")},
-  { "uids",  'u', NULL, 0,
-    N_("show message UIDs (default)")},
-  { "numbers", 'n', NULL, 0,
-    N_("show message numbers") },
-  { NULL }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "uid" },
-  { NULL }
-};
-
 static int uid_option = 1;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case 'n':
-      uid_option = 0;
-      break;
-      
-    case 'u':
-      uid_option = 1;
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+static struct mu_option options[] = {
+  { "uids",   0, NULL, MU_OPTION_DEFAULT,
+    N_("show message UIDs (default)"),
+    mu_c_int, &uid_option, NULL, "1" },
+  { "numbers", 0, NULL, MU_OPTION_DEFAULT,
+    N_("show message numbers"),
+    mu_c_int, &uid_option, NULL, "0" },
+  MU_OPTION_END
+};
+
 static int
 _print_number (size_t n, void *data)
 {
@@ -73,19 +43,15 @@ _print_number (size_t n, void *data)
 int
 main (int argc, char **argv)
 {
-  int index;
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
     
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
 
-  argc -= index;
-  argv += index;
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
 
   mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
diff --git a/mh/msgchk.c b/mh/msgchk.c
index 3153bfd..c9f63d5 100644
--- a/mh/msgchk.c
+++ b/mh/msgchk.c
@@ -21,42 +21,9 @@
 #include "mailutils/datetime.h"
 #include <pwd.h>
 
-static char doc[] = N_("GNU MH msgchk")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH msgchk");
 static char args_doc[] = N_("USER [USER...]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"date",         ARG_DATE,    N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print out the last date mail was read") },
-  {"nodate",       ARG_NODATE,  NULL, OPTION_HIDDEN,
-   N_("don't print out the last date mail was read") },
-  {"notify",       ARG_NOTIFY, "all|mail|nomail", 0,
-   N_("produce a message upon these events") },
-  {"nonotify",     ARG_NONOTIFY, "all|mail|nomail", 0,
-   N_("disable notification") },
-  {"host",         ARG_HOST,     N_("URL"), 0,
-   N_("check mail on this host or URL") },
-  {"user",         ARG_USER,     N_("NAME"), 0,
-   N_("set user name for remote mailbox access") },
-  {"apop",         ARG_APOP,    N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("enable APOP") },
-  {"noapop",       ARG_NOAPOP,  NULL, OPTION_HIDDEN,
-   N_("disable APOP") },
-  {NULL}
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "date", MH_OPT_BOOL },
-  { "notify", MH_OPT_ARG, "all|mail|nomail" },
-  { "nonotify", MH_OPT_ARG, "all|mail|nomail" },
-  { "host", MH_OPT_ARG, "host-or-url" },
-  { "user", MH_OPT_ARG, "name" },
-  { "apop", MH_OPT_BOOL },
-  { NULL }
-};
-
 int date_option = 1;
 int apop_option;
 char *remote_host;
@@ -75,55 +42,53 @@ static struct mu_kwd notifytab[] = {
   { NULL }
 };
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_notify (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
   int n;
-  
-  switch (key)
+  if (mu_kwd_xlat_name (notifytab, arg, &n))
     {
-    case ARG_DATE:
-      date_option = is_true (arg);
-      break;
-      
-    case ARG_NODATE:
-      date_option = 0;
-      break;
-      
-    case ARG_APOP:
-      apop_option = is_true (arg);
-      break;
-      
-    case ARG_NOAPOP:
-      apop_option = 0;
-      break;
-      
-    case ARG_NOTIFY:
-      if (mu_kwd_xlat_name (notifytab, arg, &n))
-	argp_error (state, "unknown notify argument: %s", arg);
-      notify |= n;
-      break;
-      
-    case ARG_NONOTIFY:
-      if (mu_kwd_xlat_name (notifytab, arg, &n))
-	argp_error (state, "unknown notify argument: %s", arg);
-      notify &= ~n;
-      break;
-      
-    case ARG_USER:
-      remote_user = arg;
-      break;
-      
-    case ARG_HOST:
-      remote_host = arg;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
+      mu_parseopt_error (po, "unknown notify argument: %s", arg);
+      exit (po->po_exit_error);
     }
-  return 0;
+  notify |= n;
 }
 
+static void
+clr_notify (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  int n;
+  if (mu_kwd_xlat_name (notifytab, arg, &n))
+    {
+      mu_parseopt_error (po, "unknown notify argument: %s", arg);
+      exit (po->po_exit_error);
+    }
+  notify &= ~n;
+}
+  
+static struct mu_option options[] = {
+  { "date",        0,    NULL, MU_OPTION_DEFAULT,
+    N_("print out the last date mail was read"),
+    mu_c_bool, &date_option },
+  { "notify",      0, "all|mail|nomail", MU_OPTION_DEFAULT,
+    N_("produce a message upon these events"),
+    mu_c_string, NULL, set_notify },
+  { "nonotify",    0, "all|mail|nomail", MU_OPTION_DEFAULT,
+    N_("disable notification"),
+    mu_c_string, NULL, clr_notify },
+  { "host",        0,  N_("URL"), MU_OPTION_DEFAULT,
+    N_("check mail on this host or URL"),
+    mu_c_string, &remote_host },
+  { "user",        0,  N_("NAME"), MU_OPTION_DEFAULT,
+    N_("set user name for remote mailbox access"),
+    mu_c_string, &remote_user },
+  { "apop",        0,  NULL, MU_OPTION_DEFAULT,
+    N_("enable APOP"),
+    mu_c_bool, &apop_option },
+  
+  MU_OPTION_END
+};
+
 static char *
 attach_auth_ticket (mu_mailbox_t mbox)
 {
@@ -185,7 +150,7 @@ checkmail (const char *username, int personal)
     {
       static mu_url_t pop_hint;
 
-      if (pop_hint)
+      if (!pop_hint)
 	{
 	  rc = mu_url_create (&pop_hint, "pop://");
 	  if (rc)
@@ -382,17 +347,11 @@ checkmail (const char *username, int personal)
 int
 main (int argc, char **argv)
 {
-  int index;
   int rc = 0;
   
   MU_APP_INIT_NLS ();
-  
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
 
-  argc -= index;
-  argv += index;
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);  
 
   if (argc == 0)
     {
diff --git a/mh/pick.c b/mh/pick.c
index ac62c3a..3624267 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -22,119 +22,11 @@
 #include <pick.h>
 #include <pick-gram.h>
 
-static char doc[] = N_("GNU MH pick")"\v"
-N_("Compatibility syntax for picking a matching component is:\n\
-\n\
-  --Component pattern\n\
-\n\
-where Component is the component name, containing at least one capital\n\
-letter or followed by a colon, e.g.:\n\
-\n\
-  --User-Agent Mailutils\n\
-  --user-agent: Mailutils\n\
-\n\
-Use -help to obtain a list of traditional MH options.");
-static char args_doc[] = N_("[MSGLIST]");
-
-/* GNU options */
-static struct argp_option options[] = {
-#define GRID 10
-  { "folder",  ARG_FOLDER, N_("FOLDER"), 0,
-    N_("specify folder to operate upon"), GRID },
-#undef GRID
-
-#define GRID 20
-  { N_("Search patterns"), 0,  NULL, OPTION_DOC,  NULL, GRID },
-  { "component", ARG_COMPONENT, N_("FIELD"), 0,
-    N_("search the named header field"), GRID+1},
-  { "pattern", ARG_PATTERN, N_("STRING"), 0,
-    N_("set pattern to look for"), GRID+1 },
-  { "search",  0, NULL, OPTION_ALIAS, NULL, GRID+1 },
-  { "cflags",  ARG_CFLAGS,  N_("STRING"), 0,
-    N_("flags controlling the type of regular expressions. STRING must consist of one or more of the following letters: B=basic, E=extended, I=ignore case, C=case sensitive. Default is \"EI\". The flags remain in effect until the next occurrence of --cflags option. The option must occur right before --pattern or --component option (or its alias)."), GRID+1 },
-  { "cc",      ARG_CC,      N_("STRING"), 0,
-    N_("same as --component cc --pattern STRING"), GRID+1 },
-  { "date",    ARG_DATE,    N_("STRING"), 0,
-    N_("same as --component date --pattern STRING"), GRID+1 },
-  { "from",    ARG_FROM,    N_("STRING"), 0,
-    N_("same as --component from --pattern STRING"), GRID+1 },
-  { "subject", ARG_SUBJECT, N_("STRING"), 0,
-    N_("same as --component subject --pattern STRING"), GRID+1 },
-  { "to",      ARG_TO,      N_("STRING"), 0,
-    N_("same as --component to --pattern STRING"), GRID+1 },
-#undef GRID
-
-#define GRID 30  
-  { N_("Date constraint operations"), 0,  NULL, OPTION_DOC, NULL, GRID },
-  { "datefield",ARG_DATEFIELD, N_("STRING"), 0,
-    N_("search in the named date header field (default is `Date:')"), GRID+1 },
-  { "after",    ARG_AFTER,     N_("DATE"), 0,
-    N_("match messages after the given date"), GRID+1 },
-  { "before",   ARG_BEFORE,    N_("DATE"), 0,
-    N_("match messages before the given date"), GRID+1 },
-#undef GRID
-
-#define GRID 40
-  { N_("Logical operations and grouping"), 0, NULL, OPTION_DOC, NULL, GRID },
-  { "and",     ARG_AND,    NULL, 0,
-    N_("logical AND (default)"), GRID+1 },
-  { "or",      ARG_OR,     NULL, 0,
-    N_("logical OR"), GRID+1 },
-  { "not",     ARG_NOT,    NULL, 0,
-    N_("logical NOT"), GRID+1 },
-  { "lbrace",  ARG_LBRACE, NULL, 0,
-    N_("open group"), GRID+1 },
-  { "(",       0, NULL, OPTION_ALIAS, NULL, GRID+1 },
-  { "rbrace",  ARG_RBRACE, NULL, 0,
-    N_("close group"), GRID+1},
-  { ")",       0, NULL, OPTION_ALIAS, NULL, GRID+1 },
-#undef GRID
-
-#define GRID 50
-  { N_("Operations over the selected messages"), 0, NULL, OPTION_DOC, NULL,
-    GRID },
-  { "list",   ARG_LIST,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("list the numbers of the selected messages (default)"), GRID+1 },
-  { "nolist", ARG_NOLIST,     NULL, OPTION_HIDDEN, "", GRID+1 },
-  { "sequence", ARG_SEQUENCE,  N_("NAME"), 0,
-    N_("add matching messages to the given sequence"), GRID+1 },
-  { "public", ARG_PUBLIC, N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("create public sequence"), GRID+1 },
-  { "nopublic", ARG_NOPUBLIC, NULL, OPTION_HIDDEN, "", GRID+1 },
-  { "zero",     ARG_ZERO,     N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("empty the sequence before adding messages"), GRID+1 },
-  { "nozero", ARG_NOZERO, NULL, OPTION_HIDDEN, "", GRID+1 },
-#undef GRID
-
-  { NULL }
-  
-};
+static char prog_doc[] = N_("GNU MH pick");
+static char args_doc[] = N_("[--COMPONENT PATTERN]... [MSGLIST]");
 
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "component", MH_OPT_ARG, "field" },
-  { "pattern",   MH_OPT_ARG, "pattern" },
-  { "search",    MH_OPT_ARG, "pattern" },
-  { "cc",        MH_OPT_ARG, "pattern" },
-  { "date",      MH_OPT_ARG, "pattern" },
-  { "from",      MH_OPT_ARG, "pattern" },
-  { "subject",   MH_OPT_ARG, "pattern" },
-  { "to",        MH_OPT_ARG, "pattern" },
-  { "datefield", MH_OPT_ARG, "field" },
-  { "after",     MH_OPT_ARG, "date" },
-  { "before",    MH_OPT_ARG, "date" },
-  { "and" },
-  { "or" }, 
-  { "not" },
-  { "lbrace" },
-  { "rbrace" },
-
-  { "list",      MH_OPT_BOOL },
-  { "sequence",  MH_OPT_ARG, "name" },
-  { "public",    MH_OPT_BOOL },
-  { "zero",      MH_OPT_BOOL },
-  { NULL }
-};
+static int public_option = 1;
+static int zero_option = 0;
 
 static int list = 1;
 static int seq_flags = 0; /* Create public sequences;
@@ -146,138 +38,177 @@ static mu_list_t lexlist;   /* List of input tokens */
 static mu_msgset_t picked_message_uids;
 
 static void
-add_sequence (char *name)
+add_component_name (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
 {
-  if (!seq_list && mu_list_create (&seq_list))
-    {
-      mu_error (_("cannot create sequence list"));
-      exit (1);
-    }
-  mu_list_append (seq_list, name);
+  pick_add_token (&lexlist, T_COMP, arg);
+}
+
+static void
+add_component_pattern (struct mu_parseopt *po, struct mu_option *opt,
+		       char const *arg)
+{
+  pick_add_token (&lexlist, T_STRING, arg);
 }
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+add_cflags (struct mu_parseopt *po, struct mu_option *opt,
+	    char const *arg)
+{
+  pick_add_token (&lexlist, T_CFLAGS, arg);
+}
+
+static void
+add_comp_match (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_COMP, opt->opt_default);
+  pick_add_token (&lexlist, T_STRING, arg);
+}
+
+static void
+add_datefield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
+  pick_add_token (&lexlist, T_DATEFIELD, arg);
+}
+
+static void
+add_after (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_AFTER, NULL);
+  pick_add_token (&lexlist, T_STRING, arg);
+}
+
+static void
+add_before (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_BEFORE, NULL);
+  pick_add_token (&lexlist, T_STRING, arg);
+}
+
+static void
+add_and (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_AND, NULL);
+}
+
+static void
+add_or (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_OR, NULL);  
+}
+
+static void
+add_not (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_NOT, NULL);
+}
+
+static void
+add_lbrace (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_LBRACE, NULL);
+}
+
+static void
+add_rbrace (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  pick_add_token (&lexlist, T_RBRACE, NULL);
+}
+
+static void
+add_to_sequence (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  if (!seq_list && mu_list_create (&seq_list))
     {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_SEQUENCE:
-      add_sequence (arg);
-      list = 0;
-      break;
-
-    case ARG_LIST:
-      list = is_true (arg);
-      break;
-
-    case ARG_NOLIST:
-      list = 0;
-      break;
-
-    case ARG_COMPONENT:
-      pick_add_token (&lexlist, T_COMP, arg);
-      break;
-      
-    case ARG_PATTERN:
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_CC:
-      pick_add_token (&lexlist, T_COMP, "cc");
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_DATE:           
-      pick_add_token (&lexlist, T_COMP, "date");
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_FROM:           
-      pick_add_token (&lexlist, T_COMP, "from");
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_SUBJECT:        
-      pick_add_token (&lexlist, T_COMP, "subject");
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_TO:
-      pick_add_token (&lexlist, T_COMP, "to");
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_DATEFIELD:
-      pick_add_token (&lexlist, T_DATEFIELD, arg);
-      break;
-      
-    case ARG_AFTER:
-      pick_add_token (&lexlist, T_AFTER, NULL);
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-      
-    case ARG_BEFORE:
-      pick_add_token (&lexlist, T_BEFORE, NULL);
-      pick_add_token (&lexlist, T_STRING, arg);
-      break;
-	
-    case ARG_AND:
-      pick_add_token (&lexlist, T_AND, NULL);
-      break;
-      
-    case ARG_OR:
-      pick_add_token (&lexlist, T_OR, NULL);
-      break;
-      
-    case ARG_NOT:
-      pick_add_token (&lexlist, T_NOT, NULL);
-      break;
-
-    case ARG_LBRACE:
-      pick_add_token (&lexlist, T_LBRACE, NULL);
-      break;
-      
-    case ARG_RBRACE:
-      pick_add_token (&lexlist, T_RBRACE, NULL);
-      break;
-
-    case ARG_CFLAGS:
-      pick_add_token (&lexlist, T_CFLAGS, arg);
-      break;
-      
-    case ARG_PUBLIC:
-      if (is_true (arg))
-	seq_flags &= ~SEQ_PRIVATE;
-      else
-	seq_flags |= SEQ_PRIVATE;
-      break;
-      
-    case ARG_NOPUBLIC:
-      seq_flags |= SEQ_PRIVATE;
-      break;
-      
-    case ARG_ZERO:
-      if (is_true (arg))
-	seq_flags |= SEQ_ZERO;
-      else
-	seq_flags &= ~SEQ_ZERO;
-      break;
-
-    case ARG_NOZERO:
-      seq_flags &= ~SEQ_ZERO;
-      break;
-	
-    default:
-      return ARGP_ERR_UNKNOWN;
+      mu_error (_("cannot create sequence list"));
+      exit (1);
     }
-
-  return 0;
+  mu_list_append (seq_list, mu_strdup (arg));
+  list = 0;
 }
 
+static struct mu_option options[] = {
+  MU_OPTION_GROUP (N_("Search patterns")),
+  { "component", 0, N_("FIELD"), MU_OPTION_DEFAULT,
+    N_("search the named header field"),
+    mu_c_string, NULL, add_component_name },
+  { "pattern",   0, N_("STRING"), MU_OPTION_DEFAULT,
+    N_("set pattern to look for"),
+    mu_c_string, NULL, add_component_pattern },
+  { "search",    0, NULL, MU_OPTION_ALIAS },
+  { "cflags",    0,  N_("STRING"), MU_OPTION_DEFAULT,
+    N_("flags controlling the type of regular expressions. "
+       "STRING must consist of one or more of the following letters: "
+       "B=basic, E=extended, I=ignore case, C=case sensitive. "
+       "Default is \"EI\". The flags remain in effect until the next "
+       "occurrence of --cflags option. The option must occur right "
+       "before --pattern or --component option (or its alias)."),
+    mu_c_string, NULL, add_cflags },
+  { "cc",        0,  N_("STRING"), MU_OPTION_DEFAULT,
+    N_("search for Cc matching STRING"),
+    mu_c_string, NULL, add_comp_match, "cc" },
+  { "date",      0,  N_("STRING"), MU_OPTION_DEFAULT,
+    N_("search for Date matching STRING"),
+    mu_c_string, NULL, add_comp_match, "date" },
+  { "from",      0,  N_("STRING"), MU_OPTION_DEFAULT,
+    N_("search for From matching STRING"),
+    mu_c_string, NULL, add_comp_match, "from" },
+  { "subject",   0,  N_("STRING"), MU_OPTION_DEFAULT,
+    N_("search for Subject matching STRING"),
+    mu_c_string, NULL, add_comp_match, "subject" },
+  { "to",        0,  N_("STRING"), MU_OPTION_DEFAULT,
+    N_("search for To matching STRING"),
+    mu_c_string, NULL, add_comp_match, "to" },
+
+  MU_OPTION_GROUP (N_("Date constraint operations")),
+  { "datefield", 0, N_("STRING"), MU_OPTION_DEFAULT,
+    N_("search in the named date header field (default is `Date:')"),
+    mu_c_string, NULL, add_datefield },
+  { "after",     0, N_("DATE"), MU_OPTION_DEFAULT,
+    N_("match messages after the given date"),
+    mu_c_string, NULL, add_after },
+  { "before",    0, N_("DATE"), MU_OPTION_DEFAULT,
+    N_("match messages before the given date"),
+    mu_c_string, NULL, add_before },
+
+  MU_OPTION_GROUP (N_("Logical operations and grouping")),
+  { "and",       0, NULL, MU_OPTION_DEFAULT,
+    N_("logical AND (default)"),
+    mu_c_string, NULL, add_and },
+  { "or",        0, NULL, MU_OPTION_DEFAULT,
+    N_("logical OR"),
+    mu_c_string, NULL, add_or },
+  { "not",       0, NULL, MU_OPTION_DEFAULT,
+    N_("logical NOT"),
+    mu_c_string, NULL, add_not },
+  { "lbrace",    0, NULL, MU_OPTION_DEFAULT,
+    N_("open group"),
+    mu_c_string, NULL, add_lbrace },
+  { "(",         0, NULL, MU_OPTION_ALIAS },
+  { "rbrace",    0, NULL, MU_OPTION_DEFAULT,
+    N_("close group"),
+    mu_c_string, NULL, add_rbrace },
+  { ")",         0, NULL, MU_OPTION_ALIAS },
+
+  MU_OPTION_GROUP (N_("Operations over the selected messages")),
+  { "list",      0, NULL, MU_OPTION_ALIAS,
+    N_("list the numbers of the selected messages (default)"),
+    mu_c_bool, &list },
+  { "sequence",  0, N_("NAME"), MU_OPTION_DEFAULT,
+    N_("add matching messages to the given sequence"),
+    mu_c_string, NULL, add_to_sequence },
+  { "public",    0, NULL,       MU_OPTION_DEFAULT,
+    N_("create public sequence"),
+    mu_c_bool, &public_option },
+  { "zero",      0, NULL,       MU_OPTION_DEFAULT,
+    N_("empty the sequence before adding messages"),
+    mu_c_bool, &zero_option },
+
+  MU_OPTION_END
+  
+};
+
 static int
 pick_message (size_t num, mu_message_t msg, void *data)
 {
@@ -301,89 +232,56 @@ action_add (void *item, void *data)
   return 0;
 }
 
-void
-pick_help_hook (void)
+static void
+parse_comp_match (int *pargc, char **argv)
 {
-  printf ("\n");
-  printf (_("To match another component, use:\n\n"));
-  printf (_("  --Component pattern\n\n"));
-  printf (_("Note, that the component name must either be capitalized,\n"
-	    "or followed by a colon.\n"));
-  printf ("\n");
-}
-
-/* NOTICE: For compatibility with RAND MH we have to support
-   the following command line syntax:
-
-       --COMP STRING
-
-   where `COMP' may be any string and which is equivalent to
-   `--component FIELD --pattern STRING'. Obviously this is in conflict
-   with the usual GNU long options paradigm which requires that any
-   unrecognized long option produce an error. The following
-   compromise solution is used:
-
-   The arguments `--COMP STRING' is recognized as a component matching
-   request if any of the following conditions is met:
-
-   1. The word `COMP' contains at least one capital letter.  E.g.:
+  int i, j;
+  int argc = *pargc;
 
-       --User-Agent Mailutils
-       
-   2. The word `COMP' ends with a colon, e.g.:
-
-       --user-agent: Mailutils
-   
-   3. Standard input is not connected to a terminal.  This is always
-      true when pick is invoked from mh-pick.el Emacs module.
-*/
+  for (i = j = 0; i < argc; i++)
+    {
+      if (strncmp (argv[i], "--", 2) == 0)
+	{
+	  if (++i < argc)
+	    {
+	      pick_add_token (&lexlist, T_COMP, argv[i-1] + 2);
+	      pick_add_token (&lexlist, T_STRING, argv[i]);
+	    }
+	  else
+	    {
+	      mu_error (_("%s: must be followed by a pattern"), argv[i-1]);
+	      exit (1);
+	    }
+	}
+      else
+	argv[j++] = argv[i];
+    }
+  argv[j] = NULL;
+  *pargc = j;
+}
 
 int
 main (int argc, char **argv)
 {
   int status;
-  int index;
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
-  int interactive = mh_interactive_mode_p ();
 
   MU_APP_INIT_NLS ();
 
-  for (index = 1; index < argc; index++)
-    {
-      int colon = 0, cpos;
-      if (argv[index][0] == '-' && argv[index][1] == '-' &&
-	  !strchr (argv[index], '=') &&
-	  (!interactive ||
-	   (colon = argv[index][cpos = strlen (argv[index]) - 1] == ':') ||
-	   *mu_str_skip_class_comp (argv[index], MU_CTYPE_UPPER)) &&
-	  index + 1 < argc)
-	{
-	  if (colon)
-	    {
-	      cpos -= 2;
-	      mu_asprintf (&argv[index], "--component=%*.*s", cpos, cpos,
-			   argv[index] + 2);
-	    }
-	  else
-	    mu_asprintf (&argv[index], "--component=%s", argv[index] + 2);
-	  mu_asprintf (&argv[index + 1], "--pattern=%s", argv[index + 1]);
-	  index++;
-	}
-    }
-  mh_help_hook = pick_help_hook;
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option,
-		 args_doc, doc, opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+
+  parse_comp_match (&argc, argv);
+  
   if (pick_parse (lexlist))
     return 1;
 
+  seq_flags = (public_option ? 0 : SEQ_PRIVATE) | (zero_option ? SEQ_ZERO : 0);
+  
   mbox = mh_open_folder (mh_current_folder (),
 			 seq_list ? MU_STREAM_RDWR : MU_STREAM_READ);
 
-  argc -= index;
-  argv += index;
-
   if (seq_list)
     mu_msgset_create (&picked_message_uids, NULL, MU_MSGSET_UID);
   
diff --git a/mh/pick.h b/mh/pick.h
index 75a5805..4c967b8 100644
--- a/mh/pick.h
+++ b/mh/pick.h
@@ -56,6 +56,6 @@ struct node
   } v;
 };
 
-void pick_add_token (mu_list_t *list, int tok, char *val);
+void pick_add_token (mu_list_t *list, int tok, char const *val);
 int pick_parse (mu_list_t toklist);
 int pick_eval (mu_message_t msg);
diff --git a/mh/pick.y b/mh/pick.y
index 908f9de..6c88c2c 100644
--- a/mh/pick.y
+++ b/mh/pick.y
@@ -189,28 +189,28 @@ tokname (int tok)
   switch (tok)
     {
     case T_DATEFIELD:
-      return "--datefield";
+      return "-datefield";
       
     case T_BEFORE:
-      return "--before";
+      return "-before";
       
     case T_AFTER:
-      return "--after";
+      return "-after";
       
     case T_LBRACE:
-      return "--lbrace";
+      return "-lbrace";
       
     case T_RBRACE:
-      return "--rbrace";
+      return "-rbrace";
       
     case T_OR:
-      return "--or";
+      return "-or";
       
     case T_AND:
-      return "--and";
+      return "-and";
       
     case T_NOT:
-      return "--not";
+      return "-not";
     }
   return NULL;
 }
@@ -236,7 +236,7 @@ yyerror (const char *s)
 }
   
 void
-pick_add_token (mu_list_t *list, int tok, char *val)
+pick_add_token (mu_list_t *list, int tok, char const *val)
 {
   struct token *tp;
   int rc;
diff --git a/mh/prompter.c b/mh/prompter.c
index 1d1f47b..116e102 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -19,98 +19,33 @@
 #include <mh.h>
 #include "prompter.h"
 
-static char doc[] = N_("GNU MH prompter")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH prompter");
 static char args_doc[] = N_("FILE");
 
-enum {
-  ARG_ERASE=256,
-  ARG_KILL,
-  ARG_PREPEND,
-  ARG_NOPREPEND,
-  ARG_RAPID,
-  ARG_NORAPID,
-  ARG_DOTEOF,
-  ARG_NODOTEOF
-};
-
-static struct argp_option options[] = {
-  { "erase",         ARG_ERASE,         N_("CHAR"), 0,
-    N_("set erase character") },
-  { "kill",          ARG_KILL,          N_("CHAR"), 0,
-    N_("set kill character") },
-  { "prepend",       ARG_PREPEND,       N_("BOOL"), 0,
-    N_("prepend user input to the message body") },
-  { "noprepend",     ARG_NOPREPEND,     NULL, OPTION_HIDDEN,
-    NULL },
-  { "rapid",         ARG_RAPID,         N_("BOOL"), 0,
-    N_("do not display message body") },
-  { "norapid",       ARG_NORAPID,       NULL, OPTION_HIDDEN,
-    NULL },
-  { "doteof",        ARG_DOTEOF,        N_("BOOL"), 0,
-    N_("a period on a line marks end-of-file") },
-  { "nodoteof",      ARG_NODOTEOF,      NULL, OPTION_HIDDEN,
-    NULL },
-  { NULL }
-};
-
-struct mh_option mh_option[] = {
-  { "erase", MH_OPT_ARG, "chr" },
-  { "kill",  MH_OPT_ARG, "chr" },
-  { "prepend", MH_OPT_BOOL },
-  { "rapid", MH_OPT_BOOL },
-  { "doteof", MH_OPT_BOOL },
-  { NULL }
-};
-
 char *erase_seq;
 char *kill_seq;
 int prepend_option;
 int rapid_option;
 int doteof_option;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_ERASE:
-      erase_seq = arg;
-      break;
-      
-    case ARG_KILL:
-      kill_seq = arg;
-      break;
-      
-    case ARG_PREPEND:
-      prepend_option = is_true (arg);
-      break;
-      
-    case ARG_NOPREPEND:
-      prepend_option = 0;
-      break;
-      
-    case ARG_RAPID:
-      rapid_option = is_true (arg);
-      break;
-      
-    case ARG_NORAPID:
-      rapid_option = 0;
-      break;
-      
-    case ARG_DOTEOF:
-      doteof_option = is_true (arg);
-      break;
-      
-    case ARG_NODOTEOF:
-      doteof_option = 0;
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-   }
-  return 0;
-}
+static struct mu_option options[] = {
+  { "erase",         0,     N_("CHAR"), MU_OPTION_DEFAULT,
+    N_("set erase character"),
+    mu_c_string, &erase_seq },
+  { "kill",          0,     N_("CHAR"), MU_OPTION_DEFAULT,
+    N_("set kill character"),
+    mu_c_string, &kill_seq },
+  { "prepend",       0,     NULL, MU_OPTION_DEFAULT,
+    N_("prepend user input to the message body"),
+    mu_c_bool, &prepend_option },
+  { "rapid",         0,     NULL, MU_OPTION_DEFAULT,
+    N_("do not display message body"),
+    mu_c_bool, &rapid_option },
+  { "doteof",        0,     NULL, MU_OPTION_DEFAULT,
+    N_("a period on a line marks end-of-file"),
+    mu_c_bool, &doteof_option },
+  MU_OPTION_END
+};
 
 static int
 is_empty_string (const char *str)
@@ -142,7 +77,6 @@ mu_stream_t strout;
 int
 main (int argc, char **argv)
 {
-  int index;
   int rc;
   mu_stream_t in, tmp;
   mu_message_t msg;
@@ -156,16 +90,20 @@ main (int argc, char **argv)
   
   MU_APP_INIT_NLS ();
   
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
-  if (index == argc)
+  if (argc == 0)
     {
       mu_error (_("file name not given"));
       exit (1);
     }
-  file = argv[index];
+  else if (argc > 1)
+    {
+      mu_error (_("too many arguments"));
+      exit (1);
+    }
+  
+  file = argv[0];
 
   prompter_init ();
   if (erase_seq)
@@ -178,7 +116,7 @@ main (int argc, char **argv)
       mu_error (_("cannot open stdout: %s"), mu_strerror (rc));
       return 1;
     }
-  
+
   if ((rc = mu_file_stream_create (&in, file, MU_STREAM_RDWR)))
     {
       mu_error (_("cannot open input file `%s': %s"),
@@ -186,14 +124,13 @@ main (int argc, char **argv)
       return 1;
     }
   rc = mu_stream_to_message (in, &msg);
-  mu_stream_unref (in);
   if (rc)
     {
       mu_error (_("input stream %s is not a message (%s)"),
 		file, mu_strerror (rc));
       return 1;
     }
-  
+
   if ((rc = mu_temp_file_stream_create (&tmp, NULL, 0))) 
     {
       mu_error (_("Cannot open temporary file: %s"),
diff --git a/mh/refile.c b/mh/refile.c
index a522a81..36bffbf 100644
--- a/mh/refile.c
+++ b/mh/refile.c
@@ -23,39 +23,9 @@
 #include <errno.h>
 #include <fcntl.h>
 
-static char doc[] = N_("GNU MH refile")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH refile");
 static char args_doc[] = N_("MSGLIST FOLDER [FOLDER...]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  {"draft",   ARG_DRAFT, NULL, 0,
-   N_("use <mh-dir>/draft as the source message")},
-  {"copy",    ARG_LINK, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("preserve the source folder copy")},
-  {"link",    0, NULL, OPTION_ALIAS, NULL},
-  {"preserve", ARG_PRESERVE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* try to preserve message sequence numbers")},
-  {"source", ARG_SOURCE, N_("FOLDER"), 0,
-   N_("specify source folder; it will become the current folder after the program exits")},
-  {"src", 0, NULL, OPTION_ALIAS, NULL},
-  {"file", ARG_FILE, N_("FILE"), 0, N_("use FILE as the source message")},
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "file",     MH_OPT_ARG, "input-file"},
-  { "draft" },
-  { "link",     MH_OPT_BOOL },
-  { "preserve", MH_OPT_BOOL },
-  { "src",      MH_OPT_ARG, "folder" },
-  { NULL }
-};
-
 int link_flag = 0;
 int preserve_flag = 0;
 char *source_file = NULL;
@@ -72,9 +42,40 @@ add_folder (const char *folder)
     }
   mu_list_append (folder_name_list, mu_strdup (folder));
 }
+
+static void
+add_folder_option (struct mu_parseopt *po, struct mu_option *opt,
+		   const char *arg)
+{
+  add_folder (arg);
+}
 
+static struct mu_option options[] = {
+  { "folder",  0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify folder to operate upon"),
+    mu_c_string, NULL, add_folder_option },
+  { "draft",   0, NULL, MU_OPTION_DEFAULT,
+    N_("use <mh-dir>/draft as the source message"),
+    mu_c_string, &source_file, NULL, "draft" },
+  { "copy",    0, NULL, MU_OPTION_DEFAULT,
+    N_("preserve the source folder copy"),
+    mu_c_bool, &link_flag },
+  { "link",    0, NULL, MU_OPTION_ALIAS },
+  { "preserve", 0, NULL, MU_OPTION_HIDDEN,
+    N_("try to preserve message sequence numbers"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+  { "source", 0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify source folder; it will become the current folder after the program exits"),
+    mu_c_string, NULL, mh_opt_set_folder },
+  { "src", 0, NULL, MU_OPTION_ALIAS },
+  { "file", 0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("use FILE as the source message"),
+    mu_c_string, &source_file },
+  MU_OPTION_END
+};
+
 void
-open_folders ()
+open_folders (void)
 {
   int rc;
   mu_iterator_t itr;
@@ -139,47 +140,11 @@ _close_folder (void *unused, mu_mailbox_t mbox)
 }
 
 void
-close_folders ()
+close_folders (void)
 {
   enumerate_folders (_close_folder, NULL);
 }
 
-static int
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      add_folder (arg);
-      break;
-
-    case ARG_DRAFT:
-      source_file = "draft";
-      break;
-
-    case ARG_LINK:
-      link_flag = is_true(arg);
-      break;
-      
-    case ARG_PRESERVE:
-      mh_opt_notimpl_warning ("-preserve");
-      preserve_flag = is_true(arg);
-      break;
-	
-    case ARG_SOURCE:
-      mh_set_current_folder (arg);
-      break;
-      
-    case ARG_FILE:
-      source_file = arg;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
 void
 refile_folder (void *data, mu_mailbox_t mbox)
 {
@@ -216,7 +181,6 @@ refile_iterator (size_t num, mu_message_t msg, void *data)
 int
 main (int argc, char **argv)
 {
-  int index;
   mu_msgset_t msgset;
   mu_mailbox_t mbox;
   int status, i, j;
@@ -224,13 +188,7 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
-  argc -= index;
-  argv += index;
-
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
   /* Collect any surplus folders */
   for (i = j = 0; i < argc; i++)
     {
diff --git a/mh/repl.c b/mh/repl.c
index 0ab11f4..826ecaf 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -22,89 +22,9 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-static char doc[] = N_("GNU MH repl")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH repl");
 static char args_doc[] = N_("[+FOLDER] [MESSAGE]");
 
-
-/* GNU options */
-static struct argp_option options[] = {
-  {"annotate", ARG_ANNOTATE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("add Replied: header to the message being replied to")},
-  {"build",   ARG_BUILD, 0, 0,
-   N_("build the draft and quit immediately")},
-  {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0,
-   N_("specify the folder for message drafts")},
-  {"nodraftfolder", ARG_NODRAFTFOLDER, 0, 0,
-   N_("undo the effect of the last --draftfolder option")},
-  {"draftmessage" , ARG_DRAFTMESSAGE, N_("MSG"), 0,
-   N_("invoke the draftmessage facility")},
-  {"cc", ARG_CC, "{all|to|cc|me}", 0,
-   N_("specify whom to place on the Cc: list of the reply")},
-  {"nocc", ARG_NOCC, "{all|to|cc|me}", 0,
-   N_("specify whom to remove from the Cc: list of the reply")},
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0, N_("specify folder to operate upon")},
-  {"group",  ARG_GROUP,  N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("construct a group or followup reply") },
-  {"editor", ARG_EDITOR, N_("PROG"), 0, N_("set the editor program to use")},
-  {"noedit", ARG_NOEDIT, 0, 0, N_("suppress the initial edit")},
-  {"fcc",    ARG_FCC, N_("FOLDER"), 0, N_("set the folder to receive Fcc's")},
-  {"filter", ARG_FILTER, N_("MHL-FILTER"), 0,
-   N_("set the mhl filter to preprocess the body of the message being replied")},
-  {"form",   ARG_FORM, N_("FILE"), 0, N_("read format from given file")},
-  {"format", ARG_FORMAT, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("include a copy of the message being replied; the message will be processed using either the default filter \"mhl.reply\", or the filter specified by --filter option") },
-  {"noformat", ARG_NOFORMAT, 0,          OPTION_HIDDEN, "" },
-  {"inplace", ARG_INPLACE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* annotate the message in place")},
-  {"query", ARG_QUERY, N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* query for addresses to place in To: and Cc: lists")},
-  {"width", ARG_WIDTH, N_("NUMBER"), 0, N_("set output width")},
-  {"whatnowproc", ARG_WHATNOWPROC, N_("PROG"), 0,
-   N_("set the replacement for whatnow program")},
-  {"nowhatnowproc", ARG_NOWHATNOWPROC, NULL, 0,
-   N_("don't run whatnowproc")},
-  {"use", ARG_USE, N_("BOOL"), OPTION_ARG_OPTIONAL, N_("use draft file preserved after the last session") },
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "annotate",    MH_OPT_BOOL },
-  { "build" },
-  { "cc",          MH_OPT_ARG, "all/to/cc/me"},
-  { "nocc",        MH_OPT_ARG, "all/to/cc/me"},
-  { "form",        MH_OPT_ARG, "formatfile"},
-  { "width",       MH_OPT_ARG, "number"},
-  { "draftfolder", MH_OPT_ARG, "folder"},
-  { "nodraftfolder" },
-  { "draftmessage" },
-  { "editor", MH_OPT_ARG, "program"},
-  { "noedit" },
-  { "fcc",         MH_OPT_ARG, "folder"},
-  { "filter",      MH_OPT_ARG, "program"},
-  { "format",      MH_OPT_BOOL },
-  { "group",       MH_OPT_BOOL },
-  { "inplace",     MH_OPT_BOOL },
-  { "query",       MH_OPT_BOOL },
-  { "whatnowproc", MH_OPT_ARG, "program"},
-  { "nowhatnowproc" },
-  { NULL }
-};
-
-static char default_format_str[] =
-"%(lit)%(formataddr %<{reply-to}%?{from}%?{sender}%?{return-path}%>)"
-"%<(nonnull)%(void(width))%(putaddr To: )\\n%>"
-"%(lit)%<(rcpt to)%(formataddr{to})%>%<(rcpt cc)%(formataddr{cc})%>%<(rcpt me)%(formataddr(me))%>"
-"%<(nonnull)%(void(width))%(putaddr cc: )\\n%>"
-"%<{fcc}Fcc: %{fcc}\\n%>"
-"%<{subject}Subject: Re: %(unre{subject})\\n%>"
-"%(lit)%(concat(in_reply_to))%<(nonnull)%(void(width))%(printhdr In-reply-to: )\\n%>"
-"%(lit)%(concat(references))%<(nonnull)%(void(width))%(printhdr References: )\\n%>"
-"X-Mailer: MH \\(%(package_string)\\)\\n" 
-"--------\n";
-
 static char *format_str = NULL;
 static mh_format_t format;
 static int width = 80;
@@ -114,12 +34,11 @@ static int initial_edit = 1;
 static const char *whatnowproc;
 static mu_msgset_t msgset;
 static mu_mailbox_t mbox;
-static int build_only = 0; /* --build flag */
-static int nowhatnowproc = 0; /* --nowhatnowproc */
-static int query_mode = 0; /* --query flag */
-static int use_draft = 0;  /* --use flag */
-static char *mhl_filter = NULL; /* --filter flag */
-static int annotate;       /* --annotate flag */
+static int build_only = 0; /* -build flag */
+static int nowhatnowproc = 0; /* -nowhatnowproc */
+static int use_draft = 0;  /* -use flag */
+static char *mhl_filter = NULL; /* -filter flag */
+static int annotate;       /* -annotate flag */
 static char *draftmessage = "new";
 static const char *draftfolder = NULL;
 static mu_opool_t fcc_pool;
@@ -136,146 +55,136 @@ decode_cc_flag (const char *opt, const char *arg)
     }
   return rc;
 }
+
+static void
+set_cc (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  rcpt_mask |= decode_cc_flag ("-cc", arg);
+}
+
+static void
+clr_cc (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  rcpt_mask &= ~decode_cc_flag ("-nocc", arg);
+}
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_fcc (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
+  if (!has_fcc)
     {
-    case ARGP_KEY_INIT:
-      draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
-      whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
-      break;
-      
-    case ARG_ANNOTATE:
-      annotate = is_true (arg);
-      break;
-      
-    case ARG_BUILD:
-      build_only = 1;
-      break;
-      
-    case ARG_CC:
-      rcpt_mask |= decode_cc_flag ("-cc", arg);
-      break;
+      mu_opool_create (&fcc_pool, 1);
+      has_fcc = 1;
+    }
+  else
+    mu_opool_append (fcc_pool, ", ", 2);
+  mu_opool_appendz (fcc_pool, arg);
+}
 
-    case ARG_NOCC:
-      rcpt_mask &= ~decode_cc_flag ("-nocc", arg);
-      break;
-	
-    case ARG_DRAFTFOLDER:
-      draftfolder = arg;
-      break;
-      
-    case ARG_EDITOR:
-      wh_env.editor = arg;
-      break;
-      
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
+static void
+set_whatnowproc (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
+{
+  whatnowproc = mu_strdup (arg);
+  nowhatnowproc = 0;
+}
 
-    case ARG_FORM:
+static void
+set_group (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  if (strcmp (arg, "1") == 0)
+    {
+      if (mh_read_formfile ("replgroupcomps", &format_str))
+	exit (1);
+      rcpt_mask |= RCPT_ALL;
+    }
+  else
+    {
       free (format_str);
       format_str = NULL;
-      if (mh_read_formfile (arg, &format_str))
-	exit (1);
-      break;
-
-    case ARG_GROUP:
-      if (is_true (arg))
-	{
-	  if (mh_read_formfile ("replgroupcomps", &format_str))
-	    exit (1);
-	  rcpt_mask |= RCPT_ALL;
-	}
-      else
-	{
-	  free (format_str);
-	  format_str = NULL;
-	}
-      break;
-	    
-    case ARG_DRAFTMESSAGE:
-      draftmessage = arg;
-      break;
-
-    case ARG_USE:
-      use_draft = is_true (arg);
-      break;
-      
-    case ARG_WIDTH:
-      width = strtoul (arg, NULL, 0);
-      if (!width)
-	{
-	  argp_error (state, _("invalid width"));
-	  exit (1);
-	}
-      break;
-
-    case ARG_NODRAFTFOLDER:
-      draftfolder = NULL;
-      break;
-
-    case ARG_NOEDIT:
-      initial_edit = 0;
-      break;
-      
-    case ARG_QUERY:
-      query_mode = is_true (arg);
-      if (query_mode)
-	mh_opt_notimpl_warning ("-query");
-      break;
-      
-    case ARG_FILTER:
-      mh_find_file (arg, &mhl_filter);
-      break;
-
-    case ARG_FORMAT:
-      if (is_true (arg))
-	mh_find_file ("mhl.repl", &mhl_filter);
-      else
-	mhl_filter = NULL;
-      break;
-
-    case ARG_NOFORMAT:
-      mhl_filter = NULL;
-      break;
-      
-    case ARG_FCC:
-      if (!has_fcc)
-	{
-	  mu_opool_create (&fcc_pool, 1);
-	  has_fcc = 1;
-	}
-      else
-	mu_opool_append (fcc_pool, ", ", 2);
-      mu_opool_appendz (fcc_pool, arg);
-      break;
-	  
-    case ARG_INPLACE:
-      mh_opt_notimpl_warning ("-inplace");
-      break;
-      
-    case ARG_WHATNOWPROC:
-      whatnowproc = arg;
-      break;
-
-    case ARG_NOWHATNOWPROC:
-      nowhatnowproc = 1;
-      break;
-
-    case ARGP_KEY_FINI:
-      if (!format_str)
-	format_str = default_format_str;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
     }
-  return 0;
 }
 
+static struct mu_option options[] = {
+  { "annotate", 0, NULL, MU_OPTION_DEFAULT,
+    N_("add Replied: header to the message being replied to"),
+    mu_c_bool, &annotate },
+  { "build",    0, NULL, MU_OPTION_DEFAULT,
+    N_("build the draft and quit immediately"),
+    mu_c_bool, &build_only },
+  { "draftfolder", 0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder for message drafts"),
+    mu_c_string, &draftfolder },
+  { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("undo the effect of the last --draftfolder option"),
+    mu_c_string, &draftfolder, mh_opt_clear_string },
+  { "draftmessage" , 0, N_("MSG"), MU_OPTION_DEFAULT,
+    N_("invoke the draftmessage facility"),
+    mu_c_string, &draftmessage },
+  { "cc", 0, "{all|to|cc|me}", 0,
+    N_("specify whom to place on the Cc: list of the reply"),
+    mu_c_string, NULL, set_cc },
+  { "nocc", 0, "{all|to|cc|me}", 0,
+    N_("specify whom to remove from the Cc: list of the reply"),
+    mu_c_string, NULL, clr_cc },
+  { "group", 0,  NULL, MU_OPTION_DEFAULT,
+    N_("construct a group or followup reply"),
+    mu_c_string, NULL, set_group },
+  { "editor", 0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the editor program to use"),
+    mu_c_string, &wh_env.editor },
+  { "noedit", 0, NULL, MU_OPTION_DEFAULT,
+    N_("suppress the initial edit"),
+    mu_c_int, &initial_edit, NULL, "0" },
+  { "fcc",    0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("set the folder to receive Fcc's"),
+    mu_c_string, NULL, set_fcc },
+  { "filter", 0, N_("MHL-FILTER"), MU_OPTION_DEFAULT,
+    N_("set the mhl filter to preprocess the body of the message being replied"),
+    mu_c_string, &mhl_filter, mh_opt_find_file },
+  { "form",   0, N_("FILE"), MU_OPTION_DEFAULT,
+    N_("read format from given file") ,
+    mu_c_string, &format_str, mh_opt_read_formfile },
+  { "format", 0, NULL, MU_OPTION_DEFAULT,
+    N_("include a copy of the message being replied; the message will be processed using either the default filter \"mhl.reply\", or the filter specified by --filter option"),
+    mu_c_string, &mhl_filter, mh_opt_find_file, "mhl.repl" },
+  { "noformat", 0, NULL,   MU_OPTION_DEFAULT,
+    N_("cancels the effect of the recent -format option"),
+    mu_c_string, &mhl_filter, mh_opt_clear_string },
+  { "inplace",  0, NULL,   MU_OPTION_HIDDEN,
+    N_("annotate the message in place"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+  { "query",    0, NULL,   MU_OPTION_HIDDEN,
+    N_("query for addresses to place in To: and Cc: lists"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+  { "width",    0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output width"),
+    mu_c_int, &width },
+  { "whatnowproc", 0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the replacement for whatnow program"),
+    mu_c_string, NULL, set_whatnowproc },
+  { "nowhatnowproc", 0, NULL, MU_OPTION_DEFAULT,
+    N_("don't run whatnowproc"),
+    mu_c_int, &nowhatnowproc, NULL, "1" },
+  { "use", 0, NULL, MU_OPTION_DEFAULT,
+    N_("use draft file preserved after the last session"),
+    mu_c_bool, &use_draft },
+  
+  MU_OPTION_END
+};
+
+static char default_format_str[] =
+"%(lit)%(formataddr %<{reply-to}%?{from}%?{sender}%?{return-path}%>)"
+"%<(nonnull)%(void(width))%(putaddr To: )\\n%>"
+"%(lit)%<(rcpt to)%(formataddr{to})%>%<(rcpt cc)%(formataddr{cc})%>%<(rcpt me)%(formataddr(me))%>"
+"%<(nonnull)%(void(width))%(putaddr cc: )\\n%>"
+"%<{fcc}Fcc: %{fcc}\\n%>"
+"%<{subject}Subject: Re: %(unre{subject})\\n%>"
+"%(lit)%(concat(in_reply_to))%<(nonnull)%(void(width))%(printhdr In-reply-to: )\\n%>"
+"%(lit)%(concat(references))%<(nonnull)%(void(width))%(printhdr References: )\\n%>"
+"X-Mailer: MH \\(%(package_string)\\)\\n" 
+"--------\n";
+
 void
 make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
 {
@@ -396,15 +305,20 @@ make_draft (mu_mailbox_t mbox, int disp, struct mh_whatnow_env *wh)
 int
 main (int argc, char **argv)
 {
-  int index, rc;
+  int rc;
 
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
+  draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
+  whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
+
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+
+  if (!format_str)
+    format_str = default_format_str;
 
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
   if (mh_format_parse (format_str, &format))
     {
       mu_error (_("Bad format string"));
@@ -412,7 +326,7 @@ main (int argc, char **argv)
     }
 
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
-  mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur");
+  mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
   if (!mh_msgset_single_message (msgset))
     {
       mu_error (_("only one message at a time!"));
diff --git a/mh/rmf.c b/mh/rmf.c
index 2e8c47f..91d66af 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -28,29 +28,9 @@
 
 #include <dirent.h>
 
-static char doc[] = N_("GNU MH rmf")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH rmf");
 static char args_doc[] = N_("[+FOLDER]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify the folder to delete")},
-  {"interactive", ARG_INTERACTIVE, N_("BOOL"), OPTION_ARG_OPTIONAL,
-    N_("interactive mode: ask for confirmation before removing each folder")},
-  {"nointeractive", ARG_NOINTERACTIVE, NULL, OPTION_HIDDEN, ""},
-  {"recursive", ARG_RECURSIVE, NULL, 0,
-   N_("recursively delete all subfolders")},
-  {"norecursive", ARG_NORECURSIVE, NULL, OPTION_HIDDEN, ""},
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "interactive", MH_OPT_BOOL },
-  { 0 }
-};
-
 int explicit_folder; /* Was the folder explicitly given */
 int interactive; /* Ask for confirmation before deleting */
 int recursive;     /* Recursively process all the sub-directories */
@@ -59,38 +39,26 @@ static char *cur_folder_path; /* Full pathname of the current folder */
 static char *folder_name;     /* Name of the (topmost) folder to be
 				 deleted */
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_folder (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARG_FOLDER:
-      explicit_folder = 1;
-      folder_name = arg;
-      break;
-
-    case ARG_INTERACTIVE:
-      interactive = is_true (arg);
-      break;
-
-    case ARG_NOINTERACTIVE:
-      interactive = 0;
-      break;
-	
-    case ARG_RECURSIVE:
-      recursive = is_true (arg);
-      break;
-      
-    case ARG_NORECURSIVE:
-      recursive = 0;
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+  explicit_folder = 1;
+  folder_name = mu_strdup (arg);
+} 
+
+static struct mu_option options[] = {
+  { "folder",  0, N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder to delete"),
+    mu_c_string, NULL, set_folder },
+  { "interactive", 0, NULL, MU_OPTION_DEFAULT,
+    N_("interactive mode: ask for confirmation before removing each folder"),
+    mu_c_bool, &interactive },
+  { "recursive", 0, NULL, MU_OPTION_DEFAULT,
+    N_("recursively delete all subfolders"),
+    mu_c_bool, &recursive },
+  MU_OPTION_END
+};
+
 static char *
 current_folder_path (void)
 {
@@ -185,9 +153,7 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, NULL);
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   cur_folder_path = current_folder_path ();
 
diff --git a/mh/rmm.c b/mh/rmm.c
index 40ee6cf..7b0de27 100644
--- a/mh/rmm.c
+++ b/mh/rmm.c
@@ -19,37 +19,9 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH rmm")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH rmm");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",  ARG_FOLDER, N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { NULL }
-};
-
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
 static int
 rmm (size_t num, mu_message_t msg, void *data)
 {
@@ -79,7 +51,6 @@ rmseq (const char *name, const char *value, void *data)
 int
 main (int argc, char **argv)
 {
-  int index = 0;
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
   int status;
@@ -88,13 +59,12 @@ main (int argc, char **argv)
   /* Native Language Support */
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
+  mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
 
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
 
-  mh_msgset_parse (&msgset, mbox, argc - index, argv + index, "cur");
+  mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
 
   status = mu_msgset_foreach_message (msgset, rmm, NULL);
   
diff --git a/mh/scan.c b/mh/scan.c
index a938aa0..3a197c7 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -26,7 +26,7 @@
 #include <time.h>
 #include <mailutils/observer.h>
 
-static char progdoc[] = N_("GNU MH scan");
+static char prog_doc[] = N_("GNU MH scan");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 static int clear;
@@ -107,7 +107,7 @@ main (int argc, char **argv)
   MU_APP_INIT_NLS ();
 
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
-	     args_doc, progdoc, NULL);
+	     args_doc, prog_doc, NULL);
 
   if (mh_format_parse (format_str, &format))
     {
diff --git a/mh/send.c b/mh/send.c
index 1ecda9f..cb9c2b8 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -23,91 +23,13 @@
 #include <stdarg.h>
 #include <pwd.h>
 
-static char doc[] = N_("GNU MH send")"\v"
-N_("Options marked with `*' are not yet implemented.\n\
-Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH send");
 static char args_doc[] = N_("FILE [FILE...]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"alias",         ARG_ALIAS,         N_("FILE"), 0,
-   N_("specify additional alias file") },
-  {"draft",         ARG_DRAFT,         NULL, 0,
-   N_("use prepared draft") },
-  {"draftfolder",   ARG_DRAFTFOLDER,   N_("FOLDER"), 0,
-   N_("specify the folder for message drafts") },
-  {"draftmessage",  ARG_DRAFTMESSAGE,  N_("MSG"), 0,
-   N_("use MSG from the draftfolder as a draft") },
-  {"nodraftfolder", ARG_NODRAFTFOLDER, NULL, 0,
-   N_("undo the effect of the last --draftfolder option") },
-  {"filter",        ARG_FILTER,        N_("FILE"), 0,
-  N_("* use filter FILE to preprocess the body of the message") },
-  {"nofilter",      ARG_NOFILTER,      NULL, 0,
-   N_("* undo the effect of the last --filter option") },
-  {"format",        ARG_FORMAT,        N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* reformat To: and Cc: addresses") },
-  {"noformat",      ARG_NOFORMAT,      NULL, OPTION_HIDDEN, "" },
-  {"forward",       ARG_FORWARD,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* in case of failure forward the draft along with the failure notice to the sender") },
-  {"noforward",     ARG_NOFORWARD,     NULL, OPTION_HIDDEN, "" },
-  {"mime",          ARG_MIME,          N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("* use MIME encapsulation") },
-  {"nomime",        ARG_NOMIME,        NULL, OPTION_HIDDEN, "" },
-  {"msgid",         ARG_MSGID,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("add Message-ID: field") },
-  {"nomsgid",       ARG_NOMSGID,       NULL, OPTION_HIDDEN, ""},
-  {"push",          ARG_PUSH,          N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("run in the background") },
-  {"nopush",        ARG_NOPUSH,        NULL, OPTION_HIDDEN, "" },
-  {"preserve",      ARG_PRESERVE,      N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("keep draft files") },
-  {"keep",          0, NULL, OPTION_ALIAS, NULL},
-  {"split",         ARG_SPLIT,         N_("SECONDS"), 0,
-   N_("split the draft into several partial messages and send them with SECONDS interval") },
-  {"chunksize",     ARG_CHUNKSIZE,     N_("NUMBER"), 0,
-   N_("set the size of chunk for --split (in bytes)") },
-  {"verbose",       ARG_VERBOSE,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("print the transcript of interactions with the transport system") },
-  {"noverbose",     ARG_NOVERBOSE,     NULL, OPTION_HIDDEN, "" },
-  {"watch",         ARG_WATCH,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("monitor the delivery of mail") },
-  {"nowatch",       ARG_NOWATCH,       NULL, OPTION_HIDDEN, "" },
-  {"width",         ARG_WIDTH,         N_("NUMBER"), 0,
-   N_("* make header fields no longer than NUMBER columns") },
-  { 0 }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "alias",         MH_OPT_ARG, "aliasfile" },
-  { "draft" },
-  { "draftfolder",   MH_OPT_ARG, "folder" },
-  { "draftmessage",  MH_OPT_ARG, "message" },
-  { "nodraftfolder" },
-  { "filter",        MH_OPT_ARG, "filterfile" },
-  { "nofilter" },
-  { "format",        MH_OPT_BOOL },
-  { "forward",       MH_OPT_BOOL },
-  { "mime",          MH_OPT_BOOL },
-  { "msgid",         MH_OPT_BOOL },
-  { "push",          MH_OPT_BOOL },
-  { "preserve",      MH_OPT_BOOL },
-  { "keep",          MH_OPT_BOOL },
-  { "split",         MH_OPT_ARG, "seconds" },
-  { "verbose",       MH_OPT_BOOL },
-  { "watch",         MH_OPT_BOOL },
-  { "width" },
-  { NULL }
-};
-
 static const char *draftfolder;  /* Use this draft folder */
 static int use_draftfolder = 1;
 static int use_draft;
 
-static int reformat_recipients;  /* --format option */
-static int forward_notice;       /* Forward the failure notice to the sender,
-				    --forward flag */
-static int mime_encaps;          /* Use MIME encapsulation */
 static int append_msgid;         /* Append Message-ID: header */
 static int background;           /* Operate in the background */
 
@@ -117,7 +39,6 @@ static unsigned long split_interval; /* Interval in seconds between sending two
 static size_t split_size = 76*632;   /* Size of split parts */
 static int verbose;              /* Produce verbose diagnostics */
 static int watch;                /* Watch the delivery process */
-static unsigned width = 76;      /* Maximum width of header fields */
 
 static int keep_files;           /* Keep draft files */
 
@@ -128,147 +49,116 @@ static int keep_files;           /* Keep draft files */
     watch_printf c;\
 } while (0)
 
-static int add_file (char *name);
+static int add_file (char const *name);
 static void mesg_list_fixup (void);
+
+static void
+add_alias (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  mh_alias_read (arg, 1);
+}
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_draftfolder (struct mu_parseopt *po, struct mu_option *opt,
+		 char const *arg)
 {
-  char *p;
-  
-  switch (key)
-    {
-    case ARG_ALIAS:
-      mh_alias_read (arg, 1);
-      break;
+  draftfolder = mu_strdup (arg);
+  use_draftfolder = 1;
+}
 
-    case ARG_CHUNKSIZE:
-      split_size = strtoul (arg, &p, 10);
-      if (*p)
-	{
-	  argp_error (state, "%s: %s", arg, _("invalid number"));
-	  exit (1);
-	}
-      break;
-	
-    case ARG_DRAFT:
-      use_draft = 1;
-      break;
-	
-    case ARG_DRAFTFOLDER:
-      draftfolder = arg;
-      use_draftfolder = 1;
-      break;
-      
-    case ARG_NODRAFTFOLDER:
-      draftfolder = NULL;
-      use_draftfolder = 0;
-      break;
-      
-    case ARG_DRAFTMESSAGE:
-      add_file (arg);
-      break;
-      
-    case ARG_FILTER:
-      mh_opt_notimpl ("-filter");
-      break;
+static void
+add_draftmessage (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  add_file (arg);
+}
 
-    case ARG_NOFILTER:
-      mh_opt_notimpl ("-nofilter");
-      break;
- 
-    case ARG_FORMAT:
-      mh_opt_notimpl_warning ("-format"); 
-      reformat_recipients = is_true (arg);
-      break;
-      
-    case ARG_NOFORMAT:
-      mh_opt_notimpl_warning ("-noformat"); 
-      reformat_recipients = 0;
-      break;
-      
-    case ARG_FORWARD:
-      mh_opt_notimpl_warning ("-forward");
-      forward_notice = is_true (arg);
-      break;
-      
-    case ARG_NOFORWARD:
-      mh_opt_notimpl_warning ("-noforward");
-      forward_notice = 0;
-      break;
-      
-    case ARG_MIME:
-      mh_opt_notimpl_warning ("-mime");
-      mime_encaps = is_true (arg);
-      break;
-      
-    case ARG_NOMIME:
-      mh_opt_notimpl_warning ("-nomime");
-      mime_encaps = 0;
-      break;
-      
-    case ARG_MSGID:
-      append_msgid = is_true (arg);
-      break;
-      
-    case ARG_NOMSGID:
-      append_msgid = 0;
-      break;
+static void
+set_split_opt (struct mu_parseopt *po, struct mu_option *opt,
+	       char const *arg)
+{
+  char *errmsg;
+  int rc = mu_str_to_c (arg, opt->opt_type, opt->opt_ptr, &errmsg);
+  if (rc)
+    {
+      char const *errtext;
+      if (errmsg)
+	errtext = errmsg;
+      else
+	errtext = mu_strerror (rc);
 
-    case ARG_PRESERVE:
-      keep_files = is_true (arg);
-      break;
-      
-    case ARG_PUSH:
-      background = is_true (arg);
-      break;
-      
-    case ARG_NOPUSH:
-      background = 0;
-      break;
-      
-    case ARG_SPLIT:
-      split_message = 1;
-      split_interval = strtoul (arg, &p, 10);
-      if (*p)
-	{
-	  argp_error (state, "%s: %s", arg, _("invalid number"));
-	  exit (1);
-	}
-      break;
-      
-    case ARG_VERBOSE:
-      verbose = is_true (arg);
-      break;
-      
-    case ARG_NOVERBOSE:
-      verbose = 0;
-      break;
-      
-    case ARG_WATCH:
-      watch = is_true (arg);
-      break;
-      
-    case ARG_NOWATCH:
-      watch = 0;
-      break;
-      
-    case ARG_WIDTH:
-      mh_opt_notimpl_warning ("-width");
-      width = strtoul (arg, &p, 10);
-      if (*p)
-	{
-	  argp_error (state, _("invalid number"));
-	  exit (1);
-	}
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
+      mu_parseopt_error (po, "%s%s: %s", po->po_long_opt_start,
+			 opt->opt_long, errtext);
+      free (errmsg);
+
+      if (!(po->po_flags & MU_PARSEOPT_NO_ERREXIT))
+	exit (po->po_exit_error);
     }
-  return 0;
+  split_message = 1;
 }
 
+static struct mu_option options[] = {
+  { "alias",        0,    N_("FILE"), MU_OPTION_DEFAULT,
+    N_("specify additional alias file"),
+    mu_c_string, NULL, add_alias },
+  { "draft",        0,    NULL, MU_OPTION_DEFAULT,
+    N_("use prepared draft"),
+    mu_c_bool, &use_draft },
+  { "draftfolder",  0,   N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder for message drafts"),
+    mu_c_string, NULL, set_draftfolder },
+  { "draftmessage", 0,   N_("MSG"), MU_OPTION_DEFAULT,
+    N_("use MSG from the draftfolder as a draft"),
+    mu_c_string, NULL, add_draftmessage },
+  { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("undo the effect of the last --draftfolder option"),
+    mu_c_int, &use_draftfolder, NULL, "1" },
+  { "filter",        0, N_("FILE"), MU_OPTION_HIDDEN,
+    N_("use filter FILE to preprocess the body of the message"),
+    mu_c_string, NULL, mh_opt_notimpl },
+  { "nofilter",      0, NULL, MU_OPTION_HIDDEN,
+    N_("undo the effect of the last --filter option"),
+    mu_c_string, NULL, mh_opt_notimpl },
+  { "format",        0, NULL, MU_OPTION_HIDDEN,
+    N_("reformat To: and Cc: addresses"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+  { "noformat",      0, NULL, MU_OPTION_HIDDEN },
+  { "forward",       0, NULL, MU_OPTION_HIDDEN,
+    N_("in case of failure forward the draft along with the failure notice to the sender"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+  { "noforward",     0, NULL, MU_OPTION_HIDDEN, "" },
+  { "mime",          0, NULL, MU_OPTION_HIDDEN,
+    N_("use MIME encapsulation"),
+    mu_c_bool, NULL, mh_opt_notimpl_warning },
+  { "msgid",         0, NULL, MU_OPTION_DEFAULT,
+    N_("add Message-ID: field"),
+    mu_c_bool, &append_msgid },
+  { "push",          0, NULL, MU_OPTION_DEFAULT,
+    N_("run in the background"),
+    mu_c_bool, &background },
+  { "preserve",      0, NULL, MU_OPTION_DEFAULT,
+    N_("keep draft files"),
+    mu_c_bool, &keep_files },
+  { "keep",          0, NULL, MU_OPTION_ALIAS },
+  { "split",         0, N_("SECONDS"), MU_OPTION_DEFAULT,
+   N_("split the draft into several partial messages and send them with SECONDS interval"),
+    mu_c_ulong, &split_interval, set_split_opt },
+  { "chunksize",     0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set the size of chunk for --split (in bytes)"),
+    mu_c_size, &split_size },
+  { "verbose",       0, NULL, MU_OPTION_DEFAULT,
+    N_("print the transcript of interactions with the transport system"),
+    mu_c_bool, &verbose },
+  { "watch",         0, NULL, MU_OPTION_DEFAULT,
+    N_("monitor the delivery of mail"),
+    mu_c_bool, &watch },
+  { "width",         0, N_("NUMBER"), MU_OPTION_HIDDEN,
+    N_("make header fields no longer than NUMBER columns"),
+    mu_c_string, NULL, mh_opt_notimpl_warning },
+
+  MU_OPTION_END
+};
+
 static void
 watch_printf (const char *fmt, ...)
 {
@@ -291,7 +181,7 @@ static mu_list_t mesg_list;
 static mu_property_t mts_profile;
 
 int
-add_file (char *name)
+add_file (char const *name)
 {
   struct list_elt *elt;
 
@@ -859,17 +749,12 @@ int
 main (int argc, char **argv)
 {
   mu_mailbox_t mbox = NULL;
-  int index;
   char *p;
   int rc;
   
   MU_APP_INIT_NLS ();
   
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-  argc -= index;
-  argv += index;
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   mh_read_aliases ();
   /* Process the mtstailor file */
diff --git a/mh/show.c b/mh/show.c
index e2bc1c0..fcd87eb 100644
--- a/mh/show.c
+++ b/mh/show.c
@@ -19,55 +19,9 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH show")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH show");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
-#define ARG_PASS ARG_MAX
-
-static struct argp_option options[] = {
-  {"draft",         ARG_DRAFT,          NULL, 0,
-   N_("show the draft file") },
-  {"file",          ARG_FILE,     N_("FILE"), 0,
-   N_("show this file") },
-  {"header",        ARG_HEADER,   N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("display a description of the message before the message itself") },
-  {"noheader",      ARG_HEADER,   NULL, OPTION_HIDDEN, "" },
-  {"showproc",      ARG_SHOWPROC, N_("PROGRAM"), 0,
-   N_("use PROGRAM to show messages")},
-  {"noshowproc",    ARG_NOSHOWPROC, NULL, 0,
-   N_("disable the use of the \"showproc:\" profile component") },
-
-  {"form",          ARG_FORM,     N_("FILE"),   0,
-   N_("read format from given file")},
-  {"moreproc",      ARG_MOREPROC, N_("PROG"),   0,
-   N_("use this PROG as pager"), },
-  {"nomoreproc",    ARG_NOMOREPROC,     NULL,         0,
-   N_("disable the use of moreproc") },
-  {"length",        ARG_LENGTH,   N_("NUMBER"), 0,
-   N_("set output screen length")},
-  {"width",         ARG_WIDTH,    N_("NUMBER"), 0,
-   N_("set output width")},
-  
-  {NULL}
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "draft" },
-  { "file", MH_OPT_ARG, "file" },
-  { "header", MH_OPT_BOOL },
-  { "showproc", MH_OPT_ARG, "program" },
-  { "noshowproc" },
-  { "form",       MH_OPT_ARG, "formatfile"},
-  { "width",      MH_OPT_ARG, "number"},
-  { "length",     MH_OPT_ARG, "number"},
-  { "moreproc",   MH_OPT_ARG, "program"},
-  { "nomoreproc" },
-  
-  { NULL }
-};
-
 int use_draft;
 int use_showproc = 1;
 int header_option = 1;
@@ -100,71 +54,75 @@ insarg (char *arg)
       showargv[1] = p;
     }
 }
-
-static const char *
-findopt (int key)
+
+static void
+set_draft (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  struct argp_option *p;
-
-  for (p = options; p->name; p++)
-    if (p->key == key)
-      return p->name;
-  abort ();
+  if (use_draft || file)
+    {
+      mu_parseopt_error (po, _("only one file at a time!"));
+      exit (po->po_exit_error);
+    }
+  use_draft = 1;
 }
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+set_file (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
+  if (use_draft || file)
     {
-    case ARG_FOLDER: 
-      mh_set_current_folder (arg);
-      break;
-
-    case ARG_DRAFT:
-      if (use_draft || file)
-	argp_error (state, _("only one file at a time!"));
-      use_draft = 1;
-      break;
-
-    case ARG_FILE:
-      if (use_draft || file)
-	argp_error (state, _("only one file at a time!"));
-      file = mh_expand_name (NULL, arg, NAME_FILE);
-      break;
-      
-    case ARG_HEADER:
-      header_option = is_true (arg);
-      break;
-
-    case ARG_NOHEADER:
-      header_option = 0;
-      break;
-
-    case ARG_SHOWPROC:
-      showproc = arg;
-      break;
-
-    case ARG_NOSHOWPROC:
-      use_showproc = 0;
-      break;
-      
-    case ARG_NOMOREPROC:
-    case ARG_FORM:
-    case ARG_MOREPROC:
-    case ARG_LENGTH:
-    case ARG_WIDTH:
-      addarg (findopt (key));
-      if (arg)
-	addarg (arg);
-      break;
-
-    default:
-      return ARGP_ERR_UNKNOWN;
+      mu_parseopt_error (po, _("only one file at a time!"));
+      exit (po->po_exit_error);
     }
-  return 0;
+  file = mh_expand_name (NULL, arg, NAME_FILE);
+}
+
+static void
+add_show_arg (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  char *name = mu_alloc (strlen (opt->opt_long) + 2);
+  name[0] = '-';
+  strcpy (name + 1, opt->opt_long);
+  addarg (name);
+  if (arg)
+    addarg (arg);
 }
 
+static struct mu_option options[] = {
+  { "draft",        0,     NULL, MU_OPTION_DEFAULT,
+    N_("show the draft file"),
+    mu_c_string, NULL, set_draft },
+  { "file",         0,     N_("FILE"), MU_OPTION_DEFAULT,
+    N_("show this file"),
+    mu_c_string, NULL, set_file },
+  { "header",       0,     NULL, MU_OPTION_DEFAULT,
+    N_("display a description of the message before the message itself"),
+    mu_c_bool, &header_option },
+  { "showproc",     0,     N_("PROGRAM"), MU_OPTION_DEFAULT,
+    N_("use PROGRAM to show messages"),
+    mu_c_string, &showproc },
+  { "noshowproc",   0,  NULL, MU_OPTION_DEFAULT,
+    N_("disable the use of the \"showproc:\" profile component"),
+    mu_c_int, &use_showproc, NULL, "0" },
+  { "form",         0,  N_("FILE"),  MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, NULL, add_show_arg },
+  { "moreproc",     0, N_("PROG"),   MU_OPTION_DEFAULT,
+    N_("use this PROG as pager"),
+    mu_c_string, NULL, add_show_arg },
+  { "nomoreproc",   0, NULL,         MU_OPTION_DEFAULT,
+    N_("disable the use of moreproc"),
+    mu_c_string, NULL, add_show_arg },
+  { "length",       0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output screen length"),
+    mu_c_string, NULL, add_show_arg },
+  { "width",        0, N_("NUMBER"), MU_OPTION_DEFAULT,
+    N_("set output width"),
+    mu_c_string, NULL, add_show_arg },
+  
+  MU_OPTION_END
+};
+
 static int
 resolve_mime (size_t num, mu_message_t msg, void *data)
 {
@@ -222,7 +180,6 @@ checkfile (char *file)
 int
 main (int argc, char **argv)
 {
-  int index = 0;
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
   const char *p;
@@ -233,15 +190,13 @@ main (int argc, char **argv)
   showargmax = 2;
   showargc = 1;
   showargv = mu_calloc (showargmax, sizeof showargv[0]);
+
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+
   
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
   mbox = mh_open_folder (mh_current_folder (), MU_STREAM_RDWR);
 
-  argc -= index;
-  argv += index;
-  
   if (use_draft || file)
     {
       if (argc)
diff --git a/mh/sortm.c b/mh/sortm.c
index f2e1290..bb991cf 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -22,72 +22,10 @@
 #include <unistd.h>
 #include <signal.h>
 
-static char doc[] = N_("GNU MH sortm")"\v"
+static char prog_doc[] = N_("GNU MH sortm")"\v"
 N_("Use -help to obtain the list of traditional MH options.");
 static char args_doc[] = N_("[MSGLIST]");
 
-#define ARG_QUICKSORT 1024
-#define ARG_SHELL     1025
-
-/* GNU options */
-static struct argp_option options[] = {
-  {"folder",        ARG_FOLDER,        N_("FOLDER"), 0,
-   N_("specify folder to operate upon")},
-
-  {N_("Setting sort keys:"), 0,  NULL, OPTION_DOC,  NULL, 0},
-  {"datefield",     ARG_DATEFIELD,     N_("STRING"), 0,
-   N_("sort on the date field (default `Date:')"), 10},
-  {"nodatefield",   ARG_NODATEFIELD,   NULL,       0,
-   N_("undo the effect of the last --datefield option"), 10},
-  {"limit",         ARG_LIMIT,         N_("DAYS"), 0,
-   N_("consider two datefields equal if their difference lies within the given nuber of DAYS."), 11},
-  {"nolimit",       ARG_NOLIMIT,       NULL,       0,
-   N_("undo the effect of the last --limit option"), 11},
-  {"textfield",     ARG_TEXTFIELD,     N_("STRING"), 0,
-   N_("sort on the text field"), 15},
-  {"notextfield",   ARG_NOTEXTFIELD,   NULL,       0,
-   N_("undo the effect of the last --textfield option"), 15},
-  {"numfield",      ARG_NUMFIELD,      N_("STRING"), 0,
-   N_("sort on the numeric field"), 16},
-  
-  {N_("Actions:"), 0,  NULL, OPTION_DOC,  NULL, 16},
-  {"reorder", ARG_REORDER,    0, 0,
-   N_("reorder the messages (default)"), 20 },
-  {"dry-run", ARG_DRY_RUN,    0, 0,
-   N_("do not do anything, only show what would have been done"), 20 },
-  {"list",    ARG_LIST,   0, 0,
-   N_("list the sorted messages"), 20 },
-  {"form",    ARG_FORM, N_("FILE"),   0,
-   N_("read format from given file"), 23},
-  {"format",  ARG_FORMAT, N_("FORMAT"), 0,
-   N_("use this format string"), 23},
-
-  {"verbose",       ARG_VERBOSE,       N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("verbosely list executed actions"), 30 },
-  {"noverbose",     ARG_NOVERBOSE,     NULL, OPTION_HIDDEN, "" },
-
-  {N_("Select sort algorithm:"), 0,  NULL, OPTION_DOC,  NULL, 30},
-
-  {"shell",     ARG_SHELL,      0, 0,
-   N_("use shell algorithm"), 40 },
-  {"quicksort", ARG_QUICKSORT,  0, 0,
-   N_("use quicksort algorithm (default)"), 40 },
-
-  { NULL },
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "datefield",     MH_OPT_ARG, "field" },
-  { "nodatefield" },
-  { "textfield",     MH_OPT_ARG, "field" },
-  { "notextfield" },
-  { "limit",         MH_OPT_ARG, "days" },
-  { "nolimit" },
-  { "verbose",       MH_OPT_BOOL },
-  { NULL },
-};
-
 static int limit;
 static int verbose;
 static mu_mailbox_t mbox;
@@ -98,115 +36,175 @@ static size_t msgcount;
 
 static size_t current_num;
 
-#define ACTION_REORDER   0
-#define ACTION_DRY_RUN   1
-#define ACTION_LIST      2  
-
-static int algorithm = ARG_QUICKSORT;
+enum
+  {
+    ACTION_REORDER,
+    ACTION_DRY_RUN,
+    ACTION_LIST
+  };
+
+enum
+  {
+    algo_quicksort,
+    algo_shell
+  };
+static int algorithm = algo_quicksort;
 static int action = ACTION_REORDER;
 static char *format_str = mh_list_format;
 static mh_format_t format;
 
 typedef int (*compfun) (void *, void *);
-static void addop (char *field, compfun comp);
+static void addop (char const *field, compfun comp);
 static void remop (compfun comp);
 static int comp_text (void *a, void *b);
 static int comp_date (void *a, void *b);
 static int comp_number (void *a, void *b);
+
+static void
+add_datefield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  addop (arg, comp_date);
+}
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+static void
+add_numfield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARG_FOLDER:
-      mh_set_current_folder (arg);
-      break;
-      
-    case ARG_DATEFIELD:
-      addop (arg, comp_date);
-      break;
-      
-    case ARG_NUMFIELD:
-      addop (arg, comp_number);
-      break;
+  addop (arg, comp_number);
+}
 
-    case ARG_NODATEFIELD:
-      remop (comp_date);
-      break;
-      
-    case ARG_TEXTFIELD:
-      addop (arg, comp_text);
-      break;
-      
-    case ARG_NOTEXTFIELD:
-      remop (comp_text);
-      break;
-      
-    case ARG_LIMIT:
-      limit = strtoul (arg, NULL, 0);
-      break;
-      
-    case ARG_NOLIMIT:
-      limit = -1;
-      break;
-      
-    case ARG_VERBOSE:
-      if (!arg || mu_isalpha (arg[0]))
-	verbose = is_true (arg);
-      else
-	verbose = arg[0] - '0';
-      break;
-      
-    case ARG_NOVERBOSE:
-      verbose = 0;
-      break;
-      
-    case ARG_FORM:
-      mh_read_formfile (arg, &format_str);
-      break;
-      
-    case ARG_FORMAT:
-      format_str = arg;
-      break;
+static void
+add_textfield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  addop (arg, comp_text);
+}
 
-    case ARG_REORDER:
-      action = ACTION_REORDER;
-      break;
-      
-    case ARG_LIST:
-      action = ACTION_LIST;
-      break;
+static void
+rem_datefield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  remop (comp_date);
+}
 
-    case ARG_DRY_RUN:
-      action = ACTION_DRY_RUN;
-      if (!verbose)
-	verbose = 1;
-      break;
+static void
+rem_numfield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  remop (comp_number);
+}
 
-    case ARG_SHELL:
-    case ARG_QUICKSORT:
-      algorithm = key;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+rem_textfield (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
+{
+  remop (comp_text);
+}
+
+static void
+set_action_reorder (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  action = ACTION_REORDER;
+}
+
+static void
+set_action_list (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  action = ACTION_LIST;
 }
 
+static void
+set_action_dry_run (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  action = ACTION_DRY_RUN;
+  if (!verbose)
+    verbose = 1;
+}
+
+static void
+set_algo_shell (struct mu_parseopt *po, struct mu_option *opt,
+		char const *arg)
+{
+  algorithm = algo_shell;
+}
+
+static void
+set_algo_quicksort (struct mu_parseopt *po, struct mu_option *opt,
+		    char const *arg)
+{
+  algorithm = algo_quicksort;
+}
+
+static struct mu_option options[] = {
+  MU_OPTION_GROUP (N_("Setting sort keys:")),
+  { "datefield",     0, N_("STRING"), MU_OPTION_DEFAULT,
+    N_("sort on the date field (default `Date:')"),
+    mu_c_string, NULL, add_datefield },
+  { "nodatefield",   0, NULL,       MU_OPTION_DEFAULT,
+    N_("don't sort on the date field"),
+    mu_c_string, NULL, rem_datefield },
+  { "limit",         0, N_("DAYS"), MU_OPTION_DEFAULT,
+    N_("consider two datefields equal if their difference lies within the given nuber of DAYS."),
+    mu_c_int, &limit },
+  { "nolimit",       0,       NULL,       MU_OPTION_DEFAULT,
+    N_("undo the effect of the last -limit option"),
+    mu_c_int, &limit, NULL, "-1" },
+  { "textfield",     0,       N_("STRING"), MU_OPTION_DEFAULT,
+    N_("sort on the text field"),
+    mu_c_string, NULL, add_textfield },
+  { "notextfield",   0,       NULL,       MU_OPTION_DEFAULT, 
+    N_("don't sort on the text field"),
+    mu_c_string, NULL, rem_textfield },
+  { "numfield",      0,       N_("STRING"), MU_OPTION_DEFAULT,
+    N_("sort on the numeric field"),
+    mu_c_string, NULL, add_numfield },
+  { "nonumfield",    0,       NULL,       MU_OPTION_DEFAULT,
+    N_("don't sort on the numeric field"),
+    mu_c_string, NULL, rem_numfield },
+  
+  MU_OPTION_GROUP (N_("Actions:")),
+  { "reorder", 0,    NULL, MU_OPTION_DEFAULT,
+    N_("reorder the messages (default)"),
+    mu_c_string, NULL, set_action_reorder },
+  { "dry-run", 0,    NULL, MU_OPTION_DEFAULT,
+   N_("do not do anything, only show what would have been done"),
+    mu_c_string, NULL, set_action_dry_run },
+  { "list",    0,    NULL, MU_OPTION_DEFAULT,
+    N_("list the sorted messages"), 
+    mu_c_string, NULL, set_action_list },
+  
+  { "form",    0, N_("FILE"),   MU_OPTION_DEFAULT,
+    N_("read format from given file"),
+    mu_c_string, &format_str, mh_opt_read_formfile },
+  { "format",  0, N_("FORMAT"), MU_OPTION_DEFAULT,
+    N_("use this format string"),
+    mu_c_string, &format_str },
+
+  { "verbose",  0, NULL,   MU_OPTION_DEFAULT,
+    N_("verbosely list executed actions"),
+    mu_c_bool, &verbose },
+
+  MU_OPTION_GROUP (N_("Select sort algorithm:")),
+  { "shell",    0, NULL,   MU_OPTION_DEFAULT,
+    N_("use shell algorithm"),
+    mu_c_string, NULL, set_algo_shell },
+  
+  { "quicksort", 0, NULL,   MU_OPTION_DEFAULT,
+    N_("use quicksort algorithm (default)"),
+    mu_c_string, NULL, set_algo_quicksort },
+
+  MU_OPTION_END
+};
 
 /* *********************** Comparison functions **************************** */
 struct comp_op
 {
-  char *field;
+  char const *field;
   compfun comp;
 };
 
 static mu_list_t oplist;
 
 static void
-addop (char *field, compfun comp)
+addop (char const *field, compfun comp)
 {
   struct comp_op *op = mu_alloc (sizeof (*op));
   
@@ -497,11 +495,11 @@ sort ()
 
   switch (algorithm)
     {
-    case ARG_QUICKSORT:
+    case algo_quicksort:
       qsort (msgarr, msgcount, sizeof (msgarr[0]), comp);
       break;
 
-    case ARG_SHELL:
+    case algo_shell:
       shell_sort ();
       break;
     }
@@ -599,19 +597,17 @@ fill_msgarr (mu_msgset_t msgset)
 }
 
 
-/* Main */
-
 int
 main (int argc, char **argv)
 {
-  int index;
   mu_url_t url;
   mu_msgset_t msgset;
   
   MU_APP_INIT_NLS ();
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option,
-		 args_doc, doc, opt_handler, NULL, &index);
+
+  mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
+	     args_doc, prog_doc, NULL);
+  
   if (!oplist)
     addop ("date", comp_date);
 
@@ -627,9 +623,6 @@ main (int argc, char **argv)
   if (memcmp (mbox_path, "mh:", 3) == 0)
     mbox_path += 3;
   
-  argc -= index;
-  argv += index;
-
   mh_mailbox_get_cur (mbox, &current_num);
 
   mh_msgset_parse (&msgset, mbox, argc, argv, "all");
diff --git a/mh/tests/refile.at b/mh/tests/refile.at
index 46aea36..caec370 100644
--- a/mh/tests/refile.at
+++ b/mh/tests/refile.at
@@ -53,11 +53,11 @@ Mail/inbox/5
 Mail/inbox/6
 ])
 
-MH_CHECK([refile --copy],[refile02 refile--copy],[
+MH_CHECK([refile -copy],[refile02 refile-copy],[
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/mbox1,[Mail/inbox])
 MUT_MBCOPY($abs_top_srcdir/testsuite/mh/teaparty,[Mail/teaparty])
 echo 'Current-Folder: teaparty' > Mail/context
-refile --copy 3 4 +inbox || exit $?
+refile -copy 3 4 +inbox || exit $?
 find Mail/inbox -name '[[0-9]]' | sort
 cmp Mail/inbox/6 Mail/teaparty/3 >/dev/null || echo "Message 3 differs"
 cmp Mail/inbox/7 Mail/teaparty/4 >/dev/null || echo "Message 4 differs"
diff --git a/mh/whatnow.c b/mh/whatnow.c
index 0ca7add..9e0d38e 100644
--- a/mh/whatnow.c
+++ b/mh/whatnow.c
@@ -19,88 +19,45 @@
 
 #include <mh.h>
 
-static char doc[] = "GNU MH whatnow";
+static char prog_doc[] = "GNU MH whatnow";
 static char args_doc[] = N_("[FILE]");
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"draftfolder", ARG_DRAFTFOLDER, N_("FOLDER"), 0,
-   N_("specify the folder for message drafts")},
-  {"nodraftfolder", ARG_NODRAFTFOLDER, 0, 0,
-   N_("undo the effect of the last --draftfolder option")},
-  {"draftmessage" , ARG_DRAFTMESSAGE, N_("MSG"), 0,
-   N_("invoke the draftmessage facility")},
-  {"editor",  ARG_EDITOR, N_("PROG"), 0, N_("set the editor program to use")},
-  {"noedit", ARG_NOEDIT, 0, 0, N_("suppress the initial edit")},
-  {"prompt", ARG_PROMPT, N_("STRING"), 0, N_("set the prompt")},
-
-  { NULL }
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "draftfolder",  MH_OPT_ARG, "folder" },
-  { "nodraftfolder" },
-  { "draftmessage" },
-  { "editor",       MH_OPT_ARG, "program" },
-  { "noedit" },
-  { "prompt" },
-  { NULL }
-};
-
 struct mh_whatnow_env wh_env = { 0 };
 static int initial_edit = 1;
 static char *draftmessage = "cur";
 static const char *draftfolder = NULL;
 
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    case ARG_DRAFTFOLDER:
-      draftfolder = arg;
-      break;
-      
-    case ARG_EDITOR:
-      wh_env.editor = arg;
-      break;
-      
-    case ARG_NODRAFTFOLDER:
-      draftfolder = NULL;
-      break;
-
-    case ARG_NOEDIT:
-      initial_edit = 0;
-      break;
-
-    case ARG_DRAFTMESSAGE:
-      draftmessage = arg;
-      break;
-
-    case ARG_PROMPT:
-      wh_env.prompt = arg;
-      break;
-      
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
+static struct mu_option options[] = {
+  { "draftfolder",   0,      N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder for message drafts"),
+    mu_c_string, &draftfolder },
+  { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("undo the effect of the last -draftfolder option"),
+    mu_c_string, &draftfolder, mh_opt_clear_string },
+  { "draftmessage" , 0, N_("MSG"), MU_OPTION_DEFAULT,
+    N_("invoke the draftmessage facility"),
+    mu_c_string, &draftmessage },
+  { "editor",        0, N_("PROG"), MU_OPTION_DEFAULT,
+    N_("set the editor program to use"),
+    mu_c_string, &wh_env.editor },
+  { "noedit",        0, NULL, MU_OPTION_DEFAULT,
+    N_("suppress the initial edit"),
+    mu_c_int, &initial_edit, NULL, "0" },
+  { "prompt", 0, N_("STRING"), MU_OPTION_DEFAULT,
+    N_("set the prompt"),
+    mu_c_string, &wh_env.prompt },
+  MU_OPTION_END
+};
+
 int
 main (int argc, char **argv)
 {
-  int index;
-  
   MU_APP_INIT_NLS ();
 
-  mh_argp_init ();
   mh_whatnow_env_from_environ (&wh_env);
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-  argc -= index;
-  argv += index;
+
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
+  
   if (argc)
     wh_env.draftfile = argv[0];
   else if (draftfolder)
diff --git a/mh/whom.c b/mh/whom.c
index 792a032..f21eee4 100644
--- a/mh/whom.c
+++ b/mh/whom.c
@@ -17,99 +17,58 @@
 
 #include <mh.h>
 
-static char doc[] = N_("GNU MH whom")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("GNU MH whom");
 static char args_doc[] = "[FILE]";
 
-/* GNU options */
-static struct argp_option options[] = {
-  {"alias",         ARG_ALIAS,         N_("FILE"), 0,
-   N_("specify additional alias file") },
-  {"draft",         ARG_DRAFT,         NULL, 0,
-   N_("use prepared draft") },
-  {"draftfolder",   ARG_DRAFTFOLDER,   N_("FOLDER"), 0,
-   N_("specify the folder for message drafts") },
-  {"draftmessage",  ARG_DRAFTMESSAGE,  NULL, 0,
-   N_("treat the arguments as a list of messages from the draftfolder") },
-  {"nodraftfolder", ARG_NODRAFTFOLDER, NULL, 0,
-   N_("undo the effect of the last --draftfolder option") },
-  {"check",         ARG_CHECK,         N_("BOOL"), OPTION_ARG_OPTIONAL,
-   N_("check if addresses are deliverable") },
-  {"nocheck",       ARG_NOCHECK,       NULL, OPTION_HIDDEN, "" },
-
-  {NULL}
-};
-
-/* Traditional MH options */
-struct mh_option mh_option[] = {
-  { "alias",         MH_OPT_ARG, "aliasfile" },
-  { "draft" },
-  { "draftfolder",   MH_OPT_ARG, "folder" },
-  { "draftmessage",  MH_OPT_ARG, "message" },
-  { "nodraftfolder" },
-  { "check",         MH_OPT_BOOL },
-  {NULL}
-};
-
 static int check_recipients;
 static int use_draft;            /* Use the prepared draft */
 static const char *draft_folder; /* Use this draft folder */
-
-static error_t
-opt_handler (int key, char *arg, struct argp_state *state)
+
+static void
+add_alias (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
-  switch (key)
-    {
-    case ARG_ALIAS:
-      mh_alias_read (arg, 1);
-      break;
-      
-    case ARG_DRAFT:
-      use_draft = 1;
-      break;
-	
-    case ARG_DRAFTFOLDER:
-      draft_folder = arg;
-      break;
-      
-    case ARG_NODRAFTFOLDER:
-      draft_folder = NULL;
-      break;
-      
-    case ARG_DRAFTMESSAGE:
-      if (!draft_folder)
-	draft_folder = mh_global_profile_get ("Draft-Folder",
-					      mu_folder_directory ());
-      break;
-
-    case ARG_CHECK:
-      check_recipients = is_true (arg);
-      break;
-
-    case ARG_NOCHECK:
-      check_recipients = 0;
-      break;
+  mh_alias_read (arg, 1);
+}
 
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
+static void
+set_draftmessage (struct mu_parseopt *po, struct mu_option *opt,
+		  char const *arg)
+{
+  if (!draft_folder)
+    draft_folder = mh_global_profile_get ("Draft-Folder",
+					  mu_folder_directory ());
 }
 
+static struct mu_option options[] = {
+  { "alias",        0,    N_("FILE"), MU_OPTION_DEFAULT,
+    N_("specify additional alias file"),
+    mu_c_string, NULL, add_alias },
+  { "draft",        0,    NULL, MU_OPTION_DEFAULT,
+    N_("use prepared draft"),
+    mu_c_bool, &use_draft },
+  { "draftfolder",   0,      N_("FOLDER"), MU_OPTION_DEFAULT,
+    N_("specify the folder for message drafts"),
+    mu_c_string, &draft_folder },
+  { "nodraftfolder", 0, NULL, MU_OPTION_DEFAULT,
+    N_("undo the effect of the last -draftfolder option"),
+    mu_c_string, &draft_folder, mh_opt_clear_string },
+  { "draftmessage",  0,  NULL, MU_OPTION_DEFAULT,
+    N_("treat the arguments as a list of messages from the draftfolder"),
+    mu_c_string, NULL, set_draftmessage },
+  { "check",         0,  NULL, MU_OPTION_DEFAULT,
+    N_("check if addresses are deliverable"),
+    mu_c_bool, &check_recipients },
+  MU_OPTION_END
+};
+
 int
 main (int argc, char **argv)
 {
-  int index;
   char *name = "draft";
   
   MU_APP_INIT_NLS ();
   
-  mh_argp_init ();
-  mh_argp_parse (&argc, &argv, 0, options, mh_option, args_doc, doc,
-		 opt_handler, NULL, &index);
-
-  argc -= index;
-  argv += index;
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (!use_draft && argc > 0)
     name = argv[0];
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d62e071..e75a7d9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -144,7 +144,6 @@ mh/inc.c
 mh/install-mh.c
 mh/mark.c
 mh/mboxprop.c
-mh/mh_argp.c
 mh/mh_fmtgram.y
 mh/mh_format.c
 mh/mh_getopt.c


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 22 08:45:44 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bxvgG-00030u-3L
	for mharc-commit-mailutils@gnu.org; Sat, 22 Oct 2016 08:45:44 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:39184)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxvgB-00030E-Ld
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 08:45:42 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxvg8-0004Nc-Tu
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 08:45:39 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:53934)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxvg8-0004NY-Kc
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 08:45:36 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 4A53C22015E; Sat, 22 Oct 2016 12:45:36 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-790-gd153077
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: e267ac86e2c3a78979fe12bdd16392f30f8d1725
X-Git-Newrev: d153077cd608fc034e61e046c59ff46159223b31
Message-Id: <20161022124536.4A53C22015E@vcs.savannah.gnu.org>
Date: Sat, 22 Oct 2016 12:45:36 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Oct 2016 12:45:42 -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=d153077cd608fc034e61e046c59ff46159223b31

The branch, master has been updated
       via  d153077cd608fc034e61e046c59ff46159223b31 (commit)
      from  e267ac86e2c3a78979fe12bdd16392f30f8d1725 (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 d153077cd608fc034e61e046c59ff46159223b31
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 22 14:29:20 2016 +0300

    MH: Fix MH-E compatibility
    
    * include/mailutils/cli.h (mu_version_func): Rename to mu_version_hook.
    * libmailutils/cli/cli.c: Likewise.
    * pop3d/popauth.c: Likewise.
    * mh/mh_getopt.c: (mh_getopt): Initialize NLS support. Install
    standard version hook (needed for mh-e autodetect feature).
    
    * mh/ali.c: Update prog_doc. Remove NLS initialization.
    * mh/anno.c: Likewise
    * mh/burst.c: Likewise
    * mh/comp.c: Likewise
    * mh/fmtcheck.c: Likewise
    * mh/folder.c: Likewise
    * mh/forw.c: Likewise
    * mh/inc.c: Likewise
    * mh/install-mh.c: Likewise
    * mh/mark.c: Likewise
    * mh/mhl.c: Likewise
    * mh/mhn.c: Likewise
    * mh/mhparam.c: Likewise
    * mh/mhpath.c: Likewise
    * mh/mhseq.c: Likewise
    * mh/msgchk.c: Likewise
    * mh/pick.c: Likewise
    * mh/prompter.c: Likewise
    * mh/refile.c: Likewise
    * mh/repl.c: Likewise
    * mh/rmf.c: Likewise
    * mh/rmm.c: Likewise
    * mh/scan.c: Likewise
    * mh/send.c: Likewise
    * mh/show.c: Likewise
    * mh/sortm.c: Likewise
    * mh/whatnow.c: Likewise
    * mh/whom.c: Likewise

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

Summary of changes:
 include/mailutils/cli.h |    2 +-
 libmailutils/cli/cli.c  |    4 ++--
 mh/ali.c                |    5 +----
 mh/anno.c               |    4 +---
 mh/burst.c              |    5 +----
 mh/comp.c               |    8 ++------
 mh/fmtcheck.c           |    5 +----
 mh/folder.c             |    5 +----
 mh/forw.c               |    5 +----
 mh/inc.c                |    5 +----
 mh/install-mh.c         |    3 ---
 mh/mark.c               |    4 +---
 mh/mh_getopt.c          |   30 +++++-------------------------
 mh/mhl.c                |    4 +---
 mh/mhn.c                |    4 +---
 mh/mhparam.c            |    5 +----
 mh/mhpath.c             |    5 +----
 mh/mhseq.c              |    7 +------
 mh/msgchk.c             |    4 +---
 mh/pick.c               |    4 +---
 mh/prompter.c           |    4 +---
 mh/refile.c             |    5 +----
 mh/repl.c               |    5 +----
 mh/rmf.c                |    5 +----
 mh/rmm.c                |    5 +----
 mh/scan.c               |    5 +----
 mh/send.c               |    4 +---
 mh/show.c               |    5 +----
 mh/sortm.c              |    5 +----
 mh/whatnow.c            |    4 +---
 mh/whom.c               |    6 ++----
 pop3d/popauth.c         |    2 +-
 32 files changed, 38 insertions(+), 135 deletions(-)

diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index d2964ff..fbf31f3 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -54,7 +54,7 @@ struct mu_cli_setup
   void (*prog_doc_hook) (mu_stream_t);
 };
 
-void mu_version_func (struct mu_parseopt *po, mu_stream_t stream);
+void mu_version_hook (struct mu_parseopt *po, mu_stream_t stream);
 void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
 	     char **capa, void *data,
 	     int *ret_argc, char ***ret_argv);
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 0a608ba..d607551 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -54,7 +54,7 @@ const char mu_version_copyright[] =
   "Copyright %s 2007-2016 Free Software Foundation, inc.";
 
 void
-mu_version_func (struct mu_parseopt *po, mu_stream_t stream)
+mu_version_hook (struct mu_parseopt *po, mu_stream_t stream)
 {
 #ifdef GIT_DESCRIBE
   mu_stream_printf (stream, "%s (%s) %s [%s]\n",
@@ -428,7 +428,7 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   po.po_extra_info = gnu_general_help_url;
   flags |= MU_PARSEOPT_EXTRA_INFO;
 
-  po.po_version_hook = mu_version_func;
+  po.po_version_hook = mu_version_hook;
   flags |= MU_PARSEOPT_VERSION_HOOK;
 
   if (setup->prog_extra_doc)
diff --git a/mh/ali.c b/mh/ali.c
index d52145a..4d95a97 100644
--- a/mh/ali.c
+++ b/mh/ali.c
@@ -23,7 +23,7 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 
-static char prog_doc[] = N_("GNU MH ali");
+static char prog_doc[] = N_("List mail aliases");
 static char args_doc[] = N_("ALIAS [ALIAS...]");
 
 static int list_mode;
@@ -142,9 +142,6 @@ ali_print_name (char *name)
 int
 main (int argc, char **argv)
 {
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (!nolist_mode)
diff --git a/mh/anno.c b/mh/anno.c
index aa36718..604b9be 100644
--- a/mh/anno.c
+++ b/mh/anno.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH anno");
+static char prog_doc[] = N_("Annotate messages");
 static char args_doc[] = N_("[MSGLIST]");
 
 //static int inplace;       /* Annotate the message in place */
@@ -58,8 +58,6 @@ main (int argc, char **argv)
   mu_msgset_t msgset;
   size_t len;
 
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
   if (anno_text)
diff --git a/mh/burst.c b/mh/burst.c
index 87b067c..173a8f7 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -18,7 +18,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH burst");
+static char prog_doc[] = N_("Explode digests into messages");
 static char args_doc[] = N_("[MSGLIST]");
 
 /* Command line switches */
@@ -652,9 +652,6 @@ main (int argc, char **argv)
   mu_msgset_t msgset;
   const char *tempfolder = mh_global_profile_get ("Temp-Folder", ".temp");
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
   if (eb_min_length == 0)
diff --git a/mh/comp.c b/mh/comp.c
index c80e343..8a9df01 100644
--- a/mh/comp.c
+++ b/mh/comp.c
@@ -21,7 +21,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-static char prog_doc[] = N_("GNU MH comp");
+static char prog_doc[] = N_("Compose a message");
 static char args_doc[] = N_("[MSG]");
 
 struct mh_whatnow_env wh_env = { 0 };
@@ -131,14 +131,10 @@ copy_message (mu_mailbox_t mbox, size_t n, const char *file)
 int
 main (int argc, char **argv)
 {
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
   whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
 
-  mh_getopt (&argc, &argv, options, 0,
-	     args_doc, prog_doc, NULL);
+  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
   if (use_draft)
     draftmessage = "cur";
   if (!formfile)
diff --git a/mh/fmtcheck.c b/mh/fmtcheck.c
index c3a2b46..93aea17 100644
--- a/mh/fmtcheck.c
+++ b/mh/fmtcheck.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH fmtcheck");
+static char prog_doc[] = N_("Check MH format string");
 
 char *format_str;
 static mh_format_t format;
@@ -59,9 +59,6 @@ action_dump (void)
 int
 main (int argc, char **argv)
 {
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL);
   mh_format_debug (debug_option);
   if (format_str && mh_format_parse (format_str, &format))
diff --git a/mh/folder.c b/mh/folder.c
index e68a624..cc9142a 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -28,7 +28,7 @@
 
 #include <dirent.h>
 
-static char prog_doc[] = N_("GNU MH folder");
+static char prog_doc[] = N_("set or list current folder or message");
 static char args_doc[] = N_("[ACTION] [MSG]");
 
 typedef int (*folder_action) (void);
@@ -889,9 +889,6 @@ main (int argc, char **argv)
   int index = 0;
   mu_msgset_t msgset;
 
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
   if (recurse_option)
     max_depth = 0;
diff --git a/mh/forw.c b/mh/forw.c
index 7c25ea8..5c9fd93 100644
--- a/mh/forw.c
+++ b/mh/forw.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH forw");
+static char prog_doc[] = N_("Forward messages");
 static char args_doc[] = N_("[MSGLIST]");
 
 enum encap_type
@@ -383,9 +383,6 @@ main (int argc, char **argv)
 {
   int rc;
 
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
   whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
diff --git a/mh/inc.c b/mh/inc.c
index f6fed0f..987c1d1 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -20,7 +20,7 @@
 #include <mh.h>
 #include "muscript.h"
 
-static char prog_doc[] = N_("GNU MH inc");
+static char prog_doc[] = N_("Incorporate new mail");
 static char extra_doc[] = N_("Debug flags are:\n\
   g - guile stack traces\n\
   t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
@@ -345,9 +345,6 @@ main (int argc, char **argv)
   size_t lastseen;
   const char *unseen_seq;
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-  
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, extra_doc);
   if (!append_folder)
     append_folder = mh_global_profile_get ("Inbox", "inbox");
diff --git a/mh/install-mh.c b/mh/install-mh.c
index 0432ba2..9f6f7d9 100644
--- a/mh/install-mh.c
+++ b/mh/install-mh.c
@@ -35,9 +35,6 @@ main (int argc, char **argv)
   char *name;
   extern int mh_auto_install;
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_auto_install = 0;
   mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL);
 
diff --git a/mh/mark.c b/mh/mark.c
index 3c17752..8365b18 100644
--- a/mh/mark.c
+++ b/mh/mark.c
@@ -17,7 +17,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH mark");
+static char prog_doc[] = N_("Manipulate message sequences");
 static char args_doc[] = N_("[MSGLIST]");
 
 enum action_type
@@ -167,8 +167,6 @@ main (int argc, char **argv)
   mu_url_t url;
   struct mark_closure clos;
   
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
   if (public_option == -1)
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 50a034c..62fbc8e 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -26,6 +26,7 @@
 #include <mailutils/stream.h>
 #include <mailutils/wordsplit.h>
 #include <mailutils/io.h>
+#include <mailutils/cli.h>
 
 struct getopt_data
 {
@@ -140,30 +141,6 @@ static struct mu_option folder_option[] = {
   MU_OPTION_END
 };
 
-void
-mh_version_hook (struct mu_parseopt *po, mu_stream_t stream)
-{
-  extern const char mu_version_copyright[];
-#ifdef GIT_DESCRIBE
-  mu_stream_printf (stream, "%s (GNU MH, %s) %s [%s]\n",
-		    mu_program_name, PACKAGE_NAME, PACKAGE_VERSION,
-		    GIT_DESCRIBE);
-#else
-  mu_stream_printf (stream, "%s (GNU MH, %s) %s\n", mu_program_name,
-		    PACKAGE_NAME, PACKAGE_VERSION);
-#endif
-  /* TRANSLATORS: Translate "(C)" to the copyright symbol
-     (C-in-a-circle), if this symbol is available in the user's
-     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
-  mu_stream_printf (stream, mu_version_copyright, _("(C)"));
-  mu_stream_printf (stream, _("\
-\n\
-License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
-There is NO WARRANTY, to the extent permitted by law.\n\
-\n\
-"));
-}
-
 static void
 fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
@@ -192,6 +169,9 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   int flags = MU_PARSEOPT_SINGLE_DASH | MU_PARSEOPT_IMMEDIATE;
   int i;
   
+  /* Native Language Support */
+  MU_APP_INIT_NLS ();
+
   po.po_negation = "no";
   flags |= MU_PARSEOPT_NEGATION;
 
@@ -233,7 +213,7 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   //po.po_extra_info = gnu_general_help_url;
   //flags |= MU_PARSEOPT_EXTRA_INFO;
 
-  po.po_version_hook = mh_version_hook;
+  po.po_version_hook = mu_version_hook;
   flags |= MU_PARSEOPT_VERSION_HOOK;
   
   mu_set_program_name (argv[0]);
diff --git a/mh/mhl.c b/mh/mhl.c
index 3b6ca6e..d26574d 100644
--- a/mh/mhl.c
+++ b/mh/mhl.c
@@ -21,7 +21,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-static char prog_doc[] = N_("GNU MH mhl");
+static char prog_doc[] = N_("Produce formatted listings of MH messages");
 static char args_doc[] = N_("[FILE [FILE...]]");
 
 static int bell_option;
@@ -138,8 +138,6 @@ main (int argc, char **argv)
   
   interactive = isatty (1) && isatty (0);
   
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);  
 
diff --git a/mh/mhn.c b/mh/mhn.c
index 1f04c6f..357c824 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -22,7 +22,7 @@
 #include <mailutils/mime.h>
 #include <setjmp.h>
 
-static char prog_doc[] = N_("GNU MH mhn");
+static char prog_doc[] = N_("manipulate MIME messages");
 static char args_doc[] = N_("[MSGLIST]");
 
 typedef struct _msg_part *msg_part_t;
@@ -2759,8 +2759,6 @@ main (int argc, char **argv)
 {
   int rc;
   
-  MU_APP_INIT_NLS ();
-  
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
   if (!formfile)
     mh_find_file ("mhl.headers", &formfile);
diff --git a/mh/mhparam.c b/mh/mhparam.c
index 12733de..8b9b8bb 100644
--- a/mh/mhparam.c
+++ b/mh/mhparam.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH mhparam");
+static char prog_doc[] = N_("Print GNU MH profile and context components");
 static char args_doc[] = N_("[COMPONENT [COMPONENT...]]");
 
 static int display_all;
@@ -87,9 +87,6 @@ mhparam (char *comp)
 int
 main (int argc, char **argv)
 {
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (display_all)
diff --git a/mh/mhpath.c b/mh/mhpath.c
index 9ef8b6c..c1fe01f 100644
--- a/mh/mhpath.c
+++ b/mh/mhpath.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH mhpath");
+static char prog_doc[] = N_("Print full pathnames of GNU MH messages and folders");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 static int
@@ -43,9 +43,6 @@ main (int argc, char **argv)
   int status;
   const char *current_folder;
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
 
diff --git a/mh/mhseq.c b/mh/mhseq.c
index 142903c..d64ce64 100644
--- a/mh/mhseq.c
+++ b/mh/mhseq.c
@@ -14,11 +14,9 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-/* MH mhparam command */
-
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH mhseq");
+static char prog_doc[] = N_("Print numbers of messages in GNU MH sequence");
 static char args_doc[] = N_("[SEQUENCE]");
 
 static int uid_option = 1;
@@ -46,9 +44,6 @@ main (int argc, char **argv)
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
     
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
 
diff --git a/mh/msgchk.c b/mh/msgchk.c
index c9f63d5..b2b3812 100644
--- a/mh/msgchk.c
+++ b/mh/msgchk.c
@@ -21,7 +21,7 @@
 #include "mailutils/datetime.h"
 #include <pwd.h>
 
-static char prog_doc[] = N_("GNU MH msgchk");
+static char prog_doc[] = N_("Check for messages");
 static char args_doc[] = N_("USER [USER...]");
 
 int date_option = 1;
@@ -349,8 +349,6 @@ main (int argc, char **argv)
 {
   int rc = 0;
   
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);  
 
   if (argc == 0)
diff --git a/mh/pick.c b/mh/pick.c
index 3624267..9a78866 100644
--- a/mh/pick.c
+++ b/mh/pick.c
@@ -22,7 +22,7 @@
 #include <pick.h>
 #include <pick-gram.h>
 
-static char prog_doc[] = N_("GNU MH pick");
+static char prog_doc[] = N_("Search for messages by content");
 static char args_doc[] = N_("[--COMPONENT PATTERN]... [MSGLIST]");
 
 static int public_option = 1;
@@ -267,8 +267,6 @@ main (int argc, char **argv)
   mu_mailbox_t mbox;
   mu_msgset_t msgset;
 
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
 
diff --git a/mh/prompter.c b/mh/prompter.c
index 116e102..5c4405f 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -19,7 +19,7 @@
 #include <mh.h>
 #include "prompter.h"
 
-static char prog_doc[] = N_("GNU MH prompter");
+static char prog_doc[] = N_("Prompting editor front-end for GNU MH");
 static char args_doc[] = N_("FILE");
 
 char *erase_seq;
@@ -88,8 +88,6 @@ main (int argc, char **argv)
   mu_body_t body;
   mu_stream_t bstr;
   
-  MU_APP_INIT_NLS ();
-  
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (argc == 0)
diff --git a/mh/refile.c b/mh/refile.c
index 36bffbf..8c7747d 100644
--- a/mh/refile.c
+++ b/mh/refile.c
@@ -23,7 +23,7 @@
 #include <errno.h>
 #include <fcntl.h>
 
-static char prog_doc[] = N_("GNU MH refile");
+static char prog_doc[] = N_("File messages in other folders");
 static char args_doc[] = N_("MSGLIST FOLDER [FOLDER...]");
 
 int link_flag = 0;
@@ -185,9 +185,6 @@ main (int argc, char **argv)
   mu_mailbox_t mbox;
   int status, i, j;
 
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
   /* Collect any surplus folders */
   for (i = j = 0; i < argc; i++)
diff --git a/mh/repl.c b/mh/repl.c
index 826ecaf..d546d2c 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -22,7 +22,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-static char prog_doc[] = N_("GNU MH repl");
+static char prog_doc[] = N_("Reply to a message");
 static char args_doc[] = N_("[+FOLDER] [MESSAGE]");
 
 static char *format_str = NULL;
@@ -307,9 +307,6 @@ main (int argc, char **argv)
 {
   int rc;
 
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   draftfolder = mh_global_profile_get ("Draft-Folder", NULL);
   whatnowproc = mh_global_profile_get ("whatnowproc", NULL);
 
diff --git a/mh/rmf.c b/mh/rmf.c
index 91d66af..17e9cf2 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -28,7 +28,7 @@
 
 #include <dirent.h>
 
-static char prog_doc[] = N_("GNU MH rmf");
+static char prog_doc[] = N_("Remove a GNU MH folder");
 static char args_doc[] = N_("[+FOLDER]");
 
 int explicit_folder; /* Was the folder explicitly given */
@@ -150,9 +150,6 @@ main (int argc, char **argv)
   int status;
   char *name;
 
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   cur_folder_path = current_folder_path ();
diff --git a/mh/rmm.c b/mh/rmm.c
index 7b0de27..c0ba7d5 100644
--- a/mh/rmm.c
+++ b/mh/rmm.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH rmm");
+static char prog_doc[] = N_("Remove messages");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 static int
@@ -56,9 +56,6 @@ main (int argc, char **argv)
   int status;
   struct seq_closure clos;
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, NULL, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
 
diff --git a/mh/scan.c b/mh/scan.c
index 3a197c7..29ed31e 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -26,7 +26,7 @@
 #include <time.h>
 #include <mailutils/observer.h>
 
-static char prog_doc[] = N_("GNU MH scan");
+static char prog_doc[] = N_("Produce a one line per message scan listing");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 static int clear;
@@ -103,9 +103,6 @@ main (int argc, char **argv)
   int status;
   size_t total = 0;
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
 
diff --git a/mh/send.c b/mh/send.c
index cb9c2b8..260b5c8 100644
--- a/mh/send.c
+++ b/mh/send.c
@@ -23,7 +23,7 @@
 #include <stdarg.h>
 #include <pwd.h>
 
-static char prog_doc[] = N_("GNU MH send");
+static char prog_doc[] = N_("Send messages");
 static char args_doc[] = N_("FILE [FILE...]");
 
 static const char *draftfolder;  /* Use this draft folder */
@@ -752,8 +752,6 @@ main (int argc, char **argv)
   char *p;
   int rc;
   
-  MU_APP_INIT_NLS ();
-  
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   mh_read_aliases ();
diff --git a/mh/show.c b/mh/show.c
index fcd87eb..ca7330c 100644
--- a/mh/show.c
+++ b/mh/show.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH show");
+static char prog_doc[] = N_("Display GNU MH messages");
 static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
 
 int use_draft;
@@ -184,9 +184,6 @@ main (int argc, char **argv)
   mu_msgset_t msgset;
   const char *p;
   
-  /* Native Language Support */
-  MU_APP_INIT_NLS ();
-
   showargmax = 2;
   showargc = 1;
   showargv = mu_calloc (showargmax, sizeof showargv[0]);
diff --git a/mh/sortm.c b/mh/sortm.c
index bb991cf..4415422 100644
--- a/mh/sortm.c
+++ b/mh/sortm.c
@@ -22,8 +22,7 @@
 #include <unistd.h>
 #include <signal.h>
 
-static char prog_doc[] = N_("GNU MH sortm")"\v"
-N_("Use -help to obtain the list of traditional MH options.");
+static char prog_doc[] = N_("Sort GNU MH messages");
 static char args_doc[] = N_("[MSGLIST]");
 
 static int limit;
@@ -603,8 +602,6 @@ main (int argc, char **argv)
   mu_url_t url;
   mu_msgset_t msgset;
   
-  MU_APP_INIT_NLS ();
-
   mh_getopt (&argc, &argv, options, MH_GETOPT_DEFAULT_FOLDER,
 	     args_doc, prog_doc, NULL);
   
diff --git a/mh/whatnow.c b/mh/whatnow.c
index 9e0d38e..5307174 100644
--- a/mh/whatnow.c
+++ b/mh/whatnow.c
@@ -19,7 +19,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = "GNU MH whatnow";
+static char prog_doc[] = N_("Prompting front-end for sending messages");
 static char args_doc[] = N_("[FILE]");
 
 struct mh_whatnow_env wh_env = { 0 };
@@ -52,8 +52,6 @@ static struct mu_option options[] = {
 int
 main (int argc, char **argv)
 {
-  MU_APP_INIT_NLS ();
-
   mh_whatnow_env_from_environ (&wh_env);
 
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
diff --git a/mh/whom.c b/mh/whom.c
index f21eee4..2211dee 100644
--- a/mh/whom.c
+++ b/mh/whom.c
@@ -17,7 +17,7 @@
 
 #include <mh.h>
 
-static char prog_doc[] = N_("GNU MH whom");
+static char prog_doc[] = N_("Report to whom a message would go");
 static char args_doc[] = "[FILE]";
 
 static int check_recipients;
@@ -65,9 +65,7 @@ int
 main (int argc, char **argv)
 {
   char *name = "draft";
-  
-  MU_APP_INIT_NLS ();
-  
+
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
 
   if (!use_draft && argc > 0)
diff --git a/pop3d/popauth.c b/pop3d/popauth.c
index 8e85438..248fb4c 100644
--- a/pop3d/popauth.c
+++ b/pop3d/popauth.c
@@ -149,7 +149,7 @@ popauth_version (struct mu_parseopt *po, mu_stream_t stream)
   mu_iterator_t itr;
   int rc;
 
-  mu_version_func (po, stream);
+  mu_version_hook (po, stream);
   mu_stream_printf (stream, _("Database formats: "));
 
   rc = mu_dbm_impl_iterator (&itr);


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 22 09:56:16 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bxwmV-0005e2-UL
	for mharc-commit-mailutils@gnu.org; Sat, 22 Oct 2016 09:56:15 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49670)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxwmT-0005cq-QG
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 09:56:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxwmS-0003ak-Q1
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 09:56:13 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:54412)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxwmS-0003aa-NE
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 09:56:12 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 8660422015E; Sat, 22 Oct 2016 13:56:10 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-791-g6856669
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d153077cd608fc034e61e046c59ff46159223b31
X-Git-Newrev: 6856669720c066769f82b90fee521fd05794dec0
Message-Id: <20161022135612.8660422015E@vcs.savannah.gnu.org>
Date: Sat, 22 Oct 2016 13:56:10 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Oct 2016 13:56:15 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=6856669720c066769f82b90fee521fd05794dec0

The branch, master has been updated
       via  6856669720c066769f82b90fee521fd05794dec0 (commit)
      from  d153077cd608fc034e61e046c59ff46159223b31 (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 6856669720c066769f82b90fee521fd05794dec0
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 22 16:53:48 2016 +0300

    Bugfixes
    
    * libmu_auth/ldap.c: Fix compilation without ldap
    * mh/mh_getopt.c: Fix version output to match what MH-E expects

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

Summary of changes:
 libmu_auth/ldap.c |    3 ++-
 mh/mh_getopt.c    |   25 ++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index 246f802..c886e71 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -920,10 +920,11 @@ mu_auth_ldap_user_by_uid (struct mu_auth_data **return_data,
 
 
 #else
-# define mu_ldap_module_init NULL
+# define module_init NULL
 # define mu_ldap_authenticate mu_auth_nosupport
 # define mu_auth_ldap_user_by_name mu_auth_nosupport 
 # define mu_auth_ldap_user_by_uid mu_auth_nosupport
+# define mu_ldap_param NULL
 
 #endif
 
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 62fbc8e..bddd942 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -141,6 +141,29 @@ static struct mu_option folder_option[] = {
   MU_OPTION_END
 };
 
+void
+mh_version_hook (struct mu_parseopt *po, mu_stream_t stream)
+{
+#ifdef GIT_DESCRIBE
+  mu_stream_printf (stream, "%s (%s %s) [%s]\n",
+		    mu_program_name, PACKAGE_NAME, PACKAGE_VERSION,
+		    GIT_DESCRIBE);
+#else
+  mu_stream_printf (stream, "%s (%s %s)\n", mu_program_name,
+		    PACKAGE_NAME, PACKAGE_VERSION);
+#endif
+  /* TRANSLATORS: Translate "(C)" to the copyright symbol
+     (C-in-a-circle), if this symbol is available in the user's
+     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
+  mu_stream_printf (stream, mu_version_copyright, _("(C)"));
+  mu_stream_printf (stream, _("\
+\n\
+License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\n\
+There is NO WARRANTY, to the extent permitted by law.\n\
+\n\
+"));
+}
+
 static void
 fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
 {
@@ -213,7 +236,7 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   //po.po_extra_info = gnu_general_help_url;
   //flags |= MU_PARSEOPT_EXTRA_INFO;
 
-  po.po_version_hook = mu_version_hook;
+  po.po_version_hook = mh_version_hook;
   flags |= MU_PARSEOPT_VERSION_HOOK;
   
   mu_set_program_name (argv[0]);


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 22 13:05:24 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bxzjX-0002ZB-Th
	for mharc-commit-mailutils@gnu.org; Sat, 22 Oct 2016 13:05:23 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:55802)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxzjU-0002Ya-0k
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 13:05:21 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxzjS-0001en-4D
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 13:05:19 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:56003)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bxzjS-0001eZ-0B
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 13:05:18 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id B42BA22015E; Sat, 22 Oct 2016 17:05:17 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-792-g97fb478
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 6856669720c066769f82b90fee521fd05794dec0
X-Git-Newrev: 97fb4785661350ab0ff8ae5605d1bdf7f6566386
Message-Id: <20161022170517.B42BA22015E@vcs.savannah.gnu.org>
Date: Sat, 22 Oct 2016 17:05:17 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Oct 2016 17:05: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=97fb4785661350ab0ff8ae5605d1bdf7f6566386

The branch, master has been updated
       via  97fb4785661350ab0ff8ae5605d1bdf7f6566386 (commit)
      from  6856669720c066769f82b90fee521fd05794dec0 (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 97fb4785661350ab0ff8ae5605d1bdf7f6566386
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 22 18:39:50 2016 +0300

    Provide extended interface to mu_cli.
    
    * include/mailutils/cfg.h (MU_CFG_APPEND_TREE): New flag.
    * include/mailutils/cli.h (mu_version_copyright): New extern.
    (mu_cli_ext): New proto.
    * libmailutils/cfg/parser.y (mu_cfg_parse_config): Check for
    MU_CFG_APPEND_TREE bit set before accessing hints->append_tree.
    * libmailutils/cli/cli.c (param_set): Likewise.
    (mu_cli_ext): New function.
    (mu_cli): Rewrite as an entry point to mu_cli_ext.
    
    * comsat/comsat.c: Remove inclusion of obsolete headers.
    * mu/help.c: Likewise.
    * pop3d/extra.c: Likewise.

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

Summary of changes:
 comsat/comsat.c           |    3 +-
 include/mailutils/cfg.h   |    1 +
 include/mailutils/cli.h   |    9 +++
 libmailutils/cfg/parser.y |    2 +-
 libmailutils/cli/cli.c    |  139 ++++++++++++++++++++++++++++++++-------------
 mu/help.c                 |    1 -
 pop3d/extra.c             |    1 -
 7 files changed, 113 insertions(+), 43 deletions(-)

diff --git a/comsat/comsat.c b/comsat/comsat.c
index c12ed20..e16f91a 100644
--- a/comsat/comsat.c
+++ b/comsat/comsat.c
@@ -16,8 +16,7 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "comsat.h"
-#define MU_CFG_COMPATIBILITY /* This source uses deprecated cfg interfaces */
-#include "mailutils/libcfg.h"
+#include "mailutils/syslog.h"
 #include "mailutils/cli.h"
 
 #ifndef PATH_DEV
diff --git a/include/mailutils/cfg.h b/include/mailutils/cfg.h
index e9f3587..1a69c82 100644
--- a/include/mailutils/cfg.h
+++ b/include/mailutils/cfg.h
@@ -241,6 +241,7 @@ int mu_config_register_plain_section (const char *parent_path,
 #define MU_CFG_FMT_VALUE_ONLY      0x100
 #define MU_CFG_FMT_PARAM_PATH      0x200
 #define MU_PARSE_CONFIG_LINT       0x400
+#define MU_CFG_APPEND_TREE         0x800
   
 #ifdef MU_CFG_COMPATIBILITY
 # define MU_CFG_DEPRECATED
diff --git a/include/mailutils/cli.h b/include/mailutils/cli.h
index fbf31f3..eaf0f8d 100644
--- a/include/mailutils/cli.h
+++ b/include/mailutils/cli.h
@@ -54,10 +54,19 @@ struct mu_cli_setup
   void (*prog_doc_hook) (mu_stream_t);
 };
 
+extern const char mu_version_copyright[];
+
 void mu_version_hook (struct mu_parseopt *po, mu_stream_t stream);
 void mu_cli (int argc, char **argv, struct mu_cli_setup *setup,
 	     char **capa, void *data,
 	     int *ret_argc, char ***ret_argv);
+void mu_cli_ext (int argc, char **argv,
+		 struct mu_cli_setup *setup,
+		 struct mu_parseopt *pohint,
+		 struct mu_cfg_parse_hints *cfhint,
+		 char **capa,
+		 void *data,
+		 int *ret_argc, char ***ret_argv);
 
 char *mu_site_config_file (void);
 
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index 043f7e0..a530f10 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -1590,7 +1590,7 @@ mu_cfg_parse_config (mu_cfg_tree_t **ptree, struct mu_cfg_parse_hints *hints)
 	}
     }
 
-  if (hints->append_tree)
+  if (hints->flags & MU_CFG_APPEND_TREE)
     mu_cfg_tree_union (&tree, &hints->append_tree);
 
   *ptree = tree;
diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index d607551..bf3edae 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -155,8 +155,11 @@ param_set (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
   if (rc)
     mu_parseopt_error (po, "%s: cannot create node: %s",
 		       arg, mu_strerror (rc));
-  if (!hints->append_tree)
-    mu_cfg_tree_create (&hints->append_tree);
+  if (!(hints->flags & MU_CFG_APPEND_TREE))
+    {
+      mu_cfg_tree_create (&hints->append_tree);
+      hints->flags |= MU_CFG_APPEND_TREE;
+    }
   mu_cfg_tree_add_node (hints->append_tree, node);
 }
 
@@ -334,11 +337,25 @@ run_commit (void *item, void *data)
   commit (data);
   return 0;
 }
-  
+
+#define PRESERVE_FLAGS \
+  ( MU_PARSEOPT_NO_SORT					\
+    | MU_PARSEOPT_SINGLE_DASH				\
+    | MU_PARSEOPT_PACKAGE_NAME				\
+    | MU_PARSEOPT_PACKAGE_URL				\
+    | MU_PARSEOPT_BUG_ADDRESS				\
+    | MU_PARSEOPT_EXTRA_INFO				\
+    | MU_PARSEOPT_VERSION_HOOK				\
+    | MU_PARSEOPT_NEGATION)
+
 void
-mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
-	void *data,
-	int *ret_argc, char ***ret_argv)
+mu_cli_ext (int argc, char **argv,
+	    struct mu_cli_setup *setup,
+	    struct mu_parseopt *pohint,
+	    struct mu_cfg_parse_hints *cfhint,
+	    char **capa,
+	    void *data,
+	    int *ret_argc, char ***ret_argv)
 {
   struct mu_parseopt po;
   int flags = 0;
@@ -356,14 +373,22 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
     setup->ex_usage = EX_USAGE;
   if (setup->ex_config == 0)
     setup->ex_config = EX_CONFIG;
-  if (setup->inorder)
-    flags |= MU_PARSEOPT_IN_ORDER;
-    
-  /* Set program name */
-  mu_set_program_name (argv[0]);
 
-  if (!mu_log_tag)
-    mu_log_tag = (char*)mu_program_name;
+  hints = *cfhint;
+  /* Set program name */
+  if (hints.flags & MU_CFG_PARSE_PROGRAM)
+    {
+      if (!mu_log_tag)
+	mu_log_tag = (char*)hints.program;
+    }
+  else
+    {
+      mu_set_program_name (argv[0]);
+      if (!mu_log_tag)
+	mu_log_tag = (char*)mu_program_name;
+      hints.program = (char*) mu_program_name;
+      hints.flags |= MU_CFG_PARSE_PROGRAM;
+    }
 
   /* Initialize standard streams */
   mu_stdstream_setup (MU_STDSTREAM_RESET_NONE);
@@ -371,16 +396,6 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
   /* Initialize standard capabilities */
   mu_cli_capa_init ();
 
-  /* Initialize hints */
-  memset (&hints, 0, sizeof (hints));
-  hints.flags |= MU_CFG_PARSE_SITE_RCFILE;
-  hints.site_rcfile = mu_site_config_file ();
-
-  hints.flags |= MU_CFG_PARSE_PROGRAM;
-  hints.program = (char*) mu_program_name;
-
-  hints.data = setup;
-  
   /* Initialize po */
   
   if (setup->prog_doc)
@@ -388,6 +403,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
       po.po_prog_doc = setup->prog_doc;
       flags |= MU_PARSEOPT_PROG_DOC;
     }
+  else if (pohint->po_flags & MU_PARSEOPT_PROG_DOC)
+    {
+      po.po_prog_doc = pohint->po_prog_doc;
+      flags |= MU_PARSEOPT_PROG_DOC;
+    }
 
   if (setup->prog_args)
     {
@@ -415,21 +435,11 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 
       flags |= MU_PARSEOPT_PROG_ARGS;
     }
-  
-  po.po_package_name = PACKAGE_NAME;
-  flags |= MU_PARSEOPT_PACKAGE_NAME;
-
-  po.po_package_url = PACKAGE_URL;
-  flags |= MU_PARSEOPT_PACKAGE_URL;
-
-  po.po_bug_address = PACKAGE_BUGREPORT;
-  flags |= MU_PARSEOPT_BUG_ADDRESS;
-
-  po.po_extra_info = gnu_general_help_url;
-  flags |= MU_PARSEOPT_EXTRA_INFO;
-
-  po.po_version_hook = mu_version_hook;
-  flags |= MU_PARSEOPT_VERSION_HOOK;
+  else if (pohint->po_flags & MU_PARSEOPT_PROG_ARGS)
+    {
+      po.po_prog_args = pohint->po_prog_args;
+      flags |= MU_PARSEOPT_PROG_ARGS;
+    }
 
   if (setup->prog_extra_doc)
     {
@@ -442,7 +452,30 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
       po.po_prog_doc_hook = prog_doc_hook;
       flags |= MU_PARSEOPT_PROG_DOC_HOOK;
     }
+  else if (pohint->po_flags & MU_PARSEOPT_PROG_DOC_HOOK)
+    {
+      po.po_prog_doc_hook = pohint->po_prog_doc_hook;
+      flags |= MU_PARSEOPT_PROG_DOC_HOOK;
+    }
+  
+  if (setup->inorder)
+    flags |= MU_PARSEOPT_IN_ORDER;
   
+  flags |= pohint->po_flags & PRESERVE_FLAGS;
+
+  if (flags & MU_PARSEOPT_PACKAGE_NAME)
+    po.po_package_name = pohint->po_package_name;
+  if (flags & MU_PARSEOPT_PACKAGE_URL)
+    po.po_package_url = pohint->po_package_url;
+  if (flags & MU_PARSEOPT_BUG_ADDRESS)
+    po.po_bug_address = pohint->po_bug_address;
+  if (flags & MU_PARSEOPT_EXTRA_INFO)
+    po.po_extra_info = pohint->po_extra_info;
+  if (flags & MU_PARSEOPT_VERSION_HOOK)
+    po.po_version_hook = pohint->po_version_hook;
+  if (flags & MU_PARSEOPT_NEGATION)
+    po.po_negation = pohint->po_negation;
+
   po.po_data = &hints;
   flags |= MU_PARSEOPT_DATA;
 
@@ -488,3 +521,33 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 
   mu_parseopt_free (&po);  
 }
+
+void
+mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
+	void *data,
+	int *ret_argc, char ***ret_argv)
+{
+  struct mu_parseopt pohint;
+  struct mu_cfg_parse_hints cfhint;
+  
+  pohint.po_package_name = PACKAGE_NAME;
+  pohint.po_flags |= MU_PARSEOPT_PACKAGE_NAME;
+
+  pohint.po_package_url = PACKAGE_URL;
+  pohint.po_flags |= MU_PARSEOPT_PACKAGE_URL;
+
+  pohint.po_bug_address = PACKAGE_BUGREPORT;
+  pohint.po_flags |= MU_PARSEOPT_BUG_ADDRESS;
+
+  pohint.po_extra_info = gnu_general_help_url;
+  pohint.po_flags |= MU_PARSEOPT_EXTRA_INFO;
+
+  pohint.po_version_hook = mu_version_hook;
+  pohint.po_flags |= MU_PARSEOPT_VERSION_HOOK;
+
+  cfhint.site_rcfile = mu_site_config_file ();
+  cfhint.flags = MU_CFG_PARSE_SITE_RCFILE;
+  
+  mu_cli_ext (argc, argv, setup, &pohint, &cfhint, capa, data,
+	      ret_argc, ret_argv);
+}
diff --git a/mu/help.c b/mu/help.c
index 3334417..c2dcf1a 100644
--- a/mu/help.c
+++ b/mu/help.c
@@ -22,7 +22,6 @@
 #include <stdlib.h>
 #include <mailutils/nls.h>
 #include <mailutils/io.h>
-#include "mailutils/libargp.h"
 #include "mu.h"
 
 static char help_doc[] = N_("mu help - display a terse help summary");
diff --git a/pop3d/extra.c b/pop3d/extra.c
index 608d8fc..aa15f79 100644
--- a/pop3d/extra.c
+++ b/pop3d/extra.c
@@ -16,7 +16,6 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "pop3d.h"
-#include "mailutils/libargp.h"
 #include "mailutils/property.h"
 
 mu_stream_t iostream;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 22 14:04:40 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1by0eu-0000WI-AE
	for mharc-commit-mailutils@gnu.org; Sat, 22 Oct 2016 14:04:40 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:36708)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1by0er-0000WB-Px
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 14:04:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1by0eq-00005e-8k
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 14:04:37 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:56490)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1by0eq-00005N-3s
	for commit-mailutils@gnu.org; Sat, 22 Oct 2016 14:04:36 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id E0C8822015E; Sat, 22 Oct 2016 18:04:35 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-793-gd8194bb
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 97fb4785661350ab0ff8ae5605d1bdf7f6566386
X-Git-Newrev: d8194bb31044d2140a7b3c0e877ae59c20152a35
Message-Id: <20161022180435.E0C8822015E@vcs.savannah.gnu.org>
Date: Sat, 22 Oct 2016 18:04:35 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 22 Oct 2016 18:04:39 -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=d8194bb31044d2140a7b3c0e877ae59c20152a35

The branch, master has been updated
       via  d8194bb31044d2140a7b3c0e877ae59c20152a35 (commit)
      from  97fb4785661350ab0ff8ae5605d1bdf7f6566386 (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 d8194bb31044d2140a7b3c0e877ae59c20152a35
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 22 21:00:45 2016 +0300

    Bugfixes
    
    * libmailutils/cli/cli.c (mu_cli_ext): Initialize hints.data
    (accidentally deleted).
    * libmailutils/opt/help.c (mu_option_describe_options): Don't
    display dup_args_note in single-dash mode.
    * libmailutils/opt/progname.c (mu_set_program_name): Free the
    old value after allocating new copy.  This allows to pass
    mu_full_program_name as argument.  Set mu_program_name to point
    to a segment of mu_full_program_name, not the original arg.
    * mh/mh_getopt.c: Remove duplicate version option.
    * po/POTFILES.in: Add missing files.

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

Summary of changes:
 libmailutils/cli/cli.c      |    2 ++
 libmailutils/opt/help.c     |    2 +-
 libmailutils/opt/progname.c |    5 +++--
 mh/mh_getopt.c              |   15 ---------------
 mu/dispatch.c               |    2 +-
 po/POTFILES.in              |    5 +++++
 6 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index bf3edae..8432aa3 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -375,6 +375,8 @@ mu_cli_ext (int argc, char **argv,
     setup->ex_config = EX_CONFIG;
 
   hints = *cfhint;
+  hints.data = setup;
+  
   /* Set program name */
   if (hints.flags & MU_CFG_PARSE_PROGRAM)
     {
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index 9ad20f0..538e311 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -334,7 +334,7 @@ mu_option_describe_options (mu_stream_t str, struct mu_parseopt *po)
     i = print_option (str, po, i, &argsused);
   mu_stream_printf (str, "\n");
 
-  if (argsused && dup_args_note)
+  if (argsused && !(po->po_flags & MU_PARSEOPT_SINGLE_DASH) && dup_args_note)
     {
       set_margin (str, 0);
       mu_stream_printf (str, "%s\n\n",
diff --git a/libmailutils/opt/progname.c b/libmailutils/opt/progname.c
index 0d19773..7652387 100644
--- a/libmailutils/opt/progname.c
+++ b/libmailutils/opt/progname.c
@@ -30,10 +30,11 @@ mu_set_program_name (const char *arg)
 {
   char *p;
 
+  p = mu_strdup (arg);
   free (mu_full_program_name);
-  mu_full_program_name = mu_strdup (arg);
+  mu_full_program_name = p;
   
-  p = strrchr (arg, '/');
+  p = strrchr (mu_full_program_name, '/');
   if (p)
     ++p;
   else
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index bddd942..13feda9 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -164,20 +164,6 @@ There is NO WARRANTY, to the extent permitted by law.\n\
 "));
 }
 
-static void
-fn_version (struct mu_parseopt *po, struct mu_option *opt, char const *unused)
-{
-  mu_program_version (po, mu_strout);
-  exit (0);
-}
-
-static struct mu_option version_option[] = {
-  { "version", 0, NULL, MU_OPTION_DEFAULT,
-    N_("print program version"),
-    mu_c_string, NULL, fn_version },
-  MU_OPTION_END
-};
-
 void
 mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
 	   int mhflags,
@@ -248,7 +234,6 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
     optv[i++] = folder_option;
   if (options)
     optv[i++] = options;
-  optv[i++] = version_option;
   optv[i] = NULL;
   
   if (mu_parseopt (&po, argc, argv, optv, flags))
diff --git a/mu/dispatch.c b/mu/dispatch.c
index cd27a66..6054e7a 100644
--- a/mu/dispatch.c
+++ b/mu/dispatch.c
@@ -54,7 +54,7 @@ subcommand_help (mu_stream_t str)
 {
   struct mutool_action_tab *p;
   unsigned margin;
-  
+
   mu_stream_printf (str, "%s\n\n", _("Commands are:"));
   for (p = mutool_action_tab; p->name; p++)
     {
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e75a7d9..0f08d37 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -104,6 +104,11 @@ libmailutils/diag/errors
 libmailutils/opt/opt.c
 libmailutils/opt/help.c
 
+libmailutils/cli/acl.c
+libmailutils/cli/capa.c
+libmailutils/cli/cli.c
+libmailutils/cli/stdcapa.c
+
 libmailutils/server/acl.c
 
 libmailutils/stream/file_stream.c


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Oct 23 13:48:37 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1byMsv-0000iu-8H
	for mharc-commit-mailutils@gnu.org; Sun, 23 Oct 2016 13:48:37 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:49639)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1byMst-0000ij-3o
	for commit-mailutils@gnu.org; Sun, 23 Oct 2016 13:48:36 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1byMsr-00015Y-Vo
	for commit-mailutils@gnu.org; Sun, 23 Oct 2016 13:48:35 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:40494)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1byMsr-00015U-Si
	for commit-mailutils@gnu.org; Sun, 23 Oct 2016 13:48:33 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id A9C45220124; Sun, 23 Oct 2016 17:48:33 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-794-gcd577bf
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: d8194bb31044d2140a7b3c0e877ae59c20152a35
X-Git-Newrev: cd577bf9f6ce6fa3402b34f322516e49a9e72d00
Message-Id: <20161023174833.A9C45220124@vcs.savannah.gnu.org>
Date: Sun, 23 Oct 2016 17:48:33 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sun, 23 Oct 2016 17:48:36 -0000

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

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

The branch, master has been updated
       via  cd577bf9f6ce6fa3402b34f322516e49a9e72d00 (commit)
      from  d8194bb31044d2140a7b3c0e877ae59c20152a35 (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 cd577bf9f6ce6fa3402b34f322516e49a9e72d00
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Sun Oct 23 20:46:34 2016 +0300

    Bugfix

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

Summary of changes:
 mh/inc.c |    5 +++++
 mh/mhn.c |    3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/mh/inc.c b/mh/inc.c
index 987c1d1..ed9c011 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -348,6 +348,11 @@ main (int argc, char **argv)
   mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, extra_doc);
   if (!append_folder)
     append_folder = mh_global_profile_get ("Inbox", "inbox");
+  if (argc)
+    {
+      mu_error (_("unrecognized arguments"));
+      exit (1);
+    }
 
   mu_registrar_set_default_scheme ("mh");
 
diff --git a/mh/mhn.c b/mh/mhn.c
index 357c824..b3c2cb7 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -2808,8 +2808,9 @@ main (int argc, char **argv)
       mbox = mh_open_folder (mh_current_folder (), MU_STREAM_READ);
       mh_msgset_parse (&msgset, mbox, argc, argv, "cur");
       /* FIXME: Combine the three */
+      rc = 0;
       if (list_option)
-	rc = mhn_list ();
+	rc |= mhn_list ();
       if (show_option)
 	rc |= mhn_show ();
       if (store_option)


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 24 02:09:57 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1byYSL-0000Rx-4o
	for mharc-commit-mailutils@gnu.org; Mon, 24 Oct 2016 02:09:57 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:53261)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1byYSI-0000Rm-4L
	for commit-mailutils@gnu.org; Mon, 24 Oct 2016 02:09:56 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1byYSG-0007ja-KP
	for commit-mailutils@gnu.org; Mon, 24 Oct 2016 02:09:54 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:46359)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1byYSG-0007jS-Fx
	for commit-mailutils@gnu.org; Mon, 24 Oct 2016 02:09:52 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 3E21D220124; Mon, 24 Oct 2016 06:09:52 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-795-g4872fc4
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: cd577bf9f6ce6fa3402b34f322516e49a9e72d00
X-Git-Newrev: 4872fc4fb478af6c718fad0a43004fdbebc53fc0
Message-Id: <20161024060952.3E21D220124@vcs.savannah.gnu.org>
Date: Mon, 24 Oct 2016 06:09:52 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 24 Oct 2016 06:09:56 -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=4872fc4fb478af6c718fad0a43004fdbebc53fc0

The branch, master has been updated
       via  4872fc4fb478af6c718fad0a43004fdbebc53fc0 (commit)
      from  cd577bf9f6ce6fa3402b34f322516e49a9e72d00 (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 4872fc4fb478af6c718fad0a43004fdbebc53fc0
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Mon Oct 24 09:04:09 2016 +0300

    Improve program usage output.
    
    * include/mailutils/opt.h (MU_PARSEOPT_SPECIAL_ARGS): New flag.
    (mu_parseopt)<po_special_args>: New field.
    * libmailutils/opt/help.c (option_summary)
    (print_program_usage): Print po_special_args, if defined.
    * libmailutils/opt/opt.c (parseopt_init): Initialize po_special_args
    unless MU_PARSEOPT_SPECIAL_ARGS is set.
    
    MH: Advertise [+FOLDER] special argument if the -folder option is declared.
    
    * mh/mh_getopt.c (folder_option): Bugfix: -folder takes argument.
    (mh_getopt): Set po_special_args if the -folder option is declared.
    * mh/inc.c: Fix arg_doc.
    * mh/mhpath.c: Likewise.
    * mh/repl.c: Likewise.
    * mh/rmf.c: Likewise.
    * mh/rmm.c: Likewise.
    * mh/scan.c: Likewise.
    * mh/show.c: Likewise.

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

Summary of changes:
 include/mailutils/opt.h |    5 ++++-
 libmailutils/opt/help.c |   14 +++++++++-----
 libmailutils/opt/opt.c  |    2 ++
 mh/inc.c                |    3 +--
 mh/mh_getopt.c          |   28 ++++++++++++++++++++++++++--
 mh/mhpath.c             |    2 +-
 mh/repl.c               |    2 +-
 mh/rmf.c                |    3 +--
 mh/rmm.c                |    2 +-
 mh/scan.c               |    2 +-
 mh/show.c               |    2 +-
 11 files changed, 48 insertions(+), 17 deletions(-)

diff --git a/include/mailutils/opt.h b/include/mailutils/opt.h
index 6a7f2dc..268956d 100644
--- a/include/mailutils/opt.h
+++ b/include/mailutils/opt.h
@@ -109,6 +109,8 @@ struct mu_option_cache
 #define MU_PARSEOPT_SINGLE_DASH    0x02000000
 /* Negation prefix is set */
 #define MU_PARSEOPT_NEGATION       0x04000000
+/* po_special_args is set */
+#define MU_PARSEOPT_SPECIAL_ARGS   0x08000000
 
 /* Reuse mu_parseopt struct initialized previously */
 #define MU_PARSEOPT_REUSE          0x80000000
@@ -131,8 +133,9 @@ struct mu_parseopt
   
   /* Informational: */
   char const *po_prog_name;
-  char const *po_prog_doc;	
+  char const *po_prog_doc;
   char const **po_prog_args;
+  char const *po_special_args;     /* Special option-like arguments */
   char const *po_bug_address;
   char const *po_package_name;
   char const *po_package_url;
diff --git a/libmailutils/opt/help.c b/libmailutils/opt/help.c
index 538e311..d24bbe7 100644
--- a/libmailutils/opt/help.c
+++ b/libmailutils/opt/help.c
@@ -523,6 +523,9 @@ option_summary (struct mu_parseopt *po, mu_stream_t str)
 	}
     }
 
+  if (po->po_special_args)
+    mu_stream_printf (str, " %s", gettext (po->po_special_args));
+  
   free (idxbuf);
 }  
 
@@ -535,10 +538,7 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
   
   usage_text = _("Usage:");
 
-  if (po->po_flags & MU_PARSEOPT_PROG_ARGS)
-    arg_text = po->po_prog_args;
-  else
-    arg_text = NULL;
+  arg_text = po->po_prog_args;
   i = 0;
   
   do
@@ -552,7 +552,11 @@ print_program_usage (struct mu_parseopt *po, int optsum, mu_stream_t str)
 	  optsum = 0;
 	}
       else
-	mu_stream_printf (str, "[%s...]", _("OPTION"));
+	{
+	  mu_stream_printf (str, "[%s...]", _("OPTION"));
+	  if (po->po_special_args)
+	    mu_stream_printf (str, " %s", gettext (po->po_special_args));
+	}
 
       if (arg_text)
 	{
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 3a34a7f..26633bb 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -578,6 +578,8 @@ parseopt_init (struct mu_parseopt *po, struct mu_option **options,
     po->po_prog_doc = NULL;
   if (!(flags & MU_PARSEOPT_PROG_ARGS))
     po->po_prog_args = NULL;
+  if (!(flags & MU_PARSEOPT_SPECIAL_ARGS))
+    po->po_special_args = NULL;
   if (!(flags & MU_PARSEOPT_BUG_ADDRESS))
     po->po_bug_address = NULL;
   if (!(flags & MU_PARSEOPT_PACKAGE_NAME))
diff --git a/mh/inc.c b/mh/inc.c
index ed9c011..1477dd5 100644
--- a/mh/inc.c
+++ b/mh/inc.c
@@ -26,7 +26,6 @@ static char extra_doc[] = N_("Debug flags are:\n\
   t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n\
   i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n\
   l - sieve action logs");
-static char args_doc[] = N_("[+FOLDER]");
 
 static char *format_str = mh_list_format;
 static int width = 80;
@@ -345,7 +344,7 @@ main (int argc, char **argv)
   size_t lastseen;
   const char *unseen_seq;
   
-  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, extra_doc);
+  mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, extra_doc);
   if (!append_folder)
     append_folder = mh_global_profile_get ("Inbox", "inbox");
   if (argc)
diff --git a/mh/mh_getopt.c b/mh/mh_getopt.c
index 13feda9..08c9001 100644
--- a/mh/mh_getopt.c
+++ b/mh/mh_getopt.c
@@ -135,7 +135,7 @@ mh_opt_set_folder (struct mu_parseopt *po, struct mu_option *opt,
 }
 
 static struct mu_option folder_option[] = {
-  { "folder", 0, NULL, MU_OPTION_DEFAULT,
+  { "folder", 0, N_("FOLDER"), MU_OPTION_DEFAULT,
     N_("set current folder"),
     mu_c_string, NULL, mh_opt_set_folder },
   MU_OPTION_END
@@ -164,6 +164,19 @@ There is NO WARRANTY, to the extent permitted by law.\n\
 "));
 }
 
+static int
+has_folder_option (struct mu_option *opt)
+{
+  while (!MU_OPTION_IS_END (opt))
+    {
+      if (MU_OPTION_IS_VALID_LONG_OPTION (opt)
+	  && strcmp (opt->opt_long, "folder") == 0)
+	return 1;
+      ++opt;
+    }
+  return 0;
+}
+
 void
 mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
 	   int mhflags,
@@ -184,6 +197,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
   po.po_negation = "no";
   flags |= MU_PARSEOPT_NEGATION;
 
+  if ((mhflags & MH_GETOPT_DEFAULT_FOLDER) || has_folder_option (options))
+    {
+      po.po_special_args = N_("[+FOLDER]");
+      flags |= MU_PARSEOPT_SPECIAL_ARGS;
+    }
+
   if (argdoc)
     {
       args[0] = argdoc;
@@ -248,7 +267,12 @@ mh_getopt (int *pargc, char ***pargv, struct mu_option *options,
 
   if (!argdoc && argc)
     {
-      mu_error (_("Extra arguments"));
+      mu_diag_init ();
+      mu_stream_printf (mu_strerr, "\033s<%d>", MU_DIAG_ERROR);
+      mu_stream_printf (mu_strerr, "%s", _("unrecognized extra arguments:"));
+      for (i = 0; i < argc; i++)
+	mu_stream_printf (mu_strerr, " %s", argv[i]);
+      mu_stream_write (mu_strerr, "\n", 1, NULL);
       exit (1);
     }
 
diff --git a/mh/mhpath.c b/mh/mhpath.c
index c1fe01f..dd1ce94 100644
--- a/mh/mhpath.c
+++ b/mh/mhpath.c
@@ -20,7 +20,7 @@
 #include <mh.h>
 
 static char prog_doc[] = N_("Print full pathnames of GNU MH messages and folders");
-static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
+static char args_doc[] = N_("[MSGLIST]");
 
 static int
 mhpath (size_t num, mu_message_t msg, void *data)
diff --git a/mh/repl.c b/mh/repl.c
index d546d2c..13fa8c9 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -23,7 +23,7 @@
 #include <unistd.h>
 
 static char prog_doc[] = N_("Reply to a message");
-static char args_doc[] = N_("[+FOLDER] [MESSAGE]");
+static char args_doc[] = N_("[MESSAGE]");
 
 static char *format_str = NULL;
 static mh_format_t format;
diff --git a/mh/rmf.c b/mh/rmf.c
index 17e9cf2..40748c3 100644
--- a/mh/rmf.c
+++ b/mh/rmf.c
@@ -29,7 +29,6 @@
 #include <dirent.h>
 
 static char prog_doc[] = N_("Remove a GNU MH folder");
-static char args_doc[] = N_("[+FOLDER]");
 
 int explicit_folder; /* Was the folder explicitly given */
 int interactive; /* Ask for confirmation before deleting */
@@ -150,7 +149,7 @@ main (int argc, char **argv)
   int status;
   char *name;
 
-  mh_getopt (&argc, &argv, options, 0, args_doc, prog_doc, NULL);
+  mh_getopt (&argc, &argv, options, 0, NULL, prog_doc, NULL);
 
   cur_folder_path = current_folder_path ();
 
diff --git a/mh/rmm.c b/mh/rmm.c
index c0ba7d5..50675eb 100644
--- a/mh/rmm.c
+++ b/mh/rmm.c
@@ -20,7 +20,7 @@
 #include <mh.h>
 
 static char prog_doc[] = N_("Remove messages");
-static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
+static char args_doc[] = N_("[MSGLIST]");
 
 static int
 rmm (size_t num, mu_message_t msg, void *data)
diff --git a/mh/scan.c b/mh/scan.c
index 29ed31e..5defd8a 100644
--- a/mh/scan.c
+++ b/mh/scan.c
@@ -27,7 +27,7 @@
 #include <mailutils/observer.h>
 
 static char prog_doc[] = N_("Produce a one line per message scan listing");
-static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
+static char args_doc[] = N_("[MSGLIST]");
 
 static int clear;
 static char *format_str = mh_list_format;
diff --git a/mh/show.c b/mh/show.c
index ca7330c..ecac725 100644
--- a/mh/show.c
+++ b/mh/show.c
@@ -20,7 +20,7 @@
 #include <mh.h>
 
 static char prog_doc[] = N_("Display GNU MH messages");
-static char args_doc[] = N_("[+FOLDER] [MSGLIST]");
+static char args_doc[] = N_("[MSGLIST]");
 
 int use_draft;
 int use_showproc = 1;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 24 07:53:17 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1bydoa-0000E7-SU
	for mharc-commit-mailutils@gnu.org; Mon, 24 Oct 2016 07:53:16 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:45394)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bydoY-0000CZ-Ew
	for commit-mailutils@gnu.org; Mon, 24 Oct 2016 07:53:15 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bydoX-0005Ub-IV
	for commit-mailutils@gnu.org; Mon, 24 Oct 2016 07:53:14 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:49861)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1bydoX-0005UW-FQ
	for commit-mailutils@gnu.org; Mon, 24 Oct 2016 07:53:13 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 387F72201D5; Mon, 24 Oct 2016 11:53:13 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-796-ga6bd9b6
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 4872fc4fb478af6c718fad0a43004fdbebc53fc0
X-Git-Newrev: a6bd9b68b90e7c106d9021aaa83c2b3c82809b18
Message-Id: <20161024115313.387F72201D5@vcs.savannah.gnu.org>
Date: Mon, 24 Oct 2016 11:53:13 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 24 Oct 2016 11:53:15 -0000

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

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

The branch, master has been updated
       via  a6bd9b68b90e7c106d9021aaa83c2b3c82809b18 (commit)
      from  4872fc4fb478af6c718fad0a43004fdbebc53fc0 (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 a6bd9b68b90e7c106d9021aaa83c2b3c82809b18
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Mon Oct 24 14:52:16 2016 +0300

    Bugfix

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

Summary of changes:
 libmailutils/cli/cli.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 8432aa3..266cb7b 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -531,6 +531,8 @@ mu_cli (int argc, char **argv, struct mu_cli_setup *setup, char **capa,
 {
   struct mu_parseopt pohint;
   struct mu_cfg_parse_hints cfhint;
+
+  pohint.po_flags = 0;
   
   pohint.po_package_name = PACKAGE_NAME;
   pohint.po_flags |= MU_PARSEOPT_PACKAGE_NAME;


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Fri Oct 28 13:23:20 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1c0AsC-0006OY-0C
	for mharc-commit-mailutils@gnu.org; Fri, 28 Oct 2016 13:23:20 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:36930)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0As6-0006JK-Jf
	for commit-mailutils@gnu.org; Fri, 28 Oct 2016 13:23:18 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0As5-0005Te-4Q
	for commit-mailutils@gnu.org; Fri, 28 Oct 2016 13:23:14 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:55379)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0As5-0005Ta-1G
	for commit-mailutils@gnu.org; Fri, 28 Oct 2016 13:23:13 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 9B4C12201D5; Fri, 28 Oct 2016 17:23:12 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-797-gb48ac92
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: a6bd9b68b90e7c106d9021aaa83c2b3c82809b18
X-Git-Newrev: b48ac923058cb1967209ee2883d93d55932a0364
Message-Id: <20161028172312.9B4C12201D5@vcs.savannah.gnu.org>
Date: Fri, 28 Oct 2016 17:23:12 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Fri, 28 Oct 2016 17:23: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=b48ac923058cb1967209ee2883d93d55932a0364

The branch, master has been updated
       via  b48ac923058cb1967209ee2883d93d55932a0364 (commit)
      from  a6bd9b68b90e7c106d9021aaa83c2b3c82809b18 (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 b48ac923058cb1967209ee2883d93d55932a0364
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Fri Oct 28 20:05:06 2016 +0300

    Bugfix
    
    * configure.ac: Version 2.99.992
    * NEWS: Update.
    * libmailutils/opt/opt.c (add_option_cache): Use opt_default if
    no argument is given.

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

Summary of changes:
 NEWS                   |    4 ++--
 configure.ac           |    2 +-
 libmailutils/opt/opt.c |    6 ++++++
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 7ebc72a..40768fa 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,11 @@
-GNU mailutils NEWS -- history of user-visible changes. 2016-10-19
+GNU mailutils NEWS -- history of user-visible changes. 2016-10-28
 Copyright (C) 2002-2016 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
 Please send mailutils bug reports to <bug-mailutils@gnu.org>.
 
 
-Version 2.99.991 (Git)
+Version 2.99.992 (Git)
 
 This version is a major rewrite of GNU Mailutils.  Quite a few parts
 of the basic framework were rewritten from scratch, while some others
diff --git a/configure.ac b/configure.ac
index 5fd7d85..4b88e6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU General Public License along
 dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AC_PREREQ(2.63)
-AC_INIT([GNU Mailutils], [2.99.991], [bug-mailutils@gnu.org], [mailutils],
+AC_INIT([GNU Mailutils], [2.99.992], [bug-mailutils@gnu.org], [mailutils],
         [http://mailutils.org])
 AC_CONFIG_SRCDIR([libmailutils/mailbox/mailbox.c])
 AC_CONFIG_AUX_DIR([build-aux])
diff --git a/libmailutils/opt/opt.c b/libmailutils/opt/opt.c
index 26633bb..0a436c5 100644
--- a/libmailutils/opt/opt.c
+++ b/libmailutils/opt/opt.c
@@ -148,7 +148,10 @@ add_option_cache (struct mu_parseopt *po, struct mu_option *opt,
 		  char const *arg)
 {
   struct mu_option_cache *cache = mu_alloc (sizeof (*cache));
+  
   cache->cache_opt = opt;
+  if (arg == NULL && opt->opt_default)
+    arg = opt->opt_default;
   cache->cache_arg = arg;
 
   if ((po->po_flags & MU_PARSEOPT_IMMEDIATE)
@@ -749,6 +752,9 @@ mu_option_set_value (struct mu_parseopt *po, struct mu_option *opt,
       if (arg == NULL)
 	{
 	  if (opt->opt_default)
+	    /* The default value has been already assigned in add_option_cache.
+	       This conditional is here in case mu_option_set_value is called
+	       from the user code. */
 	    arg = opt->opt_default;
 	  else if (opt->opt_arg == NULL)
 	    arg = "1";


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 29 13:55:52 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1c0XrD-0000SX-T6
	for mharc-commit-mailutils@gnu.org; Sat, 29 Oct 2016 13:55:51 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:52162)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0XrA-0000SC-UP
	for commit-mailutils@gnu.org; Sat, 29 Oct 2016 13:55:50 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0Xr9-0000vm-1V
	for commit-mailutils@gnu.org; Sat, 29 Oct 2016 13:55:48 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:39755)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0Xr8-0000vi-TE
	for commit-mailutils@gnu.org; Sat, 29 Oct 2016 13:55:46 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 9AED32201D5; Sat, 29 Oct 2016 17:55:46 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-798-g3a91a69
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: b48ac923058cb1967209ee2883d93d55932a0364
X-Git-Newrev: 3a91a69baef99247b066e2c5ce4fce6bf739f1ac
Message-Id: <20161029175546.9AED32201D5@vcs.savannah.gnu.org>
Date: Sat, 29 Oct 2016 17:55:46 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 29 Oct 2016 17:55:51 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=3a91a69baef99247b066e2c5ce4fce6bf739f1ac

The branch, master has been updated
       via  3a91a69baef99247b066e2c5ce4fce6bf739f1ac (commit)
      from  b48ac923058cb1967209ee2883d93d55932a0364 (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 3a91a69baef99247b066e2c5ce4fce6bf739f1ac
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 29 20:53:47 2016 +0300

    Remove left over references to argp; other bugfixes

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

Summary of changes:
 README                           |    6 -----
 bootstrap.conf                   |    7 +-----
 configure.ac                     |   10 +-------
 frm/frm.c                        |    4 +--
 include/mailutils/gnu/.gitignore |    1 -
 libmailutils/auth/mu_auth.c      |   10 +++++---
 libmailutils/opt/progname.c      |    2 +-
 libmailutils/stdstream/basestr.c |   51 ++++++++++++++++++++++----------------
 mh/pick.y                        |    6 ++---
 mu-aux/mailutils.m4              |    1 -
 mu/filter.c                      |    1 -
 mu/imap.c                        |    1 -
 mu/smtp.c                        |    1 -
 mu/template.c                    |   32 ++----------------------
 readmsg/readmsg.c                |    4 +--
 sieve/sieve.c                    |    4 +--
 16 files changed, 50 insertions(+), 91 deletions(-)

diff --git a/README b/README
index 6cfef48..fd4a22d 100644
--- a/README
+++ b/README
@@ -248,12 +248,6 @@ mailutils-specific configuration options:
 
        Use the GNU gettext library included in the Mailutils distribution.
 
-    --with-included-argp
-
-        Use the argp library supplied with the package, instead of the
-        one from your libc. You will need this option if the libc library
-        on your system was compiled without NLS support.
-
 The following options enable DBM support in Mailutils. DBM support is
 necessary if you wish to use APOP authentication in POP3 daemon or to
 use DBM-based mail box quotas with maildag.
diff --git a/bootstrap.conf b/bootstrap.conf
index b014791..d969396 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -63,12 +63,7 @@ XGETTEXT_OPTIONS=$XGETTEXT_OPTIONS'\\\
  --flag=mu_cfg_format_error:3:c-format\\\
  --flag=ali_parse_error:1:c-format\\\
  --flag=asnprintf:3:c-format --flag=vasnprintf:3:c-format\\\
- --flag=argp_error:2:c-format\\\
- --flag=__argp_error:2:c-format\\\
- --flag=argp_failure:4:c-format\\\
- --flag=__argp_failure:4:c-format\\\
- --flag=argp_fmtstream_printf:2:c-format\\\
- --flag=__argp_fmtstream_printf:2:c-format\\\
+ --flag=mu_parseopt_error:2:c-format\\\
 '
 
 # Gettext supplies these files, but we don't need them since
diff --git a/configure.ac b/configure.ac
index 4b88e6c..b8161ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -49,7 +49,6 @@ AC_SUBST(MU_LIB_POP)
 AC_SUBST(MU_LIB_SIEVE,'${top_builddir}/libmu_sieve/libmu_sieve.la')
 AC_SUBST(MU_LIB_SCM)
 AC_SUBST(MU_LIB_CPP)
-AC_SUBST(MU_LIB_ARGP,'${top_builddir}/libmu_argp/libmu_argp.la')
 AC_SUBST(MU_LIB_PY)
 
 dnl Other variables
@@ -70,7 +69,7 @@ AC_SUBST(MU_APP_LIBRARIES,'${top_builddir}/lib/libmuaux.la')
 
 AC_SUBST(MU_LIB_COMMON_INCLUDES,'-I${top_builddir} -I${top_srcdir}/include  -I${top_builddir}/include')
 
-AC_SUBST(MU_APP_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_srcdir}/lib/gnu -I${top_builddir}/lib/gnu -I${top_builddir} -I${top_builddir}/include -I${top_srcdir}/libmu_argp -I${top_srcdir}/libmu_cfg')
+AC_SUBST(MU_APP_COMMON_INCLUDES,'-I${srcdir} -I${top_srcdir}/include -I${top_srcdir}/lib -I${top_srcdir}/lib/gnu -I${top_builddir}/lib/gnu -I${top_builddir} -I${top_builddir}/include')
 
 dnl Check for programs
 AC_PROG_CC
@@ -125,13 +124,6 @@ AH_BOTTOM([
 AC_SUBST(MU_LINK_POSTFLAGS,[`for opt in $LTLIBICONV; do case $opt in -[[lL]]*) echo $opt;; esac; done|tr '\n' ' '`])
 
 
-dnl Escape defuns that force automake to add their arguments
-dnl to LIBOBJS.
-dnl All dependencies has been handled by gnulib-sync.
-
-AC_DEFINE([GNULIB_ARGP_EXTERN_BASENAME],1,
-          [Define to use our own version of __argp_base_name])
-
 # Check for large file support
 AC_SYS_LARGEFILE
 
diff --git a/frm/frm.c b/frm/frm.c
index 192521c..0f73b85 100644
--- a/frm/frm.c
+++ b/frm/frm.c
@@ -177,7 +177,7 @@ static struct mu_cli_setup cli = {
   N_("[URL ...]"),
 };
 
-static char *frm_argp_capa[] = {
+static char *capa[] = {
   "debug",
   "mailbox",
   "locking",
@@ -328,7 +328,7 @@ main (int argc, char **argv)
   mu_register_all_mbox_formats ();
 
   mu_auth_register_module (&mu_auth_tls_module);
-  mu_cli (argc, argv, &cli, frm_argp_capa, NULL, &argc, &argv);
+  mu_cli (argc, argv, &cli, capa, NULL, &argc, &argv);
 
   if (align && (s = util_getcols ()))
     init_output (s);
diff --git a/include/mailutils/gnu/.gitignore b/include/mailutils/gnu/.gitignore
index 545d850..43e57f7 100644
--- a/include/mailutils/gnu/.gitignore
+++ b/include/mailutils/gnu/.gitignore
@@ -1,7 +1,6 @@
 Makefile
 Makefile.in
 getopt.h 
-argp.h
 regex.h 
 posix
 posix/regex.h
diff --git a/libmailutils/auth/mu_auth.c b/libmailutils/auth/mu_auth.c
index 54896e1..6d10ef7 100644
--- a/libmailutils/auth/mu_auth.c
+++ b/libmailutils/auth/mu_auth.c
@@ -234,16 +234,20 @@ int
 mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
              const void *key)
 {
+  enum mu_auth_mode mode;
+  
   if (!mu_getpw_modules)
     mu_auth_begin_setup ();
   switch (type)
     {
     case mu_auth_key_name:
+      mode = mu_auth_getpwnam;
       mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1,
                 ("Getting auth info for user %s", (char*) key));
       break;
 
     case mu_auth_key_uid:
+      mode = mu_auth_getpwuid;
       mu_debug (MU_DEBCAT_AUTH, MU_DEBUG_TRACE1, 
                 ("Getting auth info for UID %lu",
 		 (unsigned long) *(uid_t*) key));
@@ -254,7 +258,7 @@ mu_get_auth (struct mu_auth_data **auth, enum mu_auth_key_type type,
                 ("Unknown mu_auth_key_type: %d", type));
       return EINVAL;
     }
-  return mu_auth_runlist (mu_getpw_modules, type, key, NULL, auth);
+  return mu_auth_runlist (mu_getpw_modules, mode, key, NULL, auth);
 }
 
 struct mu_auth_data *
@@ -289,7 +293,7 @@ mu_authenticate (struct mu_auth_data *auth_data, const char *pass)
     mu_auth_begin_setup ();
   return mu_auth_runlist (mu_auth_modules,
 			  mu_auth_authenticate,
-			  auth_data, pass, NULL);
+			  auth_data, (void *) pass, NULL);
 }
 
 
@@ -434,7 +438,7 @@ mu_authentication_clear_list ()
    2) --authentication and --authorization modify only temporary lists,
       which get flushed to the main ones when mu_auth_finish_setup() is
       run. Thus, the default "generic:system" remain in force until
-      argp_parse() exits. */
+      mu_cli_ext exits. */
    
 void
 mu_auth_begin_setup (void)
diff --git a/libmailutils/opt/progname.c b/libmailutils/opt/progname.c
index 7652387..1855f3a 100644
--- a/libmailutils/opt/progname.c
+++ b/libmailutils/opt/progname.c
@@ -38,7 +38,7 @@ mu_set_program_name (const char *arg)
   if (p)
     ++p;
   else
-    p = (char*) arg;
+    p = (char*) mu_full_program_name;
   if (strlen (p) > 3 && memcmp (p, "lt-", 3) == 0)
     p += 3;
   free (mu_program_name);
diff --git a/libmailutils/stdstream/basestr.c b/libmailutils/stdstream/basestr.c
index 76d4336..fcddd40 100644
--- a/libmailutils/stdstream/basestr.c
+++ b/libmailutils/stdstream/basestr.c
@@ -117,32 +117,39 @@ bootstrap_destroy (struct _mu_stream *str)
 
 /* Standard I/O streams: */
 static struct _mu_file_stream stdstream[2] = {
-  { { ref_count: 1,
-      buftype: mu_buffer_none,
-      flags: MU_STREAM_READ,
-      destroy: bootstrap_destroy,
-      event_cb: std_bootstrap,
-      event_mask: _MU_STR_EVMASK (_MU_STR_EVENT_BOOTSTRAP)
-    }, fd: MU_STDIN_FD, filename: "<stdin>",
-    flags: _MU_FILE_STREAM_FD_BORROWED|_MU_FILE_STREAM_STATIC_FILENAME },
-  { { ref_count: 1,
-      buftype: mu_buffer_none,
-      flags: MU_STREAM_WRITE,
-      destroy: bootstrap_destroy,
-      event_cb: std_bootstrap,
-      event_mask: _MU_STR_EVMASK (_MU_STR_EVENT_BOOTSTRAP)
-    }, fd: MU_STDOUT_FD, filename: "<stdout>",
-    flags: _MU_FILE_STREAM_FD_BORROWED|_MU_FILE_STREAM_STATIC_FILENAME }
+  { .stream = {
+      .ref_count = 1,
+      .buftype = mu_buffer_none,
+      .flags = MU_STREAM_READ,
+      .destroy = bootstrap_destroy,
+      .event_cb = std_bootstrap,
+      .event_mask = _MU_STR_EVMASK (_MU_STR_EVENT_BOOTSTRAP)
+    },
+    .fd = MU_STDIN_FD,
+    .filename = "<stdin>",
+    .flags = _MU_FILE_STREAM_FD_BORROWED|_MU_FILE_STREAM_STATIC_FILENAME },
+  { .stream = {
+      .ref_count = 1,
+      .buftype = mu_buffer_none,
+      .flags = MU_STREAM_WRITE,
+      .destroy = bootstrap_destroy,
+      .event_cb = std_bootstrap,
+      .event_mask = _MU_STR_EVMASK (_MU_STR_EVENT_BOOTSTRAP)
+    },
+    .fd = MU_STDOUT_FD,
+    .filename = "<stdout>",
+    .flags = _MU_FILE_STREAM_FD_BORROWED|_MU_FILE_STREAM_STATIC_FILENAME }
 };
 
 /* Standard error stream: */
 static struct _mu_log_stream default_strerr = {
-  { ref_count: 1,
-    buftype: mu_buffer_none,
-    flags: MU_STREAM_WRITE,
-    destroy: bootstrap_destroy,
-    event_cb: std_log_bootstrap,
-    event_mask: _MU_STR_EVMASK (_MU_STR_EVENT_BOOTSTRAP)
+  .base = {
+    .ref_count = 1,
+    .buftype = mu_buffer_none,
+    .flags = MU_STREAM_WRITE,
+    .destroy = bootstrap_destroy,
+    .event_cb = std_log_bootstrap,
+    .event_mask = _MU_STR_EVMASK (_MU_STR_EVENT_BOOTSTRAP)
   }
 };
 
diff --git a/mh/pick.y b/mh/pick.y
index 6c88c2c..07ed147 100644
--- a/mh/pick.y
+++ b/mh/pick.y
@@ -21,7 +21,7 @@
 #include <pick.h>
   
 static node_t *pick_node_create (node_type type, void *a, void *b);
-static void set_cflags (char *str);
+static void set_cflags (char const *str);
  
 static regex_t *
 regex_dup (regex_t *re)
@@ -248,7 +248,7 @@ pick_add_token (mu_list_t *list, int tok, char const *val)
     }
   tp = mu_alloc (sizeof (*tp));
   tp->tok = tok;
-  tp->val = val;
+  tp->val = (char*) val;
   mu_list_append (*list, tp);
 }
 
@@ -410,7 +410,7 @@ pick_eval (mu_message_t msg)
 }
 
 void
-set_cflags (char *str)
+set_cflags (char const *str)
 {
   reg_flags = 0;
   for (; *str; str++)
diff --git a/mu-aux/mailutils.m4 b/mu-aux/mailutils.m4
index 53568f3..2b7146b 100644
--- a/mu-aux/mailutils.m4
+++ b/mu-aux/mailutils.m4
@@ -60,7 +60,6 @@ AC_DEFUN([AM_GNU_MAILUTILS],
   do
     case $x in
     mailer)   test $MAILUTILS_VERSION_NUMBER -ge 1200 && req="$req $x";;
-    cfg|argp) test $MAILUTILS_VERSION_NUMBER -ge 1290 && req="$req $x";;
     *)        req="$req $x"
     esac
   done
diff --git a/mu/filter.c b/mu/filter.c
index ea23979..291f8cf 100644
--- a/mu/filter.c
+++ b/mu/filter.c
@@ -20,7 +20,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <mailutils/mailutils.h>
-#include "argp.h"
 #include "mu.h"
 
 char filter_docstring[] = N_("apply a chain of filters to the input");
diff --git a/mu/imap.c b/mu/imap.c
index 3f64817..d19a2e3 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -29,7 +29,6 @@
 #include <mailutils/imaputil.h>
 #include <mailutils/msgset.h>
 #include "mu.h"
-#include "argp.h"
 
 char imap_docstring[] = N_("IMAP4 client shell");
 
diff --git a/mu/smtp.c b/mu/smtp.c
index bc6d292..4dbbd1f 100644
--- a/mu/smtp.c
+++ b/mu/smtp.c
@@ -25,7 +25,6 @@
 #include <mailutils/cctype.h>
 #include <mailutils/mailutils.h>
 #include <mailutils/smtp.h>
-#include <argp.h>
 #include "mu.h"
 
 char smtp_docstring[] = N_("run a SMTP session");
diff --git a/mu/template.c b/mu/template.c
index ed30632..0cce06e 100644
--- a/mu/template.c
+++ b/mu/template.c
@@ -32,50 +32,22 @@
 # include <config.h>
 #endif
 #include <mailutils/mailutils.h>
-#include "argp.h"
 #include "mu.h"
 
-#warning "Replace DESCRIPTION with a short description of this module."
-static char FOO_doc[] = N_("mu FOO - DESCRIPTION");
-
 #warning "Usually DESCRIPTION is the same text as the one used in FOO_doc."
 char FOO_docstring[] = N_("DESCRIPTION");
 
 #warning "Edit ARGDOC or remove this variable if module does not take arguments"
 static char FOO_args_doc[] = N_("ARGDOC");
 
-static struct argp_option FOO_options[] = {
+static struct mu_option FOO_options[] = {
   { NULL }
 };
 
-static error_t
-FOO_parse_opt (int key, char *arg, struct argp_state *state)
-{
-  switch (key)
-    {
-    default:
-      return ARGP_ERR_UNKNOWN;
-    }
-  return 0;
-}
-
-static struct argp FOO_argp = {
-  FOO_options,
-  FOO_parse_opt,
-  FOO_args_doc,
-  FOO_doc,
-  NULL,
-  NULL,
-  NULL
-};
-
 int
 mutool_FOO (int argc, char **argv)
 {
-  int index;
-  
-  if (argp_parse (&FOO_argp, argc, argv, ARGP_IN_ORDER, &index, NULL))
-    return 1;
+  mu_action_getopt (&argc, &argv, FOO_options, FOO_docstring, FOO_args_doc);
 #warning "Add the necessary functionality here"  
   return 0;
 }
diff --git a/readmsg/readmsg.c b/readmsg/readmsg.c
index a405452..a587ebb 100644
--- a/readmsg/readmsg.c
+++ b/readmsg/readmsg.c
@@ -91,7 +91,7 @@ struct mu_cli_setup cli = {
   NULL
 };
 
-static char *readmsg_argp_capa[] = {
+static char *readmsg_capa[] = {
   "debug",
   "mailbox",
   "locking",
@@ -244,7 +244,7 @@ main (int argc, char **argv)
 
   mu_auth_register_module (&mu_auth_tls_module);
 
-  mu_cli (argc, argv, &cli, readmsg_argp_capa, NULL, &argc, &argv);
+  mu_cli (argc, argv, &cli, readmsg_capa, NULL, &argc, &argv);
 
   if (argc == 0)
     {
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 8642fc0..7551f44 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -233,7 +233,7 @@ static struct mu_cfg_param sieve_cfg_param[] = {
 };
 
 
-static char *sieve_argp_capa[] = {
+static char *sieve_capa[] = {
   "debug",
   "mailbox",
   "locking",
@@ -400,7 +400,7 @@ main (int argc, char *argv[])
   
   mu_register_all_formats ();
 
-  mu_cli (argc, argv, &cli, sieve_argp_capa, NULL, &argc, &argv);
+  mu_cli (argc, argv, &cli, sieve_capa, NULL, &argc, &argv);
 
   if (argc == 0)
     {


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sat Oct 29 14:40:29 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1c0YYO-00083p-TE
	for mharc-commit-mailutils@gnu.org; Sat, 29 Oct 2016 14:40:28 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:40069)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0YYK-000821-EX
	for commit-mailutils@gnu.org; Sat, 29 Oct 2016 14:40:27 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0YYH-0001ld-Qn
	for commit-mailutils@gnu.org; Sat, 29 Oct 2016 14:40:24 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:40126)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0YYH-0001lJ-Mi
	for commit-mailutils@gnu.org; Sat, 29 Oct 2016 14:40:21 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 5128E2201D5; Sat, 29 Oct 2016 18:40:21 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-799-gca49675
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: 3a91a69baef99247b066e2c5ce4fce6bf739f1ac
X-Git-Newrev: ca4967534b748731eef2f050b7c832e2604a35b2
Message-Id: <20161029184021.5128E2201D5@vcs.savannah.gnu.org>
Date: Sat, 29 Oct 2016 18:40:21 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Sat, 29 Oct 2016 18:40:27 -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=ca4967534b748731eef2f050b7c832e2604a35b2

The branch, master has been updated
       via  ca4967534b748731eef2f050b7c832e2604a35b2 (commit)
      from  3a91a69baef99247b066e2c5ce4fce6bf739f1ac (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 ca4967534b748731eef2f050b7c832e2604a35b2
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 29 21:37:49 2016 +0300

    Minor changes

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

Summary of changes:
 doc/texinfo/libmu_auth.texi |   28 +++++++++++++++++-----------
 doc/texinfo/programs.texi   |    6 ------
 imap4d/imap4d.c             |   25 ++++++++++++++++---------
 libmailutils/cli/acl.c      |   11 ++++++-----
 libmailutils/cli/stdcapa.c  |    6 ++++--
 libmailutils/server/msrv.c  |   11 +++++++----
 libmu_auth/ldap.c           |    2 +-
 libmu_auth/radius.c         |    3 ++-
 libmu_auth/sql.c            |    8 +++++---
 libmu_sieve/conf.c          |   12 +++++++-----
 maidag/maidag.c             |   18 ++++++++++++------
 mimeview/mimeview.c         |    2 +-
 movemail/movemail.c         |    3 ++-
 pop3d/pop3d.c               |   18 ++++++++++++------
 sieve/sieve.c               |    6 ++++--
 15 files changed, 96 insertions(+), 63 deletions(-)

diff --git a/doc/texinfo/libmu_auth.texi b/doc/texinfo/libmu_auth.texi
index db8b452..0849f58 100644
--- a/doc/texinfo/libmu_auth.texi
+++ b/doc/texinfo/libmu_auth.texi
@@ -102,15 +102,23 @@ libmu_auth module. It is declared as follows:
 
 @smallexample
 @group
-struct mu_auth_module @{
-  char           *name;              /* Module name */
-  struct argp    *argp;              /* Corresponding argp structure */
-  mu_auth_fp     authenticate;       /* Authentication function ... */
-  void           *authenticate_data; /* ... and its specific data */
-  mu_auth_fp     auth_by_name;       /* Get user info by user name */ 
-  void           *auth_by_name_data; /* ... and its specific data */
-  mu_auth_fp     auth_by_uid;        /* Get user info by user id */  
-  void           *auth_by_uid_data;  /* ... and its specific data */
+struct mu_auth_module
+@{
+  /* Module name */
+  char            *name;            
+  /* Pointers to functions for each mode */
+  mu_auth_fp      handler[MU_AUTH_MODE_COUNT];
+  /* Corresponding data pointers */
+  void            *data[MU_AUTH_MODE_COUNT];
+
+  /* Describes command line options for that module */
+  struct mu_option *opt;
+  /* Configuration parameters for that module */
+  struct mu_cfg_param *cfg;
+  /* Configuration section parser */
+  mu_cfg_section_fp parser;
+  /* Function to commit the changes */
+  mu_cli_capa_commit_fp commit;
 @};
 @end group
 @end smallexample
@@ -271,8 +279,6 @@ main (int argc, char **argv)
   state = STATE_NONAUTH; /* Starting state in non-auth.  */
 
   MU_AUTH_REGISTER_ALL_MODULES ();
-  mu_argp_parse (&argp, &argc, &argv, 0, imap4d_capa,
-                 NULL, &daemon_param);
   @dots{}       
 @end group
 @end smallexample
diff --git a/doc/texinfo/programs.texi b/doc/texinfo/programs.texi
index cc00c97..a4edcf8 100644
--- a/doc/texinfo/programs.texi
+++ b/doc/texinfo/programs.texi
@@ -7435,18 +7435,12 @@ Enable support for mailers.
 Link in the support for Sieve mail filtering language.
 @item dbm
 Link in the support for DBM databases (libmu_dbm library).
-@item compat
-Provide a compatibility layer for Mailutils 2.x.
 @item auth
 Link in the Mailutils authentication library.
 @item guile
 Provide Guile language bindings.
 @item python
 Provide Python language bindings.
-@item cfg
-Link in the Mailutils configuration library.
-@item argp
-Link in the library for command line parsing.
 @end table
 
 @node mailutils query
diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c
index 2c97505..031c3cc 100644
--- a/imap4d/imap4d.c
+++ b/imap4d/imap4d.c
@@ -364,7 +364,9 @@ static struct mu_cfg_param imap4d_srv_param[] = {
 #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") },
+    N_("Kind of TLS encryption to use for this server"),
+    /* TRANSLATORS: translate only arg:, the rest are keywords */
+    N_("arg: false|true|ondemand|stls|requred|connection") },
 #endif
   { NULL }
 };
@@ -396,33 +398,38 @@ static struct mu_cfg_param imap4d_cfg_param[] = {
     N_("Set shared namespace.") },
   { "other-mailbox-mode", mu_cfg_callback, &mailbox_mode[NS_OTHER], 0,
     cb_mailbox_mode,
-    N_("File mode for mailboxes in other namespace.") },
+    N_("File mode for mailboxes in other namespace."),
+    N_("mode: g(+|=)[wr]+,o(+|=)[wr]+") },
   { "shared-mailbox-mode", mu_cfg_callback, &mailbox_mode[NS_SHARED], 0,
     cb_mailbox_mode,
-    N_("File mode for mailboxes in shared namespace.") },
+    N_("File mode for mailboxes in shared namespace."),
+    N_("mode: g(+|=)[wr]+,o(+|=)[wr]+") },
   { "login-disabled", mu_c_bool, &login_disabled, 0, NULL,
     N_("Disable LOGIN command.") },
   { "create-home-dir", mu_c_bool, &create_home_dir, 0, NULL,
     N_("If true, create non-existing user home directories.") },
   { "home-dir-mode", mu_cfg_callback, NULL, 0, cb_mode,
-    N_("File mode for creating user home directories (octal)."),
-    N_("mode") },
+    N_("File mode for creating user home directories."),
+    N_("mode: octal") },
   { "retain-groups", mu_cfg_callback, &user_retain_groups, 0, cb_group,
     N_("Retain these supplementary groups when switching to user privileges"),
     N_("groups: list of string") },
 #ifdef WITH_TLS
   { "tls", mu_cfg_callback, &tls_mode, 0, cb_tls,
-    N_("Kind of TLS encryption to use") },
+    N_("Kind of TLS encryption to use"),
+    /* TRANSLATORS: translate only arg:, the rest are keywords */
+    N_("arg: false|true|ondemand|stls|requred|connection") },
   { "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.") },
+       "Deprecated, use \"tls required\" instead."),
+    N_("arg: bool") },
 #endif
   { "preauth", mu_cfg_callback, NULL, 0, cb_preauth,
-    N_("Configure PREAUTH mode.  MODE is one of:\n"
+    N_("Configure PREAUTH mode.  <value> is one of:\n"
        "  prog:///<full-program-name: string>\n"
        "  ident[://:<port: string-or-number>]\n"
        "  stdio"),
-    N_("mode") },
+    N_("mode: value") },
   { "preauth-only", mu_c_bool, &preauth_only, 0, NULL,
     N_("Use only preauth mode.  If unable to setup it, disconnect "
        "immediately.") },
diff --git a/libmailutils/cli/acl.c b/libmailutils/cli/acl.c
index 778c3f5..df6ac72 100644
--- a/libmailutils/cli/acl.c
+++ b/libmailutils/cli/acl.c
@@ -221,15 +221,16 @@ static struct mu_cfg_param acl_param[] = {
     N_("addr: IP") },
   { "exec", mu_cfg_callback, NULL, 0, cb_exec,
     N_("Execute supplied program if a connection from this IP address is "
-       "requested. Arguments are:\n"
-       "  <addr: IP> <program: string>\n"
-       "Following macros are expanded in <program> before executing:\n"
+       "requested.\n\n"
+       "The following macros are expanded in <program> before executing:\n"
        "  address  -  Source IP address\n"
-       "  port     -  Source port number\n") },
+       "  port     -  Source port number\n"),
+    N_("addr: IP> <program: string") },
   { "ifexec", mu_cfg_callback, NULL, 0, cb_ifexec,
     N_("If a connection from this IP address is requested, execute supplied "
        "program and allow or deny the connection depending on its exit code. "
-       "See `exec' for a description of its arguments.") },
+       "See `exec' for a description of its arguments."),
+    N_("addr: IP> <program: string") },
   { NULL }
 };
 
diff --git a/libmailutils/cli/stdcapa.c b/libmailutils/cli/stdcapa.c
index 05a761f..8821609 100644
--- a/libmailutils/cli/stdcapa.c
+++ b/libmailutils/cli/stdcapa.c
@@ -79,12 +79,14 @@ static struct mu_cfg_param logging_cfg[] = {
   { "severity", mu_cfg_callback, NULL, 0, cb_severity,
     N_("Output only messages with a severity equal to or greater than "
        "this one."),
-    N_("arg: string")},
+    /* TRANSLATORS: Translate only arg:, rest are keywords */
+    N_("arg: debug|info|notice|warning|error|crit|alert|emerg")},
   { "facility", mu_cfg_callback, NULL, 0, cb_facility,
     N_("Set syslog facility. Arg is one of the following: user, daemon, "
        "auth, authpriv, mail, cron, local0 through local7 (case-insensitive), "
        "or a facility number."), 
-    N_("arg: string") },
+    /* TRANSLATORS: Translate only arg: and <number>, rest are keywords */
+    N_("arg: auth|authpriv|mail|local0-local7|<number>") },
   { "session-id", mu_c_bool, &mu_log_session_id, 0, NULL,
     N_("Log session ID") },
   { "tag", mu_c_string, &mu_log_tag, 0, NULL,
diff --git a/libmailutils/server/msrv.c b/libmailutils/server/msrv.c
index a60fd53..1048a5e 100644
--- a/libmailutils/server/msrv.c
+++ b/libmailutils/server/msrv.c
@@ -895,8 +895,9 @@ static struct mu_cfg_param dot_server_cfg_param[] = {
     N_("Maximum number of children processes to run simultaneously.") },
   { "mode", mu_cfg_callback,
     NULL, mu_offsetof (struct _mu_m_server,mode), _cb_daemon_mode,
-    N_("Set daemon mode (either inetd (or interactive) or daemon)."),
-    N_("mode") },
+    N_("Set operation mode."),
+    /* TRANSLATORS: Words to the right of : are keywords. */
+    N_("mode: inetd|interactive|daemom") },
   { "foreground", mu_c_bool,
     NULL, mu_offsetof (struct _mu_m_server, foreground), NULL,
     N_("Run in foreground.") },
@@ -906,7 +907,8 @@ static struct mu_cfg_param dot_server_cfg_param[] = {
     N_("file") },
   { "port", mu_cfg_callback,
     NULL, mu_offsetof (struct _mu_m_server, hints), _cb_port,
-    N_("Default port number.") },
+    N_("Default port number."),
+    N_("arg: port number or service name") },
   { "timeout", mu_c_time,
     NULL, mu_offsetof (struct _mu_m_server,timeout), NULL,
     N_("Set idle timeout.") },
@@ -953,7 +955,8 @@ _cb_backlog (void *data, mu_config_value_t *val)
 static struct mu_cfg_param server_tcp_param[] = {
   { "backlog", mu_cfg_callback,
     NULL, mu_offsetof (struct mu_srv_config, tcpsrv), _cb_backlog,
-    N_("Size of the queue of pending connections") },
+    N_("Size of the queue of pending connections"),
+    N_("number") },
   { NULL }
 };
 
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index c886e71..ac39558 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -106,7 +106,7 @@ static struct mu_cfg_param mu_ldap_param[] = {
        "where <name> is one of the following: name, passwd, uid, gid, "
        "gecos, dir, shell, mailbox, quota, and <attr> is the name of "
        "the corresponding LDAP attribute."),
-    N_("map") },
+    N_("map: definition") },
   { "getpwnam", mu_c_string, &ldap_param.getpwnam_filter, 0, NULL,
     N_("LDAP filter to use for getpwnam requests."),
     N_("filter") },
diff --git a/libmu_auth/radius.c b/libmu_auth/radius.c
index 4d6c380..1731a8b 100644
--- a/libmu_auth/radius.c
+++ b/libmu_auth/radius.c
@@ -191,7 +191,8 @@ static struct mu_cfg_param mu_radius_param[] = {
     N_("Radius request for getpwuid."),
     N_("request: string") },
   { "directory", mu_cfg_callback, NULL, 0, cb_config_dir,
-    N_("Set radius configuration directory.") },
+    N_("Set radius configuration directory."),
+    N_("dir: string") },
   { NULL }
 };
 
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index eeb3e3f..e40b710 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -103,6 +103,7 @@ static struct mu_cfg_param mu_sql_param[] = {
   { "interface", mu_cfg_callback, &mu_sql_module_config.interface, 0,
     cb_interface,
     N_("Set SQL interface to use."),
+    /* TRANSLATORS: Words to the right of : are keywords - do not translate */
     N_("iface: mysql|odbc|postgres") },
   { "getpwnam", mu_c_string, &mu_sql_module_config.getpwnam_query, 0, NULL,
     N_("SQL query to use for getpwnam requests."),
@@ -124,8 +125,9 @@ static struct mu_cfg_param mu_sql_param[] = {
   { "db", mu_c_string, &mu_sql_module_config.db, 0, NULL,
     N_("Database name.") },
   { "password-type", mu_cfg_callback, NULL, 0, cb_password_type,
-    N_("Type of password returned by getpass query (one of: plain, hash, "
-       "scrambled).") },
+    N_("Type of password returned by getpass query."),
+    /* TRANSLATORS: Words to the right of : are keywords - do not translate */
+    N_("arg: plain|hash|scrambled") },
   { "positional", mu_c_bool, &mu_sql_module_config.positional, 0, NULL,
     N_("Use positional (v1.0 compatible) field interface.") },
   { "field-map", mu_cfg_callback, NULL, 0, cb_field_map,
@@ -136,7 +138,7 @@ static struct mu_cfg_param mu_sql_param[] = {
        "where <name> is one of the following: name, passwd, uid, gid, "
        "gecos, dir, shell, mailbox, quota, and <column> is the name of "
        "the corresponding SQL column."),
-    N_("map") },
+    N_("map: definition") },
   { NULL }
 };
 
diff --git a/libmu_sieve/conf.c b/libmu_sieve/conf.c
index 7b9102f..82ec77e 100644
--- a/libmu_sieve/conf.c
+++ b/libmu_sieve/conf.c
@@ -142,21 +142,23 @@ cb_library_path_prefix (void *data, mu_config_value_t *val)
 
 static struct mu_cfg_param mu_sieve_param[] = {
   { "clear-library-path", mu_cfg_callback, NULL, 0, cb_clear_library_path,
-     N_("Clear library search path.") },
+     N_("Clear library search path."),
+     N_("arg: directory list") },
   { "clear-include-path", mu_cfg_callback, NULL, 0, cb_clear_include_path,
-     N_("Clear include search path.") },
+     N_("Clear include search path."),
+     N_("arg: directory list") },
   { "library-path", mu_cfg_callback, NULL, 0, cb_library_path,
     N_("Add directories to the library search path.  Argument is a "
        "colon-separated list of directories."),
-    N_("list") },
+    N_("arg: directory list") },
   { "library-path-prefix", mu_cfg_callback, NULL, 0, cb_library_path_prefix,
     N_("Add directories to the beginning of the library search path.  "
        "Argument is a colon-separated list of directories."),
-    N_("list") },
+    N_("arg: directory list") },
   { "include-path", mu_cfg_callback, NULL, 0, cb_include_path,
     N_("Add directories to the include search path.  Argument is a "
        "colon-separated list of directories."),
-    N_("list") },
+    N_("arg: directory list") },
   { NULL }
 };
 
diff --git a/maidag/maidag.c b/maidag/maidag.c
index 9b1c37e..ae041ba 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -372,9 +372,12 @@ cb_script_pattern (void *data, mu_config_value_t *val)
 
 struct mu_cfg_param filter_cfg_param[] = {
   { "language", mu_cfg_callback, NULL, 0, cb_script_language,
-    N_("Set script language.") },
+    N_("Set script language."),
+    /* TRANSLATORS: words to the right of : are keywords - do not translate */
+    N_("arg: python|guile") },
   { "pattern", mu_cfg_callback, NULL, 0, cb_script_pattern,
-    N_("Set script pattern.") },
+    N_("Set script pattern."), 
+    N_("arg: glob") },
   { NULL }
 };
 
@@ -419,7 +422,8 @@ cb_listen (void *data, mu_config_value_t *val)
 struct mu_cfg_param maidag_cfg_param[] = {
   { "delivery-mode", mu_cfg_callback, NULL, 0, cb_delivery_mode,
     N_("Set delivery mode"),
-    N_("mode: {mda | url | lmtp}") },
+    /* TRANSLATORS: words to the right of : are keywords - do not translate */
+    N_("mode: mda|url|lmtp") },
   { "exit-multiple-delivery-success", mu_c_bool, &multiple_delivery, 0, NULL,
     N_("In case of multiple delivery, exit with code 0 if at least one "
        "delivery succeeded.") },
@@ -447,9 +451,11 @@ struct mu_cfg_param maidag_cfg_param[] = {
        "  g - guile stack traces\n"
        "  t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n"
        "  i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)\n"
-       "  l - sieve action logs\n") },
+       "  l - sieve action logs\n"),
+    N_("arg: string") },
   { "stderr", mu_cfg_callback, NULL, 0, cb_stderr,
-    N_("Log to stderr instead of syslog.") },
+    N_("Log to stderr instead of syslog."),
+    N_("arg: bool") },
   { "forward-file", mu_c_string, &forward_file, 0, NULL,
     N_("Process forward file.") },
   { "forward-file-checks", mu_cfg_callback, NULL, 0, cb_forward_file_checks,
@@ -467,7 +473,7 @@ struct mu_cfg_param maidag_cfg_param[] = {
        "mandatory)\n"
        "   file://<socket-file-name>\n"
        "or socket://<socket-file-name>"),
-    N_("url") },
+    N_("url: string") },
   { "reuse-address", mu_c_bool, &reuse_lmtp_address, 0, NULL,
     N_("Reuse existing address (LMTP mode).  Default is \"yes\".") },
   { "filter", mu_cfg_section, NULL, 0, NULL,
diff --git a/mimeview/mimeview.c b/mimeview/mimeview.c
index 75ea9c7..c776579 100644
--- a/mimeview/mimeview.c
+++ b/mimeview/mimeview.c
@@ -130,7 +130,7 @@ cb_debug (void *data, mu_config_value_t *val)
 struct mu_cfg_param mimeview_cfg_param[] = {
   { "debug", mu_cfg_callback, NULL, 0, cb_debug,
     N_("Set debug verbosity level."),
-    N_("flags") },
+    N_("flags: string") },
   { "mimetypes", mu_c_string, &mimetypes_config, 0, NULL,
     N_("Use this mime.types file."),
     N_("file") },
diff --git a/movemail/movemail.c b/movemail/movemail.c
index 1352578..6935763 100644
--- a/movemail/movemail.c
+++ b/movemail/movemail.c
@@ -365,7 +365,8 @@ struct mu_cfg_param movemail_cfg_param[] = {
        " delete -  delete this one and to the next message\n"
        " count  -  count this message as processed\n"
        "Each keyword can be prefixed with \"no\" to reverse its meaning\n"
-       "Setting onerror=abort reverts to the default behavior.") },
+       "Setting onerror=abort reverts to the default behavior."),
+    N_("arg: list") },
   { NULL }
 };
 
diff --git a/pop3d/pop3d.c b/pop3d/pop3d.c
index adf1a5c..39e47fc 100644
--- a/pop3d/pop3d.c
+++ b/pop3d/pop3d.c
@@ -234,7 +234,9 @@ static struct mu_cfg_param pop3d_srv_param[] = {
 #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") },
+    N_("Kind of TLS encryption to use for this server"),
+    /* TRANSLATORS: words to the right of : are keywords - do not translate */
+    N_("arg: false|true|ondemand|stls|requred|connection") },
 #endif
   { NULL }
 };
@@ -252,7 +254,8 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
   { "apop-database-file", mu_c_string, &apop_database_name, 0, NULL,
     N_("set APOP database file name or URL") },
   { "apop-database-owner", mu_cfg_callback, NULL, 0, cb_apop_database_owner,
-    N_("Name or UID of the APOP database owner") },
+    N_("Name or UID of the APOP database owner"),
+    N_("arg: string") },
   { "apop-database-safety", mu_cfg_callback, NULL, 0, cb_apop_safety_checks,
     N_("Configure safety checks for APOP database files.  Argument is a list or "
        "sequence of check names optionally prefixed with '+' to enable or "
@@ -271,10 +274,13 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
     
 #ifdef WITH_TLS
   { "tls", mu_cfg_callback, &tls_mode, 0, cb_tls,
-    N_("Kind of TLS encryption to use") },
+    N_("Kind of TLS encryption to use"),
+    /* TRANSLATORS: words to the right of : are keywords - do not translate */
+    N_("arg: false|true|ondemand|stls|requred|connection") },
   { "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.") },
+       "Deprecated, use \"tls required\" instead."),
+    N_("arg: bool") },
 #endif
 #ifdef ENABLE_LOGIN_DELAY
   { "login-delay", mu_c_time, &login_delay, 0, NULL,
@@ -284,11 +290,11 @@ static struct mu_cfg_param pop3d_cfg_param[] = {
 #endif
   { "bulletin-source", mu_cfg_callback, NULL, 0, cb_bulletin_source,
     N_("Get bulletins from the specified mailbox."),
-    N_("url") },
+    N_("url: string") },
 #ifdef ENABLE_DBM
   { "bulletin-db", mu_cfg_callback, NULL, 0, cb_bulletin_db,
     N_("Set the bulletin database file name."),
-    N_("file") },
+    N_("file: string") },
 #endif
   { "output-buffer-size", mu_c_size, &pop3d_output_bufsize, 0, NULL,
     N_("Size of the output buffer.") },
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 7551f44..2b7fb9e 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -222,13 +222,15 @@ static struct mu_cfg_param sieve_cfg_param[] = {
        "   T - mailutils traces (sieve.trace9)\n"
        "   P - network protocols (sieve.prot)\n"
        "   t - sieve trace (MU_SIEVE_DEBUG_TRACE)\n"
-       "   i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR).") },
+       "   i - sieve instructions trace (MU_SIEVE_DEBUG_INSTR)."),
+    N_("arg: string") },
   { "verbose", mu_c_bool, &verbose, 0, NULL,
     N_("Log all executed actions.") },
   { "line-info", mu_c_bool, &sieve_print_locus, 0, NULL,
     N_("Print source locations along with action logs (default).") },
   { "email", mu_cfg_callback, NULL, 0, cb_email,
-    N_("Set user email address.") },
+    N_("Set user email address."),
+    N_("arg: string") },
   { NULL }
 };
 


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Sun Oct 30 04:58:00 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1c0lwF-0007GU-VV
	for mharc-commit-mailutils@gnu.org; Sun, 30 Oct 2016 04:58:00 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:53491)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0lwB-0007G3-UY
	for commit-mailutils@gnu.org; Sun, 30 Oct 2016 04:57:58 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0lw8-0008ES-Mp
	for commit-mailutils@gnu.org; Sun, 30 Oct 2016 04:57:56 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:47072)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c0lw8-0008EN-Hp
	for commit-mailutils@gnu.org; Sun, 30 Oct 2016 04:57:52 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 40885220176; Sun, 30 Oct 2016 08:57:52 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-801-gb54540c
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: ca4967534b748731eef2f050b7c832e2604a35b2
X-Git-Newrev: b54540cbbc95069b6d073246a575683170920275
Message-Id: <20161030085752.40885220176@vcs.savannah.gnu.org>
Date: Sun, 30 Oct 2016 08:57:52 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
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, 30 Oct 2016 08:57:58 -0000

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

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

The branch, master has been updated
       via  b54540cbbc95069b6d073246a575683170920275 (commit)
       via  c6848f52257191abb36b694be61ce333a8992b4b (commit)
      from  ca4967534b748731eef2f050b7c832e2604a35b2 (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 b54540cbbc95069b6d073246a575683170920275
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sun Oct 30 10:50:07 2016 +0200

    Improve opool API
    
    * configure.ac: Version 2.99.993
    * NEWS: Update.
    
    * include/mailutils/opool.h (MU_OPOOL_DEFAULT)
    (MU_OPOOL_ENOMEMABRT): New defines.
    (mu_opool_create): Change meaning of the 2nd argument. All uses updated.
    (mu_opool_free, mu_opool_dup): New proto.
    * libmailutils/base/opool.c (_mu_opool) <memerr>: Replace with flags.
    <head,tail,free>: Rename.
    (mu_opool_free, mu_opool_dup): New functions.
    (mu_opool_head): Bugfix.

commit c6848f52257191abb36b694be61ce333a8992b4b
Author: Sergey Poznyakoff <gray@gnu.org>
Date:   Sat Oct 29 23:23:11 2016 +0300

    Remove old compatibility quirks

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

Summary of changes:
 NEWS                        |    4 +-
 comsat/action.c             |    2 +-
 configure.ac                |    2 +-
 include/mailutils/opool.h   |   18 +++--
 lib/mailcap.c               |    2 +-
 libmailutils/base/opool.c   |  166 +++++++++++++++++++++++++++----------------
 libmailutils/cfg/lexer.l    |    2 +-
 libmailutils/cfg/parser.y   |    2 +-
 libmailutils/url/urlstr.c   |    2 +-
 libproto/mailer/Makefile.am |    4 +-
 libproto/mailer/remote.c    |  159 -----------------------------------------
 libproto/mailer/smtp.c      |    1 -
 libproto/pop/mbox.c         |    2 +-
 maidag/maidag.c             |    7 --
 mh/burst.c                  |    2 +-
 mh/mh_fmtgram.y             |    2 +-
 mh/mh_format.c              |    2 +-
 mh/mhn.c                    |   10 +--
 mh/prompter.c               |    2 +-
 mh/repl.c                   |    2 +-
 mh/whatnowenv.c             |    2 +-
 mimeview/mimetypes.l        |    2 +-
 mu/dbm.c                    |    2 +-
 23 files changed, 141 insertions(+), 258 deletions(-)
 delete mode 100644 libproto/mailer/remote.c

diff --git a/NEWS b/NEWS
index 40768fa..4aa8610 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,11 @@
-GNU mailutils NEWS -- history of user-visible changes. 2016-10-28
+GNU mailutils NEWS -- history of user-visible changes. 2016-10-30
 Copyright (C) 2002-2016 Free Software Foundation, Inc.
 See the end of file for copying conditions.
 
 Please send mailutils bug reports to <bug-mailutils@gnu.org>.
 
 
-Version 2.99.992 (Git)
+Version 2.99.993 (Git)
 
 This version is a major rewrite of GNU Mailutils.  Quite a few parts
 of the basic framework were rewritten from scratch, while some others
diff --git a/comsat/action.c b/comsat/action.c
index 0582637..dc57032 100644
--- a/comsat/action.c
+++ b/comsat/action.c
@@ -144,7 +144,7 @@ expand_line (const char *str, mu_message_t msg)
 
   if (!*str)
     return NULL;
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
   for (p = str; *p; p++)
     {
       switch (*p)
diff --git a/configure.ac b/configure.ac
index b8161ec..92ac4a1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ dnl You should have received a copy of the GNU General Public License along
 dnl with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
 
 AC_PREREQ(2.63)
-AC_INIT([GNU Mailutils], [2.99.992], [bug-mailutils@gnu.org], [mailutils],
+AC_INIT([GNU Mailutils], [2.99.993], [bug-mailutils@gnu.org], [mailutils],
         [http://mailutils.org])
 AC_CONFIG_SRCDIR([libmailutils/mailbox/mailbox.c])
 AC_CONFIG_AUX_DIR([build-aux])
diff --git a/include/mailutils/opool.h b/include/mailutils/opool.h
index bc68e4a..63c5a38 100644
--- a/include/mailutils/opool.h
+++ b/include/mailutils/opool.h
@@ -24,10 +24,12 @@
 # define MU_OPOOL_BUCKET_SIZE 1024
 #endif
 
-/* Create an object pool.  If MEMERR is not 0, any operation of the
-   resulting pool (including mu_opool_create itself) will abort on
-   not enough memory condition, using mu_alloc_die. */
-int mu_opool_create (mu_opool_t *pret, int memerr);
+/* Flags for mu_opool_create call: */
+#define MU_OPOOL_DEFAULT 0
+#define MU_OPOOL_ENOMEMABRT 0x01 /* Abort on ENOMEM error */
+
+/* Create an object pool.  */
+int mu_opool_create (mu_opool_t *pret, int flags);
 int mu_opool_set_bucket_size (mu_opool_t opool, size_t size);
 int mu_opool_get_bucket_size (mu_opool_t opool, size_t *psize);
 
@@ -39,6 +41,10 @@ int mu_opool_union (mu_opool_t *dst, mu_opool_t *src);
    begin a new object. */
 void mu_opool_clear (mu_opool_t opool);
 
+/* Free object OBJ from the pool.  If OBJ is NULL, free all created objects,
+   including the one being built */
+void mu_opool_free (mu_opool_t pool, void *obj);
+
 /* Destroy the pool, reclaim any memory associated with it. */
 void mu_opool_destroy (mu_opool_t *popool);
 
@@ -80,6 +86,10 @@ void *mu_opool_head (mu_opool_t opool, size_t *psize);
    return p; */
 void *mu_opool_finish (mu_opool_t opool, size_t *psize);
 
+/* Append SIZE bytes from DATA to the pool and return the pointer to the
+   created object. */
+void *mu_opool_dup (mu_opool_t pool, void const *data, size_t size);
+
 int mu_opool_get_iterator (mu_opool_t opool, mu_iterator_t *piterator);
 
 #endif
diff --git a/lib/mailcap.c b/lib/mailcap.c
index 02f1894..503390c 100644
--- a/lib/mailcap.c
+++ b/lib/mailcap.c
@@ -686,7 +686,7 @@ display_stream_mailcap (const char *ident, mu_stream_t stream, mu_header_t hdr,
       mailcap_path = mailcap_path_tmp;
     }
   
-  mu_opool_create (&expand_pool, 1);
+  mu_opool_create (&expand_pool, MU_OPOOL_ENOMEMABRT);
 
   ws.ws_delim = ":";
   if (mu_wordsplit (mailcap_path, &ws,
diff --git a/libmailutils/base/opool.c b/libmailutils/base/opool.c
index 77257f2..5e19081 100644
--- a/libmailutils/base/opool.c
+++ b/libmailutils/base/opool.c
@@ -41,11 +41,11 @@ struct mu_opool_bucket
 
 struct _mu_opool
 {
-  int memerr;
-  size_t bucket_size;
-  size_t itr_count;
-  struct mu_opool_bucket *head, *tail;
-  struct mu_opool_bucket *free;
+  int flags;                   /* Flag bits */
+  size_t bucket_size;          /* Default bucket size */
+  size_t itr_count;            /* Number of iterators created for this pool */
+  struct mu_opool_bucket *bkt_head, *bkt_tail; 
+  struct mu_opool_bucket *bkt_fini; /* List of finished objects */
 };
 
 static struct mu_opool_bucket *
@@ -54,7 +54,7 @@ alloc_bucket (struct _mu_opool *opool, size_t size)
   struct mu_opool_bucket *p = malloc (sizeof (*p) + size);
   if (!p)
     {
-      if (opool->memerr)
+      if (opool->flags & MU_OPOOL_ENOMEMABRT)
 	mu_alloc_die ();
     }
   else
@@ -73,11 +73,11 @@ alloc_pool (mu_opool_t opool, size_t size)
   struct mu_opool_bucket *p = alloc_bucket (opool, opool->bucket_size);
   if (!p)
     return ENOMEM;
-  if (opool->tail)
-    opool->tail->next = p;
+  if (opool->bkt_tail)
+    opool->bkt_tail->next = p;
   else
-    opool->head = p;
-  opool->tail = p;
+    opool->bkt_head = p;
+  opool->bkt_tail = p;
   return 0;
 }
 
@@ -86,32 +86,32 @@ copy_chars (mu_opool_t opool, const char *str, size_t n, size_t *psize)
 {
   size_t rest;
 
-  if (!opool->head || opool->tail->level == opool->tail->size)
+  if (!opool->bkt_head || opool->bkt_tail->level == opool->bkt_tail->size)
     if (alloc_pool (opool, opool->bucket_size))
       return ENOMEM;
-  rest = opool->tail->size - opool->tail->level;
+  rest = opool->bkt_tail->size - opool->bkt_tail->level;
   if (n > rest)
     n = rest;
-  memcpy (opool->tail->buf + opool->tail->level, str, n);
-  opool->tail->level += n;
+  memcpy (opool->bkt_tail->buf + opool->bkt_tail->level, str, n);
+  opool->bkt_tail->level += n;
   *psize = n;
   return 0;
 }
 
 int
-mu_opool_create (mu_opool_t *pret, int memerr)
+mu_opool_create (mu_opool_t *pret, int flags)
 {
   struct _mu_opool *x = malloc (sizeof (x[0]));
   if (!x)
     {
-      if (memerr)
+      if (flags & MU_OPOOL_ENOMEMABRT)
 	mu_alloc_die ();
       return ENOMEM;
     }
-  x->memerr = memerr;
+  x->flags = flags;
   x->bucket_size = MU_OPOOL_BUCKET_SIZE;
   x->itr_count = 0;
-  x->head = x->tail = x->free = 0;
+  x->bkt_head = x->bkt_tail = x->bkt_fini = NULL;
   *pret = x;
   return 0;
 }
@@ -140,11 +140,11 @@ mu_opool_clear (mu_opool_t opool)
   if (!opool)
     return;
   
-  if (opool->tail)
+  if (opool->bkt_tail)
     {
-      opool->tail->next = opool->free;
-      opool->free = opool->head;
-      opool->head = opool->tail = NULL;
+      opool->bkt_tail->next = opool->bkt_fini;
+      opool->bkt_fini = opool->bkt_head;
+      opool->bkt_head = opool->bkt_tail = NULL;
     }
 }	
 
@@ -156,15 +156,15 @@ mu_opool_destroy (mu_opool_t *popool)
     {
       mu_opool_t opool = *popool;
       mu_opool_clear (opool);
-      for (p = opool->free; p; )
+      for (p = opool->bkt_fini; p; )
 	{
 	  struct mu_opool_bucket *next = p->next;
 	  free (p);
 	  p = next;
 	}
       free (opool);
+      *popool = NULL;
     }
-  *popool = NULL;
 }
 
 int
@@ -174,13 +174,13 @@ mu_opool_alloc (mu_opool_t opool, size_t size)
     {
       size_t rest;
 
-      if (!opool->head || opool->tail->level == opool->tail->size)
+      if (!opool->bkt_head || opool->bkt_tail->level == opool->bkt_tail->size)
 	if (alloc_pool (opool, opool->bucket_size))
 	  return ENOMEM;
-      rest = opool->tail->size - opool->tail->level;
+      rest = opool->bkt_tail->size - opool->bkt_tail->level;
       if (size < rest)
 	rest = size;
-      opool->tail->level += rest;
+      opool->bkt_tail->level += rest;
       size -= rest;
     }
   return 0;
@@ -218,7 +218,7 @@ mu_opool_size (mu_opool_t opool)
 {
   size_t size = 0;
   struct mu_opool_bucket *p;
-  for (p = opool->head; p; p = p->next)
+  for (p = opool->bkt_head; p; p = p->next)
     size += p->level;
   return size;
 }
@@ -230,7 +230,7 @@ mu_opool_copy (mu_opool_t opool, void *buf, size_t size)
   size_t total = 0;
   struct mu_opool_bucket *p;
   
-  for (p = opool->head; p && total < size; p = p->next)
+  for (p = opool->bkt_head; p && total < size; p = p->next)
     {
       size_t cpsize = size - total;
       if (cpsize > p->level)
@@ -249,27 +249,28 @@ mu_opool_coalesce (mu_opool_t opool, size_t *psize)
 
   if (opool->itr_count)
     return MU_ERR_FAILURE;
-  if (opool->head && opool->head->next == NULL)
-    size = opool->head->level;
-  else {
-    struct mu_opool_bucket *bucket;
-    struct mu_opool_bucket *p;
+  if (opool->bkt_head && opool->bkt_head->next == NULL)
+    size = opool->bkt_head->level;
+  else
+    {
+      struct mu_opool_bucket *bucket;
+      struct mu_opool_bucket *p;
 
-    size = mu_opool_size (opool);
+      size = mu_opool_size (opool);
 	
-    bucket = alloc_bucket (opool, size);
-    if (!bucket)
-      return ENOMEM;
-    for (p = opool->head; p; )
-      {
-	struct mu_opool_bucket *next = p->next;
-	memcpy (bucket->buf + bucket->level, p->buf, p->level);
-	bucket->level += p->level;
-	free (p);
-	p = next;
-      }
-    opool->head = opool->tail = bucket;
-  }
+      bucket = alloc_bucket (opool, size);
+      if (!bucket)
+	return ENOMEM;
+      for (p = opool->bkt_head; p; )
+	{
+	  struct mu_opool_bucket *next = p->next;
+	  memcpy (bucket->buf + bucket->level, p->buf, p->level);
+	  bucket->level += p->level;
+	  free (p);
+	  p = next;
+	}
+      opool->bkt_head = opool->bkt_tail = bucket;
+    }
   if (psize)
     *psize = size;
   return 0;
@@ -278,9 +279,9 @@ mu_opool_coalesce (mu_opool_t opool, size_t *psize)
 void *
 mu_opool_head (mu_opool_t opool, size_t *psize)
 {
-  if (*psize) 
-    *psize = opool->head ? opool->head->level : 0;
-  return opool->head ? opool->head->buf : NULL;
+  if (psize) 
+    *psize = opool->bkt_head ? opool->bkt_head->level : 0;
+  return opool->bkt_head ? opool->bkt_head->buf : NULL;
 }
 
 void *
@@ -289,7 +290,48 @@ mu_opool_finish (mu_opool_t opool, size_t *psize)
   if (mu_opool_coalesce (opool, psize))
     return NULL;
   mu_opool_clear (opool);
-  return opool->free->buf;
+  return opool->bkt_fini->buf;
+}
+
+void
+mu_opool_free (mu_opool_t pool, void *obj)
+{
+  if (!pool)
+    return;
+  if (!obj)
+    {
+      if (pool->bkt_head)
+	mu_opool_finish (pool, NULL);
+      while (pool->bkt_fini)
+	{
+	  struct mu_opool_bucket *next = pool->bkt_fini->next;
+	  free (pool->bkt_fini);
+	  pool->bkt_fini = next;
+	}
+    }
+  else
+    {
+      struct mu_opool_bucket *bucket = pool->bkt_fini, **pprev = &pool->bkt_fini;
+      while (bucket)
+	{
+	  if (bucket->buf == obj)
+	    {
+	      *pprev = bucket->next;
+	      free (bucket);
+	      return;
+	    }
+	  pprev = &bucket->next;
+	  bucket = bucket->next;
+	}
+    }
+}
+
+void *
+mu_opool_dup (mu_opool_t pool, void const *data, size_t size)
+{
+  if (mu_opool_append (pool, data, size))
+    return NULL;
+  return mu_opool_finish (pool, NULL);
 }
 
 int
@@ -314,20 +356,20 @@ mu_opool_union (mu_opool_t *pdst, mu_opool_t *psrc)
   else
     dst = *pdst;
 
-  if (dst->tail)
-    dst->tail->next = src->head;
+  if (dst->bkt_tail)
+    dst->bkt_tail->next = src->bkt_head;
   else
-    dst->head = src->head;
-  dst->tail = src->tail;
+    dst->bkt_head = src->bkt_head;
+  dst->bkt_tail = src->bkt_tail;
 
-  if (src->free)
+  if (src->bkt_fini)
     {
       struct mu_opool_bucket *p;
 
-      for (p = src->free; p->next; p = p->next)
+      for (p = src->bkt_fini; p->next; p = p->next)
 	;
-      p->next = dst->free;
-      dst->free = src->free;
+      p->next = dst->bkt_fini;
+      dst->bkt_fini = src->bkt_fini;
     }
 
   free (src);
@@ -347,7 +389,7 @@ static int
 opitr_first (void *owner)
 {
   struct opool_iterator *itr = owner;
-  itr->cur = itr->opool->head;
+  itr->cur = itr->opool->bkt_head;
   return 0;
 }
 
@@ -434,7 +476,7 @@ mu_opool_get_iterator (mu_opool_t opool, mu_iterator_t *piterator)
   if (!itr)
     return ENOMEM;
   itr->opool = opool;
-  itr->cur = opool->head;
+  itr->cur = opool->bkt_head;
   
   status = mu_iterator_create (&iterator, itr);
   if (status)
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
index b6c49ec..2ecefce 100644
--- a/libmailutils/cfg/lexer.l
+++ b/libmailutils/cfg/lexer.l
@@ -200,7 +200,7 @@ void
 _mu_line_begin ()
 {
   if (!pool)
-    mu_opool_create (&pool, 1);
+    mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
   else
     mu_opool_clear (pool);
 }
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index a530f10..9ad8e8d 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -1110,7 +1110,7 @@ mu_cfg_tree_create (struct mu_cfg_tree **ptree)
   struct mu_cfg_tree *tree = calloc (1, sizeof *tree);
   if (!tree)
     return errno;
-  mu_opool_create (&tree->pool, 1);
+  mu_opool_create (&tree->pool, MU_OPOOL_ENOMEMABRT);
   *ptree = tree;
   return 0;
 }
diff --git a/libmailutils/url/urlstr.c b/libmailutils/url/urlstr.c
index c57576a..34c69f3 100644
--- a/libmailutils/url/urlstr.c
+++ b/libmailutils/url/urlstr.c
@@ -111,7 +111,7 @@ mu_url_sget_name (const mu_url_t url, const char **retptr)
       char *ptr, *newname;
       size_t size;
       
-      rc = mu_opool_create (&pool, 0);
+      rc = mu_opool_create (&pool, MU_OPOOL_DEFAULT);
       if (rc)
 	return rc;
       rc = url_reconstruct_to_pool (url, pool);
diff --git a/libproto/mailer/Makefile.am b/libproto/mailer/Makefile.am
index 813b63e..1c195eb 100644
--- a/libproto/mailer/Makefile.am
+++ b/libproto/mailer/Makefile.am
@@ -53,6 +53,4 @@ libmu_mailer_la_SOURCES = \
  smtp_send.c\
  smtp_starttls.c\
  smtp_trace.c\
- smtp_url.c\
- remote.c
-
+ smtp_url.c
diff --git a/libproto/mailer/remote.c b/libproto/mailer/remote.c
deleted file mode 100644
index c33f9ee..0000000
--- a/libproto/mailer/remote.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2009-2012, 2014-2016 Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not,
-   see <http://www.gnu.org/licenses/>. */
-
-/* This file provides backward-compatible "remote+" mailbox types,
-   introduced in v. 2.0.
-
-   They are only used by maidag.
-
-   This file will be removed in v. 2.2
-*/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <mailutils/errno.h>
-#include <mailutils/error.h>
-#include <mailutils/diag.h>
-
-#include <mailutils/sys/url.h>
-#include <mailutils/sys/mailer.h>
-#include <mailutils/sys/registrar.h>
-
-#ifdef ENABLE_SMTP
-
-static int
-_url_remote_init (mu_url_t url, const char *new_scheme)
-{
-  char *scheme;
-  mu_record_t record;
-  int rc;
-  
-  mu_diag_output (MU_DIAG_WARNING,
-		  "%s: this URL scheme is deprecated, use %s instead",
-		  url->name, new_scheme);
-
-  rc = mu_registrar_lookup_scheme (new_scheme, &record);
-  if (rc)
-    return rc;
-
-  scheme = strdup (new_scheme);
-  if (!scheme)
-    return ENOMEM;
-  
-  free (url->scheme);
-  url->scheme = scheme;
-  
-  return record->_url ? record->_url (url) : 0;
-}
-
-
-static int
-_url_remote_smtp_init (mu_url_t url)
-{
-  return _url_remote_init (url, "smtp");
-}
-
-static struct _mu_record _mu_remote_smtp_record = {
-  MU_SMTP_PRIO,
-  "remote+smtp",
-  MU_RECORD_DEFAULT,
-  MU_URL_SCHEME | MU_URL_CRED | MU_URL_INET | MU_URL_PATH | MU_URL_PARAM,
-  MU_URL_HOST,
-  _url_remote_smtp_init,	/* url init.  */
-  _mu_mailer_mailbox_init,      /* Mailbox init.  */
-  NULL,		                /* Mailer init.  */
-  _mu_mailer_folder_init,	/* Folder init.  */
-  NULL,				/* No need for a back pointer.  */
-  NULL,				/* _is_scheme method.  */
-  NULL,				/* _get_url method.  */
-  NULL,				/* _get_mailbox method.  */
-  NULL,				/* _get_mailer method.  */
-  NULL				/* _get_folder method.  */
-};
-
-mu_record_t mu_remote_smtp_record = &_mu_remote_smtp_record;
-#else
-mu_record_t mu_remote_smtp_record = NULL;
-#endif
-
-
-#ifdef ENABLE_SENDMAIL
-static int
-_url_remote_sendmail_init (mu_url_t url)
-{
-  return _url_remote_init (url, "sendmail");
-}
-
-static struct _mu_record _mu_remote_sendmail_record =
-{
-  MU_SENDMAIL_PRIO,
-  "remote+sendmail",
-  MU_RECORD_DEFAULT,
-  MU_URL_SCHEME | MU_URL_PATH,
-  MU_URL_PATH,
-  _url_remote_sendmail_init,    /* url init.  */
-  _mu_mailer_mailbox_init,      /* Mailbox entry.  */
-  _mu_mailer_sendmail_init, /* Mailer entry.  */
-  _mu_mailer_folder_init, /* Folder entry.  */
-  NULL, /* No need for a back pointer.  */
-  NULL, /* _is_scheme method.  */
-  NULL, /* _get_url method.  */
-  NULL, /* _get_mailbox method.  */
-  NULL, /* _get_mailer method.  */
-  NULL  /* _get_folder method.  */
-};
-
-
-mu_record_t mu_remote_sendmail_record = &_mu_remote_sendmail_record;
-
-
-static int
-_url_remote_prog_init (mu_url_t url)
-{
-  return _url_remote_init (url, "prog");
-}
-
-static struct _mu_record _mu_remote_prog_record =
-{
-  MU_PROG_PRIO,
-  "remote+prog",
-  MU_RECORD_DEFAULT,
-  MU_URL_SCHEME | MU_URL_CRED | MU_URL_PATH | MU_URL_QUERY,
-  MU_URL_PATH,
-  _url_remote_prog_init,    /* url init.  */
-  _mu_mailer_mailbox_init,  /* Mailbox entry.  */
-  _mu_mailer_prog_init, /* Mailer entry.  */
-  _mu_mailer_folder_init, /* Folder entry.  */
-  NULL, /* No need for a back pointer.  */
-  NULL, /* _is_scheme method.  */
-  NULL, /* _get_url method.  */
-  NULL, /* _get_mailbox method.  */
-  NULL, /* _get_mailer method.  */
-  NULL  /* _get_folder method.  */
-};
-
-mu_record_t mu_remote_prog_record = &_mu_remote_prog_record;
-
-#else
-mu_record_t mu_remote_sendmail_record = NULL;
-mu_record_t mu_remote_prog_record = NULL;
-#endif
diff --git a/libproto/mailer/smtp.c b/libproto/mailer/smtp.c
index 6e97b80..2bf9a76 100644
--- a/libproto/mailer/smtp.c
+++ b/libproto/mailer/smtp.c
@@ -602,5 +602,4 @@ _mailer_smtp_init (mu_mailer_t mailer)
 #include <stdio.h>
 #include <mailutils/sys/registrar.h>
 mu_record_t     mu_smtp_record = NULL;
-mu_record_t     mu_remote_smtp_record = NULL;
 #endif
diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c
index 64e375a..b877b6f 100644
--- a/libproto/pop/mbox.c
+++ b/libproto/pop/mbox.c
@@ -654,7 +654,7 @@ pop_header_blurb (mu_stream_t stream, size_t maxlines,
   size_t n;
   size_t nlines = 0;
   
-  status = mu_opool_create (&opool, 0);
+  status = mu_opool_create (&opool, MU_OPOOL_DEFAULT);
   if (status)
     return status;
       
diff --git a/maidag/maidag.c b/maidag/maidag.c
index ae041ba..9e23c29 100644
--- a/maidag/maidag.c
+++ b/maidag/maidag.c
@@ -508,13 +508,6 @@ struct mu_cli_setup cli = {
   l - sieve action logs\n\
   0-9 - Set maidag debugging level\n")
 };
-
-/* FIXME: These are for compatibility with MU 2.0.
-   Remove in 2.2 */
-extern mu_record_t mu_remote_smtp_record;
-extern mu_record_t mu_remote_sendmail_record;
-extern mu_record_t mu_remote_prog_record;
-
 
 int
 main (int argc, char *argv[])
diff --git a/mh/burst.c b/mh/burst.c
index 173a8f7..4d5a3b7 100644
--- a/mh/burst.c
+++ b/mh/burst.c
@@ -678,7 +678,7 @@ main (int argc, char **argv)
 	  mu_attribute_set_deleted (attr);
 	}
       mu_mailbox_expunge (tmpbox);
-      mu_opool_create (&pool, 1);
+      mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
     }
   else
     tmpbox = mbox;
diff --git a/mh/mh_fmtgram.y b/mh/mh_fmtgram.y
index 018bdce..9b690b7 100644
--- a/mh/mh_fmtgram.y
+++ b/mh/mh_fmtgram.y
@@ -499,7 +499,7 @@ mh_format_parse (char *format_str, mh_format_t *fmt)
   if (p)
     yydebug = 1;
   start = curp = format_str;
-  mu_opool_create (&tokpool, 1);
+  mu_opool_create (&tokpool, MU_OPOOL_ENOMEMABRT);
   format.prog = NULL;
   format.progsize = 0;
   pc = 0;
diff --git a/mh/mh_format.c b/mh/mh_format.c
index 77e4e85..c74a260 100644
--- a/mh/mh_format.c
+++ b/mh/mh_format.c
@@ -490,7 +490,7 @@ mh_format (mh_format_t *fmt, mu_message_t msg, size_t msgno,
   
   mach.width = width - 1; /* Count the newline */
   mach.pc = 1;
-  mu_opool_create (&mach.pool, 1);
+  mu_opool_create (&mach.pool, MU_OPOOL_ENOMEMABRT);
   mu_list_create (&mach.addrlist);
   
   reset_fmt_defaults (&mach);
diff --git a/mh/mhn.c b/mh/mhn.c
index b3c2cb7..2ebd8c3 100644
--- a/mh/mhn.c
+++ b/mh/mhn.c
@@ -461,7 +461,7 @@ mhn_compose_command (char *typestr, char *typeargs, int *flags, char *file)
     %F  %f, and stdout is not redirected
     %s  subtype */
 
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
 
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   
@@ -642,7 +642,7 @@ mhn_show_command (mu_message_t msg, msg_part_t part, int *flags,
     %s  subtype
     %d  content description */
 
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
 
   p = mu_str_skip_class (str, MU_CTYPE_SPACE);
   
@@ -814,7 +814,7 @@ mhn_store_command (mu_message_t msg, msg_part_t part, const char *name,
      %p  part
      %s  subtype */
 
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
   
   for (p = str; *p; p++)
     {
@@ -1883,7 +1883,7 @@ parse_type_command (char **pcmd, struct compose_env *env, mu_header_t hdr)
       return 1;
     }
 
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
 
   mu_opool_appendz (pool, type);
   mu_opool_append_char (pool, '/');
@@ -2050,7 +2050,7 @@ edit_extern (char *cmd, struct compose_env *env, mu_message_t *msg, int level)
 
   mu_message_get_header (*msg, &hdr);
 
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
   mu_opool_append (pool, EXTCONTENT, sizeof (EXTCONTENT) - 1);
   *--rest = ';'; /* FIXME */
   rc = parse_content_type (env, pool, &rest, &id, NULL);
diff --git a/mh/prompter.c b/mh/prompter.c
index 5c4405f..2efde12 100644
--- a/mh/prompter.c
+++ b/mh/prompter.c
@@ -156,7 +156,7 @@ main (int argc, char **argv)
 	  mu_opool_t opool;
 	  const char *prompt = name;
 	  
-	  mu_opool_create (&opool, 1);
+	  mu_opool_create (&opool, MU_OPOOL_ENOMEMABRT);
 	  do
 	    {
 	      size_t len;
diff --git a/mh/repl.c b/mh/repl.c
index 13fa8c9..fefa6a2 100644
--- a/mh/repl.c
+++ b/mh/repl.c
@@ -73,7 +73,7 @@ set_fcc (struct mu_parseopt *po, struct mu_option *opt, char const *arg)
 {
   if (!has_fcc)
     {
-      mu_opool_create (&fcc_pool, 1);
+      mu_opool_create (&fcc_pool, MU_OPOOL_ENOMEMABRT);
       has_fcc = 1;
     }
   else
diff --git a/mh/whatnowenv.c b/mh/whatnowenv.c
index f4af156..81b9368 100644
--- a/mh/whatnowenv.c
+++ b/mh/whatnowenv.c
@@ -84,7 +84,7 @@ mh_whatnow_env_to_environ (struct mh_whatnow_env *wh)
       int mrange = 0;
       const char *s;
       
-      mu_opool_create (&opool, 1);
+      mu_opool_create (&opool, MU_OPOOL_ENOMEMABRT);
       mu_list_get_iterator (wh->anno_list, &itr);
       for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
 	   mu_iterator_next (itr))
diff --git a/mimeview/mimetypes.l b/mimeview/mimetypes.l
index 995b8de..9cdbf9d 100644
--- a/mimeview/mimetypes.l
+++ b/mimeview/mimetypes.l
@@ -172,7 +172,7 @@ mimetypes_open (const char *name)
       return -1;
     }
   line_num = 1;
-  mu_opool_create (&pool, 1);
+  mu_opool_create (&pool, MU_OPOOL_ENOMEMABRT);
   return 0;
 }
 
diff --git a/mu/dbm.c b/mu/dbm.c
index 531a3cf..0722456 100644
--- a/mu/dbm.c
+++ b/mu/dbm.c
@@ -610,7 +610,7 @@ newfmt_init (struct xfer_format *fmt, const char *version,
   else
     {
       mu_opool_t pool;
-      rc = mu_opool_create (&pool, 0);
+      rc = mu_opool_create (&pool, MU_OPOOL_DEFAULT);
       if (rc)
 	{
 	  mu_diag_funcall (MU_DIAG_ERROR, "mu_opool_create",


hooks/post-receive
-- 
GNU Mailutils


From MAILER-DAEMON Mon Oct 31 12:30:15 2016
Received: from list by lists.gnu.org with archive (Exim 4.71)
	id 1c1FTT-0003Al-KX
	for mharc-commit-mailutils@gnu.org; Mon, 31 Oct 2016 12:30:15 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:43080)
	by lists.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c1FTR-00038a-3C
	for commit-mailutils@gnu.org; Mon, 31 Oct 2016 12:30:14 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c1FTQ-000478-3g
	for commit-mailutils@gnu.org; Mon, 31 Oct 2016 12:30:13 -0400
Received: from vcs.savannah.gnu.org ([208.118.235.72]:33743)
	by eggs.gnu.org with esmtp (Exim 4.71)
	(envelope-from <INVALID.NOREPLY@gnu.org>) id 1c1FTQ-00046w-0W
	for commit-mailutils@gnu.org; Mon, 31 Oct 2016 12:30:12 -0400
Received: by vcs.savannah.gnu.org (Postfix, from userid 65697)
	id 9ECAD22017C; Mon, 31 Oct 2016 16:30:11 +0000 (UTC)
From: "Sergey Poznyakoff" <gray@gnu.org.ua>
To: commit-mailutils@gnu.org
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-802-g2ffea3b
X-Git-Refname: refs/heads/master
X-Git-Reftype: branch
X-Git-Oldrev: b54540cbbc95069b6d073246a575683170920275
X-Git-Newrev: 2ffea3b6973afdfc0972e33ba99a1faa9c4165de
Message-Id: <20161031163011.9ECAD22017C@vcs.savannah.gnu.org>
Date: Mon, 31 Oct 2016 16:30:11 +0000 (UTC)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 208.118.235.72
X-BeenThere: commit-mailutils@gnu.org
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: Commit notices for GNU mailutils <commit-mailutils.gnu.org>
List-Unsubscribe: <https://lists.gnu.org/mailman/options/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=unsubscribe>
List-Archive: <http://lists.gnu.org/archive/html/commit-mailutils/>
List-Post: <mailto:commit-mailutils@gnu.org>
List-Help: <mailto:commit-mailutils-request@gnu.org?subject=help>
List-Subscribe: <https://lists.gnu.org/mailman/listinfo/commit-mailutils>,
	<mailto:commit-mailutils-request@gnu.org?subject=subscribe>
X-List-Received-Date: Mon, 31 Oct 2016 16:30:14 -0000

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

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=2ffea3b6973afdfc0972e33ba99a1faa9c4165de

The branch, master has been updated
       via  2ffea3b6973afdfc0972e33ba99a1faa9c4165de (commit)
      from  b54540cbbc95069b6d073246a575683170920275 (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 2ffea3b6973afdfc0972e33ba99a1faa9c4165de
Author: Sergey Poznyakoff <gray@gnu.org.ua>
Date:   Mon Oct 31 18:28:03 2016 +0200

    Minor fix

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

Summary of changes:
 libmailutils/cli/cli.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmailutils/cli/cli.c b/libmailutils/cli/cli.c
index 266cb7b..793a3e2 100644
--- a/libmailutils/cli/cli.c
+++ b/libmailutils/cli/cli.c
@@ -175,7 +175,7 @@ struct mu_option mu_common_options[] = {
   { "no-user-rcfile", 0,  NULL,        MU_OPTION_ALIAS },
   
   { "no-site-config", 0,  NULL,        MU_OPTION_IMMEDIATE,
-    N_("do not load user configuration file"),
+    N_("do not load site-wide configuration file"),
     mu_c_string, NULL, no_site_config },
   { "no-site-rcfile", 0,  NULL,        MU_OPTION_ALIAS },
   


hooks/post-receive
-- 
GNU Mailutils


