commit-mailutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU Mailutils branch, master, updated. release-2.2-143-g4f9d95a


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-2.2-143-g4f9d95a
Date: Sun, 10 Oct 2010 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=4f9d95ae16167f61c74af38b564b34c2715bba1d

The branch, master has been updated
       via  4f9d95ae16167f61c74af38b564b34c2715bba1d (commit)
       via  8e96b44ffde18c9135dc5e694aea0e4e1a6a86bb (commit)
       via  1c4cec9be5a0f9dbc389b15f6effab641748e382 (commit)
      from  bf07c0b891aad29dd8eb45ff3c1b1ea8c23e7dce (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 4f9d95ae16167f61c74af38b564b34c2715bba1d
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun Oct 10 15:35:58 2010 +0300

    Minor fix
    
    * libmailutils/base/getcwd.c: Add missing include file.

commit 8e96b44ffde18c9135dc5e694aea0e4e1a6a86bb
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun Oct 10 15:29:10 2010 +0300

    Rename mu_strcasestr to mu_c_strcasestr.
    
    * include/mailutils/cstr.h (mu_strcasestr): Rename to mu_c_strcasestr.
    * libmailutils/string/cstrcasestr.c: Likewise. All uses changed.

commit 1c4cec9be5a0f9dbc389b15f6effab641748e382
Author: Sergey Poznyakoff <address@hidden>
Date:   Sun Oct 10 13:07:35 2010 +0300

    Split the mess in mutil.c into logically separated units.
    
    * libmailutils/base/mutil.c (mu_hex2ul, mu_hexstr2ul): Move to 
string/hexstr.c.
    (mu_get_homedir, mu_get_full_path)
    (mu_expand_path_pattern): Move to base/filename.c.
    (mu_getcwd): Move to base/getcwd.c.
    (mu_tilde_expansion): Move to base/tilde.c
    (mu_cpystr): Move to string/cpystr.c.
    (mu_get_host_name): Move to base/hostname.c.
    (mu_set_user_email,mu_set_user_email_domain)
    (mu_get_user_email_domain,mu_aget_user_email_domain)
    (mu_get_user_email,mu_normalize_path): Move to base/usremail.c.
    (mu_tempfile,mu_tempname): Move to base/tempfile.c.
    (mu_spawnvp): Move to base/spawnvp.c.
    (mu_qualify_link,mu_unroll_symlink): Move to base/symlink.c.
    (mu_rfc2822_references,mu_rfc2822_msg_id)
    (mu_rfc2822_in_reply_to): Move to base/msgid.c.
    (mu_strcasestr): Move to string/cstrcasestr.c.
    (mu_string_unfold): Move to string/unfold.c.
    (mu_true_answer_p): Move to string/trueans.c.
    (mu_scheme_autodetect_p): Move to base/schemeauto.c.
    (mu_fd_wait): Move to base/fdwait.c.
    (mu_set_default_fallback,mu_decode_filter): Move to filter/decode.c.
    (__argp_base_name): Move to lib/argp_base.c.
    
    * libmailutils/base/fdwait.c: New file.
    * libmailutils/base/filename.c: New file.
    * libmailutils/base/getcwd.c: New file.
    * libmailutils/base/hostname.c: New file.
    * libmailutils/base/msgid.c: New file.
    * libmailutils/base/schemeauto.c: New file.
    * libmailutils/base/spawnvp.c: New file.
    * libmailutils/base/symlink.c: New file.
    * libmailutils/base/tempfile.c: New file.
    * libmailutils/base/tilde.c: New file.
    * libmailutils/base/usremail.c: New file.
    * libmailutils/base/Makefile.am: Add new files.
    
    * libmailutils/filter/decode.c: New file.
    * libmailutils/filter/Makefile.am: Add new files.
    
    * libmailutils/string/cpystr.c: New file.
    * libmailutils/string/cstrcasestr.c: New file.
    * libmailutils/string/hexstr.c: New file.
    * libmailutils/string/trueans.c: New file.
    * libmailutils/string/unfold.c: New file.
    * libmailutils/string/Makefile.am: Add new files.
    
    * lib/argp_base.c: New file.
    * lib/Makefile.am: Add new files.
    
    * include/mailutils/io.h: Include stdarg.h
    * include/mailutils/mutil.h: Rename to util.h.  Reorder prototypes
    and declarations in logical groups.  All uses changed.
    
    * include/mailutils/cstr.h (mu_strcasestr): New proto, moved from
    include/mailutils/mutil.h.

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

Summary of changes:
 comsat/comsat.h                                    |    2 +-
 examples/addr.c                                    |    2 +-
 examples/muemail.c                                 |    2 +-
 examples/nntpclient.c                              |    2 +-
 examples/pop3client.c                              |    2 +-
 frm/frm.h                                          |    2 +-
 guimb/guimb.h                                      |    2 +-
 imap4d/imap4d.h                                    |    2 +-
 imap4d/util.c                                      |    2 +-
 include/mailutils/Makefile.am                      |    2 +-
 include/mailutils/cpp/Makefile.am                  |    2 +-
 include/mailutils/cpp/mailutils.h                  |    2 +-
 include/mailutils/cpp/{mutil.h => util.h}          |    8 +-
 include/mailutils/cstr.h                           |    1 +
 include/mailutils/io.h                             |    2 +
 include/mailutils/mailutils.h                      |    2 +-
 include/mailutils/mutil.h                          |  167 ---
 include/mailutils/parse822.h                       |    2 +-
 include/mailutils/util.h                           |  174 +++
 lib/Makefile.am                                    |    1 +
 python/libmu_py/c_api.c => lib/argp_base.c         |   17 +-
 libmailutils/address/address.c                     |    2 +-
 libmailutils/base/Makefile.am                      |   11 +
 libmailutils/base/amd.c                            |    2 +-
 libmailutils/base/assoc.c                          |    2 +-
 libmailutils/base/date.c                           |    2 +-
 libmailutils/base/fdwait.c                         |   72 +
 libmailutils/base/filename.c                       |  247 ++++
 libmailutils/base/getcwd.c                         |   70 +
 libmailutils/base/getpass.c                        |    2 +-
 libmailutils/base/hostname.c                       |  102 ++
 libmailutils/base/kwd.c                            |    2 +-
 libmailutils/base/locale.c                         |    2 +-
 libmailutils/base/locker.c                         |    2 +-
 libmailutils/base/mailcap.c                        |    2 +-
 libmailutils/base/msgid.c                          |  230 ++++
 libmailutils/base/mutil.c                          | 1372 +-------------------
 libmailutils/base/parsedate.y                      |    2 +-
 libmailutils/base/permstr.c                        |    2 +-
 libmailutils/base/registrar.c                      |    2 +-
 libmailutils/base/rfc2047.c                        |    2 +-
 .../{diag/dbgsyslog.c => base/schemeauto.c}        |   18 +-
 libmailutils/base/spawnvp.c                        |  120 ++
 libmailutils/base/symlink.c                        |  103 ++
 libmailutils/base/tempfile.c                       |  104 ++
 libmailutils/base/ticket.c                         |    2 +-
 libmailutils/base/tilde.c                          |  119 ++
 libmailutils/base/url.c                            |    2 +-
 libmailutils/base/usremail.c                       |  196 +++
 libmailutils/base/wicket.c                         |    2 +-
 libmailutils/cfg/driver.c                          |    2 +-
 libmailutils/cfg/gocs.c                            |    2 +-
 libmailutils/cfg/lexer.l                           |    2 +-
 libmailutils/cfg/parser.y                          |    2 +-
 libmailutils/filter/Makefile.am                    |    1 +
 libmailutils/filter/decode.c                       |   73 +
 libmailutils/mailbox/attribute.c                   |    2 +-
 libmailutils/mailbox/body.c                        |    2 +-
 libmailutils/mailbox/envelope.c                    |    2 +-
 libmailutils/mailbox/header.c                      |    2 +-
 libmailutils/mailbox/mailbox.c                     |    2 +-
 libmailutils/mailbox/mbx_default.c                 |    2 +-
 libmailutils/mailbox/message.c                     |    2 +-
 libmailutils/mailer/mailer.c                       |    2 +-
 libmailutils/mailer/progmailer.c                   |    2 +-
 libmailutils/mime/attachment.c                     |    2 +-
 libmailutils/mime/mime.c                           |    2 +-
 libmailutils/mime/mimehdr.c                        |    2 +-
 libmailutils/stream/file_stream.c                  |    2 +-
 libmailutils/stream/memory_stream.c                |    2 +-
 libmailutils/stream/message_stream.c               |    2 +-
 libmailutils/stream/prog_stream.c                  |    2 +-
 libmailutils/stream/tcp.c                          |    2 +-
 libmailutils/stream/temp_file_stream.c             |    2 +-
 libmailutils/string/Makefile.am                    |    5 +
 libmailutils/{diag/dbgsyslog.c => string/cpystr.c} |   27 +-
 libmailutils/string/cstrcasestr.c                  |  101 ++
 libmailutils/{diag/dbgsyslog.c => string/hexstr.c} |   44 +-
 libmailutils/string/mkfilename.c                   |    2 +-
 libmailutils/string/trueans.c                      |   58 +
 .../cpp/secret.h => libmailutils/string/unfold.c   |   71 +-
 libmailutils/tests/addr.c                          |    2 +-
 libmu_auth/ldap.c                                  |    2 +-
 libmu_auth/sql.c                                   |    2 +-
 libmu_cfg/ldap.c                                   |    2 +-
 libmu_cfg/sql.c                                    |    2 +-
 libmu_cpp/mutil.cc                                 |    2 +-
 libmu_scm/mu_scm.h                                 |    2 +-
 libmu_sieve/comparator.c                           |    2 +-
 libproto/imap/folder.c                             |    2 +-
 libproto/imap/mbox.c                               |    2 +-
 libproto/maildir/folder.c                          |    2 +-
 libproto/maildir/mbox.c                            |    2 +-
 libproto/mailer/mbox.c                             |    2 +-
 libproto/mailer/smtp.c                             |    2 +-
 libproto/mailer/smtp_auth.c                        |    2 +-
 libproto/mailer/smtp_ehlo.c                        |    2 +-
 libproto/mailer/smtp_gsasl.c                       |    2 +-
 libproto/mailer/smtp_mail.c                        |    2 +-
 libproto/mailer/smtp_mech.c                        |    2 +-
 libproto/mailer/smtp_rcpt.c                        |    2 +-
 libproto/mbox/folder.c                             |    2 +-
 libproto/mbox/mbox0.h                              |    2 +-
 libproto/mh/folder.c                               |    2 +-
 libproto/mh/mbox.c                                 |    2 +-
 libproto/pop/mbox.c                                |    2 +-
 maidag/maidag.h                                    |    2 +-
 mail/mail.h                                        |    2 +-
 mail/util.c                                        |    2 +-
 mh/mh.h                                            |    2 +-
 po/POTFILES.in                                     |   10 +
 pop3d/pop3d.h                                      |    2 +-
 python/libmu_py/libmu_py.h                         |    2 +-
 readmsg/readmsg.h                                  |    2 +-
 sieve/sieve.c                                      |    2 +-
 115 files changed, 2014 insertions(+), 1682 deletions(-)
 rename include/mailutils/cpp/{mutil.h => util.h} (90%)
 delete mode 100644 include/mailutils/mutil.h
 create mode 100644 include/mailutils/util.h
 copy python/libmu_py/c_api.c => lib/argp_base.c (73%)
 create mode 100644 libmailutils/base/fdwait.c
 create mode 100644 libmailutils/base/filename.c
 create mode 100644 libmailutils/base/getcwd.c
 create mode 100644 libmailutils/base/hostname.c
 create mode 100644 libmailutils/base/msgid.c
 copy libmailutils/{diag/dbgsyslog.c => base/schemeauto.c} (68%)
 create mode 100644 libmailutils/base/spawnvp.c
 create mode 100644 libmailutils/base/symlink.c
 create mode 100644 libmailutils/base/tempfile.c
 create mode 100644 libmailutils/base/tilde.c
 create mode 100644 libmailutils/base/usremail.c
 create mode 100644 libmailutils/filter/decode.c
 copy libmailutils/{diag/dbgsyslog.c => string/cpystr.c} (60%)
 create mode 100644 libmailutils/string/cstrcasestr.c
 copy libmailutils/{diag/dbgsyslog.c => string/hexstr.c} (52%)
 create mode 100644 libmailutils/string/trueans.c
 copy include/mailutils/cpp/secret.h => libmailutils/string/unfold.c (52%)

diff --git a/comsat/comsat.h b/comsat/comsat.h
index df4a19c..5148fa8 100644
--- a/comsat/comsat.h
+++ b/comsat/comsat.h
@@ -49,7 +49,7 @@
 #include <mailutils/list.h>
 #include <mailutils/mailbox.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/registrar.h>
 #include <mailutils/stream.h>
 #include <mailutils/mu_auth.h>
diff --git a/examples/addr.c b/examples/addr.c
index 009e13e..96a5855 100644
--- a/examples/addr.c
+++ b/examples/addr.c
@@ -25,7 +25,7 @@
 #include <mailutils/address.h>
 #include <mailutils/errno.h>
 #include <mailutils/kwd.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #define EPARSE MU_ERR_NOENT
 
diff --git a/examples/muemail.c b/examples/muemail.c
index b2635cb..0e57119 100644
--- a/examples/muemail.c
+++ b/examples/muemail.c
@@ -20,7 +20,7 @@
 #endif
 #include <stdlib.h>
 #include <stdio.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include "mailutils/libargp.h"
 
 const char *capa[] = {
diff --git a/examples/nntpclient.c b/examples/nntpclient.c
index 19fec3d..7fb28f3 100644
--- a/examples/nntpclient.c
+++ b/examples/nntpclient.c
@@ -41,7 +41,7 @@
 #include <mailutils/iterator.h>
 #include <mailutils/error.h>
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cctype.h>
 #include <mailutils/cstr.h>
 
diff --git a/examples/pop3client.c b/examples/pop3client.c
index f2d81a3..7b1f864 100644
--- a/examples/pop3client.c
+++ b/examples/pop3client.c
@@ -48,7 +48,7 @@
 #include <mailutils/cctype.h>
 #include <mailutils/cstr.h>
 #include <mailutils/tls.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 /* A structure which contains information on the commands this program
    can understand. */
diff --git a/frm/frm.h b/frm/frm.h
index 24d59ef..b45333e 100644
--- a/frm/frm.h
+++ b/frm/frm.h
@@ -59,7 +59,7 @@
 #include <mailutils/nls.h>
 #include <mailutils/tls.h>
 #include <mailutils/error.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mime.h>
 
 #include "mailutils/libargp.h"
diff --git a/guimb/guimb.h b/guimb/guimb.h
index d1fc759..621a3ec 100644
--- a/guimb/guimb.h
+++ b/guimb/guimb.h
@@ -39,7 +39,7 @@
 #include <mailutils/guile.h>
 #include <mailutils/nls.h>
 #include <mailutils/list.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/attribute.h>
 #include <mailutils/envelope.h>
 #include <mu_asprintf.h>
diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h
index 2e54f66..6cf6f58 100644
--- a/imap4d/imap4d.h
+++ b/imap4d/imap4d.h
@@ -86,7 +86,7 @@
 #include <mailutils/mailbox.h>
 #include <mailutils/message.h>
 #include <mailutils/mime.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mu_auth.h>
 #include <mailutils/nls.h>
 #include <mailutils/parse822.h>
diff --git a/imap4d/util.c b/imap4d/util.c
index 956ddc4..6d5a2c7 100644
--- a/imap4d/util.c
+++ b/imap4d/util.c
@@ -388,7 +388,7 @@ util_parse_ctime_date (const char *date, time_t * timep)
 char *
 util_strcasestr (const char *haystack, const char *needle)
 {
-  return mu_strcasestr (haystack, needle);
+  return mu_c_strcasestr (haystack, needle);
 }
 
 struct
diff --git a/include/mailutils/Makefile.am b/include/mailutils/Makefile.am
index 5b94709..6f0a67f 100644
--- a/include/mailutils/Makefile.am
+++ b/include/mailutils/Makefile.am
@@ -69,7 +69,7 @@ pkginclude_HEADERS = \
  mime.h\
  monitor.h\
  mu_auth.h\
- mutil.h\
+ util.h\
  nls.h\
  nntp.h\
  observer.h\
diff --git a/include/mailutils/cpp/Makefile.am 
b/include/mailutils/cpp/Makefile.am
index 0f9ec82..ad52dc3 100644
--- a/include/mailutils/cpp/Makefile.am
+++ b/include/mailutils/cpp/Makefile.am
@@ -33,7 +33,7 @@ cppinclude_HEADERS = \
  mailutils.h\
  message.h\
  mime.h\
- mutil.h\
+ util.h\
  pop3.h\
  registrar.h\
  secret.h\
diff --git a/include/mailutils/cpp/mailutils.h 
b/include/mailutils/cpp/mailutils.h
index d5e820d..a307e33 100644
--- a/include/mailutils/cpp/mailutils.h
+++ b/include/mailutils/cpp/mailutils.h
@@ -30,7 +30,7 @@
 #include <mailutils/cpp/mailer.h>
 #include <mailutils/cpp/message.h>
 #include <mailutils/cpp/mime.h>
-#include <mailutils/cpp/mutil.h>
+#include <mailutils/cpp/util.h>
 #include <mailutils/cpp/pop3.h>
 #include <mailutils/cpp/registrar.h>
 #include <mailutils/cpp/secret.h>
diff --git a/include/mailutils/cpp/mutil.h b/include/mailutils/cpp/util.h
similarity index 90%
rename from include/mailutils/cpp/mutil.h
rename to include/mailutils/cpp/util.h
index c64d9a7..dd2e203 100644
--- a/include/mailutils/cpp/mutil.h
+++ b/include/mailutils/cpp/util.h
@@ -15,12 +15,12 @@
    Public License along with this library.  If not, see 
    <http://www.gnu.org/licenses/>. */
 
-#ifndef _MUCPP_MUTIL_H
-#define _MUCPP_MUTIL_H
+#ifndef _MUCPP_UTIL_H
+#define _MUCPP_UTIL_H
 
 #include <string>
 #include <mailutils/filter.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 namespace mailutils
 {
@@ -32,5 +32,5 @@ std::string tempname (const std::string& tmpdir);
 
 }
 
-#endif // not _MUCPP_MUTIL_H
+#endif // not _MUCPP_UTIL_H
 
diff --git a/include/mailutils/cstr.h b/include/mailutils/cstr.h
index 787855a..0914df7 100644
--- a/include/mailutils/cstr.h
+++ b/include/mailutils/cstr.h
@@ -27,6 +27,7 @@ int mu_strupper (char *);
 
 int mu_c_strcasecmp (const char *a, const char *b);
 int mu_c_strncasecmp (const char *a, const char *b, size_t n);
+char *mu_c_strcasestr (const char *haystack, const char *needle);
 
 size_t mu_rtrim_class (char *str, int __class);
 size_t mu_rtrim_cset (char *str, const char *cset);
diff --git a/include/mailutils/io.h b/include/mailutils/io.h
index e9c862d..a80eb4b 100644
--- a/include/mailutils/io.h
+++ b/include/mailutils/io.h
@@ -18,6 +18,8 @@
 #ifndef _MAILUTILS_IO_H
 #define _MAILUTILS_IO_H
 
+#include <stdarg.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/include/mailutils/mailutils.h b/include/mailutils/mailutils.h
index 18aa097..cad14b6 100644
--- a/include/mailutils/mailutils.h
+++ b/include/mailutils/mailutils.h
@@ -44,7 +44,7 @@
 #include <mailutils/mime.h>
 #include <mailutils/monitor.h>
 #include <mailutils/mu_auth.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/nls.h>
 #include <mailutils/observer.h>
 #include <mailutils/opool.h>
diff --git a/include/mailutils/mutil.h b/include/mailutils/mutil.h
deleted file mode 100644
index 1953971..0000000
--- a/include/mailutils/mutil.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2009, 2010
-   Free Software Foundation, Inc.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 3 of the License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General
-   Public License along with this library.  If not, see
-   <http://www.gnu.org/licenses/>. */
-
-#ifndef _MAILUTILS_MUTIL_H
-#define _MAILUTILS_MUTIL_H
-
-/*
-   Collection of useful utility routines that are worth sharing,
-   but don't have a natural home somewhere else.
-*/
-
-#include <time.h>
-
-#include <mailutils/list.h>
-#include <mailutils/types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern unsigned long mu_hex2ul (char hex);
-extern size_t mu_hexstr2ul (unsigned long* ul, const char* hex, size_t len);
-
-struct mu_timezone
-{
-  int utc_offset;
-    /* Seconds east of UTC. */
-
-  const char *tz_name;
-    /* Nickname for this timezone, if known. It is always considered
-     * to be a pointer to static string, so will never be freed. */
-};
-
-typedef struct mu_timezone mu_timezone;
-
-int mu_parse_date (const char *p, time_t *rettime, const time_t *now);
-extern int mu_parse_imap_date_time (const char **p, struct tm * tm,
-                                   mu_timezone * tz);
-extern int mu_parse_ctime_date_time (const char **p, struct tm * tm,
-                                    mu_timezone * tz);
-
-extern time_t mu_utc_offset (void);
-extern time_t mu_tm2time (struct tm * timeptr, mu_timezone * tz);
-extern char * mu_get_homedir (void);
-extern char * mu_tilde_expansion (const char *ref, const char *delim, const 
char *homedir);
-
-extern size_t mu_cpystr (char *dst, const char *src, size_t size);
-
-/* Get the host name, doing a gethostbyname() if possible.
- *  
- * It is the caller's responsibility to free host.
- */
-extern int mu_get_host_name (char **host);
-
-/* Set the default user email address.
- *  
- * Subsequent calls to mu_get_user_email() with a NULL name will return this
- * email address.  email is parsed to determine that it consists of a a valid
- * rfc822 address, with one valid addr-spec, i.e, the address must be
- * qualified.
- */
-extern int mu_set_user_email (const char *email);
-
-/* Set the default user email address domain.
- *  
- * Subsequent calls to mu_get_user_email() with a non-null name will return
- * email addresses in this domain (address@hidden). It should be fully
- * qualified, but this isn't (and can't) be enforced.
- */
-extern int mu_set_user_email_domain (const char *domain);
-
-/* Return the currently set user email domain, or NULL if not set. */
-extern int mu_get_user_email_domain (const char** domain);
-
-/* Same, but allocates memory */
-extern int mu_aget_user_email_domain (char **pdomain);
-
-/*
- * Get the default email address for user name. A NULL name is taken
- * to mean the current user.
- *  
- * The result must be freed by the caller after use.
- */
-extern char *mu_get_user_email (const char *name);
-
-extern char *mu_make_file_name (const char *dir, const char *file);  
-extern char *mu_normalize_path (char *path);
-extern int mu_tempfile (const char *tmpdir, char **namep);
-extern char *mu_tempname (const char *tmpdir);
-
-extern char * mu_get_full_path (const char *file);
-extern char * mu_getcwd (void);
-  
-extern int mu_spawnvp(const char *prog, char *av[], int *stat);
-
-extern int mu_unroll_symlink (char *out, size_t outsz, const char *in);
-
-extern char * mu_expand_path_pattern (const char *pattern, const char 
*username);
-
-extern int mu_rfc2822_msg_id (int subpart, char **pstr);
-extern int mu_rfc2822_references (mu_message_t msg, char **pstr);
-extern int mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr);
-
-/* Find NEEDLE in the HAYSTACK. Case insensitive comparison */
-extern char *mu_strcasestr (const char *haystack, const char *needle);
-
-extern int mu_string_unfold (char *text, size_t *plen);
-
-extern int mu_unre_set_regex (const char *str, int caseflag, char **errp);
-extern int mu_unre_subject  (const char *subject, const char **new_subject);
-
-extern const char *mu_charset_lookup (char *lang, char *terr);
-
-extern int mu_true_answer_p (const char *p);
-extern int mu_scheme_autodetect_p (mu_url_t);
-
-struct timeval; 
-  
-extern int mu_fd_wait (int fd, int *pflags, struct timeval *tvp);
-
-extern int mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
-                            const char *filter_type,
-                            const char *fromcode, const char *tocode);
-
-extern enum mu_iconv_fallback_mode mu_default_fallback_mode;
-extern int mu_set_default_fallback (const char *str);
-
-extern int mu_is_proto (const char *p);
-
-extern int mu_mh_delim (const char *str);
-
-extern size_t mu_strftime (char *s, size_t max, const char *format,
-                          const struct tm *tm);
-  
-
-extern int mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab,
-                                 int *perr);
-
-extern int mu_stream_flags_to_mode (int flags, int isdir);
-
-extern int mu_parse_stream_perm_string (int *pmode, const char *str,
-                                       const char **endp);
-  
-extern int mu_getpass (mu_stream_t in, mu_stream_t out, const char *prompt,
-                      char **passptr);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
diff --git a/include/mailutils/parse822.h b/include/mailutils/parse822.h
index b212d18..fcfb352 100644
--- a/include/mailutils/parse822.h
+++ b/include/mailutils/parse822.h
@@ -24,7 +24,7 @@
 #define _MAILUTILS_PARSE822_H
 
 #include <mailutils/types.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/include/mailutils/util.h b/include/mailutils/util.h
new file mode 100644
index 0000000..57d11f0
--- /dev/null
+++ b/include/mailutils/util.h
@@ -0,0 +1,174 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2006, 2007, 2009, 2010
+   Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see
+   <http://www.gnu.org/licenses/>. */
+
+#ifndef _MAILUTILS_UTIL_H
+#define _MAILUTILS_UTIL_H
+
+/* A collection of utility routines that don't belong somewhere else. */
+
+#include <time.h>
+
+#include <mailutils/list.h>
+#include <mailutils/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+  /* ----------------------- */
+  /* String manipulation     */
+  /* ----------------------- */
+unsigned long mu_hex2ul (char hex);
+size_t mu_hexstr2ul (unsigned long* ul, const char* hex, size_t len);
+size_t mu_cpystr (char *dst, const char *src, size_t size);
+int mu_string_unfold (char *text, size_t *plen);
+int mu_true_answer_p (const char *p);
+int mu_unre_set_regex (const char *str, int caseflag, char **errp);
+int mu_unre_subject  (const char *subject, const char **new_subject);
+int mu_is_proto (const char *p);
+int mu_mh_delim (const char *str);
+
+
+  /* ----------------------- */
+  /* Date & time functions   */
+  /* ----------------------- */
+struct mu_timezone
+{
+  int utc_offset;  /* Seconds east of UTC. */
+
+  const char *tz_name;
+    /* Nickname for this timezone, if known. It is always considered
+       to be a pointer to static string, so will never be freed. */
+};
+
+typedef struct mu_timezone mu_timezone;
+
+int mu_parse_date (const char *p, time_t *rettime, const time_t *now);
+int mu_parse_imap_date_time (const char **p, struct tm *tm,
+                            mu_timezone *tz);
+int mu_parse_ctime_date_time (const char **p, struct tm *tm,
+                             mu_timezone *tz);
+
+time_t mu_utc_offset (void);
+time_t mu_tm2time (struct tm *timeptr, mu_timezone *tz);
+size_t mu_strftime (char *s, size_t max, const char *format,
+                   const struct tm *tm);
+  
+  /* ----------------------- */
+  /* File & path names.      */
+  /* ----------------------- */
+char *mu_get_homedir (void);
+char *mu_get_full_path (const char *file);
+char *mu_normalize_path (char *path);
+char *mu_expand_path_pattern (const char *pattern, const char *username);
+char *mu_tilde_expansion (const char *ref, const char *delim,
+                         const char *homedir);
+int mu_unroll_symlink (char *out, size_t outsz, const char *in);
+char *mu_getcwd (void);
+int mu_tempfile (const char *tmpdir, char **namep);
+char *mu_tempname (const char *tmpdir);
+char *mu_make_file_name (const char *dir, const char *file);
+  
+  /* ----------------------- */
+  /* Current user email.     */
+  /* ----------------------- */
+/* Set the default user email address.
+ *  
+ * Subsequent calls to mu_get_user_email() with a NULL name will return this
+ * email address.  email is parsed to determine that it consists of a a valid
+ * rfc822 address, with one valid addr-spec, i.e, the address must be
+ * qualified.
+ */
+int mu_set_user_email (const char *email);
+
+/* Set the default user email address domain.
+ *  
+ * Subsequent calls to mu_get_user_email() with a non-null name will return
+ * email addresses in this domain (address@hidden). It should be fully
+ * qualified, but this isn't (and can't) be enforced.
+ */
+int mu_set_user_email_domain (const char *domain);
+
+/* Return the currently set user email domain, or NULL if not set. */
+int mu_get_user_email_domain (const char** domain);
+
+/* Same, but allocates memory */
+int mu_aget_user_email_domain (char **pdomain);
+
+/*
+ * Get the default email address for user name. A NULL name is taken
+ * to mean the current user.
+ *  
+ * The result must be freed by the caller after use.
+ */
+char *mu_get_user_email (const char *name);
+
+  /* ----------------------- */
+  /* Message ID support.     */
+  /* ----------------------- */
+
+int mu_rfc2822_msg_id (int subpart, char **pstr);
+int mu_rfc2822_references (mu_message_t msg, char **pstr);
+int mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr);
+
+  /* ----------------------- */
+  /* Filter+iconv            */
+  /* ----------------------- */
+int mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
+                     const char *filter_type,
+                     const char *fromcode, const char *tocode);
+
+extern enum mu_iconv_fallback_mode mu_default_fallback_mode;
+int mu_set_default_fallback (const char *str);
+
+  /* ----------------------- */
+  /* Stream flags conversion */
+  /* ----------------------- */
+int mu_stream_flags_to_mode (int flags, int isdir);
+int mu_parse_stream_perm_string (int *pmode, const char *str,
+                                const char **endp);
+  
+  
+  /* ----------------------- */
+  /* Stream-based getpass    */
+  /* ----------------------- */
+int mu_getpass (mu_stream_t in, mu_stream_t out, const char *prompt,
+               char **passptr);
+
+  /* ----------------------- */
+  /* Assorted functions.     */
+  /* ----------------------- */
+/* Get the host name, doing a gethostbyname() if possible. */
+int mu_get_host_name (char **host);
+int mu_spawnvp(const char *prog, char *av[], int *stat);
+const char *mu_charset_lookup (char *lang, char *terr);
+int mu_scheme_autodetect_p (mu_url_t);
+
+struct timeval; 
+int mu_fd_wait (int fd, int *pflags, struct timeval *tvp);
+
+
+int mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab,
+                          int *perr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1e584d8..ed88cd0 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -20,6 +20,7 @@ include gnulib.mk
 INCLUDES = @MU_LIB_COMMON_INCLUDES@ 
 
 libmuaux_a_SOURCES += \
+ argp_base.c\
  daemon.c\
  mailcap.c\
  mu_dbm.c\
diff --git a/python/libmu_py/c_api.c b/lib/argp_base.c
similarity index 73%
copy from python/libmu_py/c_api.c
copy to lib/argp_base.c
index aab2345..36f4c88 100644
--- a/python/libmu_py/c_api.c
+++ b/lib/argp_base.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -15,11 +15,16 @@
    Public License along with this library.  If not, see
    <http://www.gnu.org/licenses/>. */
 
-#include "libmu_py.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <unistd.h>
+#include <string.h>
 
-PyMODINIT_FUNC
-initc_api (void)
+char *
+__argp_base_name (const char *arg)
 {
-  mu_py_init ();
-  mu_py_attach_modules ();
+  char *p = strrchr (arg, '/');
+  return (char *)(p ? p + 1 : arg);
 }
+
diff --git a/libmailutils/address/address.c b/libmailutils/address/address.c
index 0bdd93e..8518ada 100644
--- a/libmailutils/address/address.c
+++ b/libmailutils/address/address.c
@@ -31,7 +31,7 @@
 #include <sys/types.h>
 
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/parse822.h>
 #include <mailutils/address.h>
 #include <mailutils/cstr.h>
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am
index 4bb7acb..196344b 100644
--- a/libmailutils/base/Makefile.am
+++ b/libmailutils/base/Makefile.am
@@ -24,9 +24,13 @@ libbase_la_SOURCES = \
  assoc.c\
  daemon.c\
  date.c\
+ fdwait.c\
  fgetpwent.c\
+ filename.c\
  freeitem.c\
+ getcwd.c\
  getpass.c\
+ hostname.c\
  iterator.c\
  kwd.c\
  list.c\
@@ -36,6 +40,7 @@ libbase_la_SOURCES = \
  mailcap.c\
  md5.c\
  monitor.c\
+ msgid.c\
  munre.c\
  mutil.c\
  nls.c\
@@ -48,10 +53,16 @@ libbase_la_SOURCES = \
  registrar.c\
  refcount.c\
  rfc2047.c\
+ schemeauto.c\
  sha1.c\
  secret.c\
+ spawnvp.c\
+ symlink.c\
+ tempfile.c\
  ticket.c\
+ tilde.c\
  url.c\
+ usremail.c\
  vartab.c\
  version.c\
  wicket.c
diff --git a/libmailutils/base/amd.c b/libmailutils/base/amd.c
index 1a32228..c2f3b34 100644
--- a/libmailutils/base/amd.c
+++ b/libmailutils/base/amd.c
@@ -62,7 +62,7 @@
 #include <mailutils/header.h>
 #include <mailutils/locker.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/property.h>
 #include <mailutils/stream.h>
 #include <mailutils/url.h>
diff --git a/libmailutils/base/assoc.c b/libmailutils/base/assoc.c
index 4d27cb7..b2e3f60 100644
--- a/libmailutils/base/assoc.c
+++ b/libmailutils/base/assoc.c
@@ -25,7 +25,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/error.h>
 #include <mailutils/iterator.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 #include <mailutils/sys/iterator.h>
 
diff --git a/libmailutils/base/date.c b/libmailutils/base/date.c
index efb187b..1f9353c 100644
--- a/libmailutils/base/date.c
+++ b/libmailutils/base/date.c
@@ -22,7 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 
 #define SECS_PER_DAY 86400
diff --git a/libmailutils/base/fdwait.c b/libmailutils/base/fdwait.c
new file mode 100644
index 0000000..1a489e4
--- /dev/null
+++ b/libmailutils/base/fdwait.c
@@ -0,0 +1,72 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <errno.h>
+#include <mailutils/stream.h>
+
+int
+mu_fd_wait (int fd, int *pflags, struct timeval *tvp)
+{
+  fd_set rdset, wrset, exset;
+  int rc;
+
+  FD_ZERO (&rdset);
+  FD_ZERO (&wrset);
+  FD_ZERO (&exset);
+  if ((*pflags) & MU_STREAM_READY_RD)
+    FD_SET (fd, &rdset);
+  if ((*pflags) & MU_STREAM_READY_WR)
+    FD_SET (fd, &wrset);
+  if ((*pflags) & MU_STREAM_READY_EX)
+    FD_SET (fd, &exset);
+  
+  do
+    {
+      if (tvp)
+       {
+         struct timeval tv = *tvp; 
+         rc = select (fd + 1, &rdset, &wrset, &exset, &tv);
+       }
+      else
+       rc = select (fd + 1, &rdset, &wrset, &exset, NULL);
+    }
+  while (rc == -1 && errno == EINTR);
+
+  if (rc < 0)
+    return errno;
+  
+  *pflags = 0;
+  if (rc > 0)
+    {
+      if (FD_ISSET (fd, &rdset))
+       *pflags |= MU_STREAM_READY_RD;
+      if (FD_ISSET (fd, &wrset))
+       *pflags |= MU_STREAM_READY_WR;
+      if (FD_ISSET (fd, &exset))
+       *pflags |= MU_STREAM_READY_EX;
+    }
+  return 0;
+}
diff --git a/libmailutils/base/filename.c b/libmailutils/base/filename.c
new file mode 100644
index 0000000..97c4813
--- /dev/null
+++ b/libmailutils/base/filename.c
@@ -0,0 +1,247 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <mailutils/types.h>
+#include <mailutils/util.h>
+#include <mailutils/mu_auth.h>
+
+char *
+mu_get_homedir (void)
+{
+  char *homedir = getenv ("HOME");
+  if (homedir)
+    homedir = strdup (homedir);
+  else
+    {
+      struct mu_auth_data *auth = mu_get_auth_by_uid (geteuid ());
+      if (!auth)
+       return NULL;
+      homedir = strdup (auth->dir);
+      mu_auth_data_free (auth);
+    }
+  return homedir;
+}
+
+char *
+mu_get_full_path (const char *file)
+{
+  char *p = NULL;
+
+  if (!file)
+    p = mu_getcwd ();
+  else if (*file != '/')
+    {
+      char *cwd = mu_getcwd ();
+      if (cwd)
+       {
+         p = calloc (strlen (cwd) + 1 + strlen (file) + 1, 1);
+         if (p)
+           sprintf (p, "%s/%s", cwd, file);
+         free (cwd);
+       }
+    }
+
+  if (!p)
+    p = strdup (file);
+  return p;
+}
+
+/* mu_normalize_path: convert pathname containig relative paths specs (../)
+   into an equivalent absolute path. Strip trailing delimiter if present,
+   unless it is the only character left. E.g.:
+
+         /home/user/../smith   -->   /home/smith
+        /home/user/../..      -->   /
+
+*/
+char *
+mu_normalize_path (char *path)
+{
+  int len;
+  char *p;
+
+  if (!path)
+    return path;
+
+  len = strlen (path);
+
+  /* Empty string is returned as is */
+  if (len == 0)
+    return path;
+
+  /* delete trailing delimiter if any */
+  if (len && path[len-1] == '/')
+    path[len-1] = 0;
+
+  /* Eliminate any /../ */
+  for (p = strchr (path, '.'); p; p = strchr (p, '.'))
+    {
+      if (p > path && p[-1] == '/')
+       {
+         if (p[1] == '.' && (p[2] == 0 || p[2] == '/'))
+           /* found */
+           {
+             char *q, *s;
+
+             /* Find previous delimiter */
+             for (q = p-2; *q != '/' && q >= path; q--)
+               ;
+
+             if (q < path)
+               break;
+             /* Copy stuff */
+             s = p + 2;
+             p = q;
+             while ((*q++ = *s++))
+               ;
+             continue;
+           }
+       }
+
+      p++;
+    }
+
+  if (path[0] == 0)
+    {
+      path[0] = '/';
+      path[1] = 0;
+    }
+
+  return path;
+}
+
+/* Expand a PATTERN to the pathname. PATTERN may contain the following
+   macro-notations:
+   ---------+------------ 
+   notation |  expands to
+   ---------+------------
+   %u         user name
+   %h         user's home dir
+   ~          Likewise
+   ---------+------------
+
+   Allocates memory. 
+*/
+char *
+mu_expand_path_pattern (const char *pattern, const char *username)
+{
+  const char *p;
+  char *q;
+  char *path;
+  size_t len = 0;
+  struct mu_auth_data *auth = NULL;
+  
+  for (p = pattern; *p; p++)
+    {
+      if (*p == '~')
+        {
+          if (!auth)
+            {
+              auth = mu_get_auth_by_name (username);
+              if (!auth)
+                return NULL;
+            }
+          len += strlen (auth->dir);
+        }
+      else if (*p == '%')
+       switch (*++p)
+         {
+         case 'u':
+           len += strlen (username);
+           break;
+           
+         case 'h':
+           if (!auth)
+             {
+               auth = mu_get_auth_by_name (username);
+               if (!auth)
+                 return NULL;
+             }
+           len += strlen (auth->dir);
+           break;
+           
+         case '%':
+           len++;
+           break;
+           
+         default:
+           len += 2;
+         }
+      else
+       len++;
+    }
+  
+  path = malloc (len + 1);
+  if (!path)
+    return NULL;
+
+  p = pattern;
+  q = path;
+  while (*p)
+    {
+      size_t off = strcspn (p, "~%");
+      memcpy (q, p, off);
+      q += off;
+      p += off;
+      if (*p == '~')
+       {
+         strcpy (q, auth->dir);
+         q += strlen (auth->dir);
+         p++;
+       }
+      else if (*p == '%')
+       {
+         switch (*++p)
+           {
+           case 'u':
+             strcpy (q, username);
+             q += strlen (username);
+             break;
+           
+           case 'h':
+             strcpy (q, auth->dir);
+             q += strlen (auth->dir);
+             break;
+         
+           case '%':
+             *q++ = '%';
+             break;
+         
+           default:
+             *q++ = '%';
+             *q++ = *p;
+           }
+         p++;
+       }
+    }
+
+  *q = 0;
+  if (auth)
+    mu_auth_data_free (auth);
+  return path;
+}
diff --git a/libmailutils/base/getcwd.c b/libmailutils/base/getcwd.c
new file mode 100644
index 0000000..4f7ac60
--- /dev/null
+++ b/libmailutils/base/getcwd.c
@@ -0,0 +1,70 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+mu_getcwd ()
+{
+  char *ret;
+  unsigned path_max;
+  char buf[128];
+
+  errno = 0;
+  ret = getcwd (buf, sizeof (buf));
+  if (ret != NULL)
+    return strdup (buf);
+
+  if (errno != ERANGE)
+    return NULL;
+
+  path_max = 128;
+  path_max += 2;                /* The getcwd docs say to do this. */
+
+  for (;;)
+    {
+      char *cwd = (char *) malloc (path_max);
+
+      errno = 0;
+      ret = getcwd (cwd, path_max);
+      if (ret != NULL)
+        return ret;
+      if (errno != ERANGE)
+        {
+          int save_errno = errno;
+          free (cwd);
+          errno = save_errno;
+          return NULL;
+        }
+
+      free (cwd);
+
+      path_max += path_max / 16;
+      path_max += 32;
+    }
+  /* oops?  */
+  return NULL;
+}
+
diff --git a/libmailutils/base/getpass.c b/libmailutils/base/getpass.c
index 8a37c52..ec88b0e 100644
--- a/libmailutils/base/getpass.c
+++ b/libmailutils/base/getpass.c
@@ -24,7 +24,7 @@
 
 #include <mailutils/types.h>
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 
 int
diff --git a/libmailutils/base/hostname.c b/libmailutils/base/hostname.c
new file mode 100644
index 0000000..4113dc2
--- /dev/null
+++ b/libmailutils/base/hostname.c
@@ -0,0 +1,102 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <netdb.h>
+
+#ifndef MAXHOSTNAMELEN
+# define MAXHOSTNAMELEN 64
+#endif
+
+int
+mu_get_host_name (char **host)
+{
+  char *hostname = NULL;
+  size_t size = 0;
+  char *p;
+
+  while (1)
+    {
+      if (size == 0)
+       {
+         size = MAXHOSTNAMELEN;
+         p = malloc (size);
+       }
+      else
+       {
+         size_t ns = size * 2;
+         if (ns < size)
+           {
+             free (hostname);
+             return ENOMEM;
+           }
+         size = ns;
+         p = realloc (hostname, size);
+       }
+      if (!p)
+       {
+         free (hostname);
+         return ENOMEM;
+       }
+      hostname = p;
+      hostname[size - 1] = 0;
+      if (gethostname (hostname, size - 1) == 0)
+       {
+         if (!hostname[size - 1])
+           break;
+       }
+      else if (errno != 0 && errno != ENAMETOOLONG && errno != EINVAL
+              && errno != ENOMEM)
+       {
+         int rc = errno;
+         free (hostname);
+         return rc;
+       }
+    }
+
+  /* Try to return fully qualified host name */
+  if (!strchr (hostname, '.'))
+    {
+      struct hostent *hp = gethostbyname (hostname);
+      if (hp)
+       {
+         size_t len = strlen (hp->h_name);
+         if (size < len + 1)
+           {
+             p = realloc (hostname, len + 1);
+             if (!p)
+               {
+                 free (hostname);
+                 return ENOMEM;
+               }
+             hostname = p;
+           }
+         strcpy (hostname, hp->h_name);
+       }
+    }
+  
+  *host = hostname;
+  return 0;
+}  
+
diff --git a/libmailutils/base/kwd.c b/libmailutils/base/kwd.c
index 9135f9f..3e50e93 100644
--- a/libmailutils/base/kwd.c
+++ b/libmailutils/base/kwd.c
@@ -22,7 +22,7 @@
 #include <string.h>
 #include <mailutils/kwd.h>
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 
 int
diff --git a/libmailutils/base/locale.c b/libmailutils/base/locale.c
index 4234ad4..c871cee 100644
--- a/libmailutils/base/locale.c
+++ b/libmailutils/base/locale.c
@@ -21,7 +21,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 
 struct langtab
diff --git a/libmailutils/base/locker.c b/libmailutils/base/locker.c
index b720e20..99a1a4e 100644
--- a/libmailutils/base/locker.c
+++ b/libmailutils/base/locker.c
@@ -40,7 +40,7 @@
 
 #include <mailutils/errno.h>
 #include <mailutils/locker.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #define LOCKFILE_ATTR           0644
 
diff --git a/libmailutils/base/mailcap.c b/libmailutils/base/mailcap.c
index ede3f67..7b0af63 100644
--- a/libmailutils/base/mailcap.c
+++ b/libmailutils/base/mailcap.c
@@ -27,7 +27,7 @@
 #include <mailutils/cctype.h>
 #include <mailutils/mailcap.h>
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 
 /* Definition of the structure, this should be in mailutils/sys/mailcap.h.  */
diff --git a/libmailutils/base/msgid.c b/libmailutils/base/msgid.c
new file mode 100644
index 0000000..d7905b4
--- /dev/null
+++ b/libmailutils/base/msgid.c
@@ -0,0 +1,230 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/time.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/cctype.h>
+#include <mailutils/message.h>
+#include <mailutils/header.h>
+#include <mailutils/util.h>
+#include <mailutils/io.h>
+#include <mailutils/envelope.h>
+#include <mailutils/errno.h>
+
+#define ST_INIT  0
+#define ST_MSGID 1
+
+static int
+strip_message_id (const char *msgid, char **pval)
+{
+  const char *p;
+  char *q;
+  int state;
+  
+  *pval = malloc (strlen (msgid) + 1);
+  if (!*pval)
+    return ENOMEM;
+  state = ST_INIT;
+  for (p = msgid, q = *pval; *p; p++)
+    {
+      switch (state)
+       {
+       case ST_INIT:
+         if (*p == '<')
+           {
+             *q++ = *p;
+             state = ST_MSGID;
+           }
+         else if (mu_isspace (*p))
+           *q++ = *p;
+         break;
+
+       case ST_MSGID:
+         *q++ = *p;
+         if (*p == '>')
+           state = ST_INIT;
+         break;
+       }
+    }
+  *q = 0;
+  return 0;
+}
+
+static int
+get_msgid_header (mu_header_t hdr, const char *name, char **val)
+{
+  const char *p;
+  int status = mu_header_sget_value (hdr, name, &p);
+  if (status)
+    return status;
+  return strip_message_id (p, val);
+}
+
+static char *
+concat (const char *s1, const char *s2)
+{
+  int len = (s1 ? strlen (s1) : 0) + (s2 ? strlen (s2) : 0) + 2;
+  char *s = malloc (len);
+  if (s)
+    {
+      char *p = s;
+      
+      if (s1)
+       {
+         strcpy (p, s1);
+         p += strlen (s1);
+         *p++ = ' ';
+       }
+      if (s2)
+       strcpy (p, s2);
+    }
+  return s;
+}
+
+/* rfc2822:
+   
+   The "References:" field will contain the contents of the parent's
+   "References:" field (if any) followed by the contents of the parent's
+   "Message-ID:" field (if any).  If the parent message does not contain
+   a "References:" field but does have an "In-Reply-To:" field
+   containing a single message identifier, then the "References:" field
+   will contain the contents of the parent's "In-Reply-To:" field
+   followed by the contents of the parent's "Message-ID:" field (if
+   any).  If the parent has none of the "References:", "In-Reply-To:",
+   or "Message-ID:" fields, then the new message will have no
+   References:" field. */
+
+int
+mu_rfc2822_references (mu_message_t msg, char **pstr)
+{
+  char *ref = NULL, *msgid = NULL;
+  mu_header_t hdr;
+  int rc;
+  
+  rc = mu_message_get_header (msg, &hdr);
+  if (rc)
+    return rc;
+  get_msgid_header (hdr, MU_HEADER_MESSAGE_ID, &msgid);
+  if (get_msgid_header (hdr, MU_HEADER_REFERENCES, &ref))
+    get_msgid_header (hdr, MU_HEADER_IN_REPLY_TO, &ref);
+
+  if (ref || msgid)
+    {
+      *pstr = concat (ref, msgid);
+      free (ref);
+      free (msgid);
+      return 0;
+    }
+  return MU_ERR_FAILURE;
+}
+
+int
+mu_rfc2822_msg_id (int subpart, char **pval)
+{
+  char date[4+2+2+2+2+2+1];
+  time_t t = time (NULL);
+  struct tm *tm = localtime (&t);
+  char *host;
+  char *p;
+         
+  mu_strftime (date, sizeof date, "%Y%m%d%H%M%S", tm);
+  mu_get_host_name (&host);
+
+  if (subpart)
+    {
+      struct timeval tv;
+      gettimeofday (&tv, NULL);
+      mu_asprintf (&p, "<address@hidden>",
+                  date,
+                  (unsigned long) getpid (),
+                  subpart,
+                  host);
+    }
+  else
+    mu_asprintf (&p, "<address@hidden>", date, (unsigned long) getpid (), 
host);
+  free (host);
+  *pval = p;
+  return 0;
+}
+
+#define DATEBUFSIZE 128
+#define COMMENT "Your message of "
+
+/*
+   The "In-Reply-To:" field will contain the contents of the "Message-
+   ID:" field of the message to which this one is a reply (the "parent
+   message").  If there is more than one parent message, then the "In-
+   Reply-To:" field will contain the contents of all of the parents'
+   "Message-ID:" fields.  If there is no "Message-ID:" field in any of
+   the parent messages, then the new message will have no "In-Reply-To:"
+   field.
+*/
+int
+mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr)
+{
+  const char *value = NULL;
+  char *s1 = NULL, *s2 = NULL;
+  mu_header_t hdr;
+  int rc;
+  
+  rc = mu_message_get_header (msg, &hdr);
+  if (rc)
+    return rc;
+  
+  if (mu_header_sget_value (hdr, MU_HEADER_DATE, &value))
+    {
+      mu_envelope_t envelope = NULL;
+      mu_message_get_envelope (msg, &envelope);
+      mu_envelope_sget_date (envelope, &value);
+    }
+
+  if (value)
+    {
+      s1 = malloc (sizeof (COMMENT) + strlen (value));
+      if (!s1)
+       return ENOMEM;
+      strcat (strcpy (s1, COMMENT), value);
+    }
+  
+  if (mu_header_sget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0)
+    {
+      s2 = malloc (strlen (value) + 3);
+      if (!s2)
+       {
+         free (s1);
+         return ENOMEM;
+       }
+      strcat (strcpy (s2, "\n\t"), value);
+    }
+
+  if (s1 || s2)
+    {
+      *pstr = concat (s1, s2);
+      free (s1);
+      free (s2);
+      return 0;
+    }
+  return MU_ERR_FAILURE;
+}
diff --git a/libmailutils/base/mutil.c b/libmailutils/base/mutil.c
index 8612106..ffa04dd 100644
--- a/libmailutils/base/mutil.c
+++ b/libmailutils/base/mutil.c
@@ -20,1375 +20,16 @@
 # include <config.h>
 #endif
 
-#include <errno.h>
-#include <limits.h>
-#include <netdb.h>
-#include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/select.h>
-
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-
-#include <mailutils/address.h>
-#include <mailutils/assoc.h>
+#include <time.h>
 #include <mailutils/argcv.h>
 #include <mailutils/error.h>
 #include <mailutils/errno.h>
-#include <mailutils/iterator.h>
-#include <mailutils/mutil.h>
-#include <mailutils/parse822.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/header.h>
-#include <mailutils/message.h>
-#include <mailutils/envelope.h>
 #include <mailutils/nls.h>
+#include <mailutils/assoc.h>
 #include <mailutils/stream.h>
-#include <mailutils/filter.h>
 #include <mailutils/sql.h>
-#include <mailutils/url.h>
-#include <mailutils/io.h>
-#include <mailutils/cctype.h>
-#include <mailutils/cstr.h>
-
-#include <mailutils/sys/registrar.h>
-
-/* convert a sequence of hex characters into an integer */
-
-unsigned long
-mu_hex2ul (char hex)
-{
-  if (hex >= '0' && hex <= '9')
-   return hex - '0';
-
-  if (hex >= 'a' && hex <= 'z')
-    return hex - 'a' + 10;
-
-  if (hex >= 'A' && hex <= 'Z')
-    return hex - 'A' + 10;
-
-  return -1;
-}
-
-size_t
-mu_hexstr2ul (unsigned long *ul, const char *hex, size_t len)
-{
-  size_t r;
-
-  *ul = 0;
-
-  for (r = 0; r < len; r++)
-    {
-      unsigned long v = mu_hex2ul (hex[r]);
-
-      if (v == (unsigned long)-1)
-       return r;
-
-      *ul = *ul * 16 + v;
-    }
-  return r;
-}
-
-
-char *
-mu_get_homedir (void)
-{
-  char *homedir = getenv ("HOME");
-  if (homedir)
-    homedir = strdup (homedir);
-  else
-    {
-      struct mu_auth_data *auth = mu_get_auth_by_uid (geteuid ());
-      if (!auth)
-       return NULL;
-      homedir = strdup (auth->dir);
-      mu_auth_data_free (auth);
-    }
-  return homedir;
-}
-
-char *
-mu_getcwd ()
-{
-  char *ret;
-  unsigned path_max;
-  char buf[128];
-
-  errno = 0;
-  ret = getcwd (buf, sizeof (buf));
-  if (ret != NULL)
-    return strdup (buf);
-
-  if (errno != ERANGE)
-    return NULL;
-
-  path_max = 128;
-  path_max += 2;                /* The getcwd docs say to do this. */
-
-  for (;;)
-    {
-      char *cwd = (char *) malloc (path_max);
-
-      errno = 0;
-      ret = getcwd (cwd, path_max);
-      if (ret != NULL)
-        return ret;
-      if (errno != ERANGE)
-        {
-          int save_errno = errno;
-          free (cwd);
-          errno = save_errno;
-          return NULL;
-        }
-
-      free (cwd);
-
-      path_max += path_max / 16;
-      path_max += 32;
-    }
-  /* oops?  */
-  return NULL;
-}
-
-char *
-mu_get_full_path (const char *file)
-{
-  char *p = NULL;
-
-  if (!file)
-    p = mu_getcwd ();
-  else if (*file != '/')
-    {
-      char *cwd = mu_getcwd ();
-      if (cwd)
-       {
-         p = calloc (strlen (cwd) + 1 + strlen (file) + 1, 1);
-         if (p)
-           sprintf (p, "%s/%s", cwd, file);
-         free (cwd);
-       }
-    }
-
-  if (!p)
-    p = strdup (file);
-  return p;
-}
-
-/* NOTE: Allocates Memory.  */
-/* Expand: ~ --> /home/user and to ~guest --> /home/guest.  */
-char *
-mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
-{
-  char *base = strdup (ref);
-  char *home = NULL;
-  char *proto = NULL;
-  size_t proto_len = 0;
-  char *p;
-
-  for (p = base; *p && isascii (*p) && isalnum (*p); p++)
-    ;
-  
-  if (*p == ':')
-    {
-      p++;
-      proto_len = p - base;
-      proto = malloc (proto_len + 1);
-      if (!proto)
-       return NULL;
-      memcpy (proto, base, proto_len);
-      proto[proto_len] = 0;
-      /* Allow for extra pair of slashes after the protocol specifier */
-      if (*p == delim[0])
-       p++;
-      if (*p == delim[0])
-       p++;
-    }
-  else
-    p = base;
-  
-  if (*p == '~')
-    {
-      p++;
-      if (*p == delim[0] || *p == '\0')
-        {
-         char *s;
-         if (!homedir)
-           {
-             home = mu_get_homedir ();
-             if (!home)
-               return base;
-             homedir = home;
-           }
-         s = calloc (proto_len + strlen (homedir) + strlen (p) + 1, 1);
-         if (proto_len)
-           strcpy (s, proto);
-         else
-           s[0] = 0;
-          strcat (s, homedir);
-          strcat (s, p);
-          free (base);
-          base = s;
-        }
-      else
-        {
-          struct mu_auth_data *auth;
-          char *s = p;
-          char *name;
-          while (*s && *s != delim[0])
-            s++;
-          name = calloc (s - p + 1, 1);
-          memcpy (name, p, s - p);
-          name[s - p] = '\0';
-         
-          auth = mu_get_auth_by_name (name);
-          free (name);
-          if (auth)
-            {
-              char *buf = calloc (proto_len + strlen (auth->dir)
-                                 + strlen (s) + 1, 1);
-             if (proto_len)
-               strcpy (buf, proto);
-             else
-               buf[0] = 0;
-             strcat (buf, auth->dir);
-              strcat (buf, s);
-              free (base);
-              base = buf;
-             mu_auth_data_free (auth);
-            }
-        }
-    }
-  if (home)
-    free (home);
-  return base;
-}
-
-/* Smart strncpy that always add the null and returns the number of bytes
-   written.  */
-size_t
-mu_cpystr (char *dst, const char *src, size_t size)
-{
-  size_t len = src ? strlen (src) : 0 ;
-  if (dst == NULL || size == 0)
-    return len;
-  if (len >= size)
-    len = size - 1;
-  memcpy (dst, src, len);
-  dst[len] = '\0';
-  return len;
-}
-
-#ifndef MAXHOSTNAMELEN
-# define MAXHOSTNAMELEN 64
-#endif
-
-int
-mu_get_host_name (char **host)
-{
-  char *hostname = NULL;
-  size_t size = 0;
-  char *p;
-
-  while (1)
-    {
-      if (size == 0)
-       {
-         size = MAXHOSTNAMELEN;
-         p = malloc (size);
-       }
-      else
-       {
-         size_t ns = size * 2;
-         if (ns < size)
-           {
-             free (hostname);
-             return ENOMEM;
-           }
-         size = ns;
-         p = realloc (hostname, size);
-       }
-      if (!p)
-       {
-         free (hostname);
-         return ENOMEM;
-       }
-      hostname = p;
-      hostname[size - 1] = 0;
-      if (gethostname (hostname, size - 1) == 0)
-       {
-         if (!hostname[size - 1])
-           break;
-       }
-      else if (errno != 0 && errno != ENAMETOOLONG && errno != EINVAL
-              && errno != ENOMEM)
-       {
-         int rc = errno;
-         free (hostname);
-         return rc;
-       }
-    }
-
-  /* Try to return fully qualified host name */
-  if (!strchr (hostname, '.'))
-    {
-      struct hostent *hp = gethostbyname (hostname);
-      if (hp)
-       {
-         size_t len = strlen (hp->h_name);
-         if (size < len + 1)
-           {
-             p = realloc (hostname, len + 1);
-             if (!p)
-               {
-                 free (hostname);
-                 return ENOMEM;
-               }
-             hostname = p;
-           }
-         strcpy (hostname, hp->h_name);
-       }
-    }
-  
-  *host = hostname;
-  return 0;
-}  
-
-/*
- * Functions used to convert unix mailbox/user names into RFC822 addr-specs.
- */
-
-static char *mu_user_email = 0;
-
-int
-mu_set_user_email (const char *candidate)
-{
-  int err = 0;
-  mu_address_t addr = NULL;
-  size_t emailno = 0;
-  char *email = NULL;
-  const char *domain = NULL;
-  
-  if ((err = mu_address_create (&addr, candidate)) != 0)
-    return err;
-
-  if ((err = mu_address_get_email_count (addr, &emailno)) != 0)
-    goto cleanup;
-
-  if (emailno != 1)
-    {
-      errno = EINVAL;
-      goto cleanup;
-    }
-
-  if ((err = mu_address_aget_email (addr, 1, &email)) != 0)
-    goto cleanup;
-
-  if (mu_user_email)
-    free (mu_user_email);
-
-  mu_user_email = email;
-
-  if ((err = mu_address_sget_domain (addr, 1, &domain)) == 0)
-    mu_set_user_email_domain (domain);
-  
-cleanup:
-  mu_address_destroy (&addr);
-
-  return err;
-}
-
-static char *mu_user_email_domain = 0;
-
-int
-mu_set_user_email_domain (const char *domain)
-{
-  char *d = NULL;
-  
-  if (!domain)
-    return EINVAL;
-  
-  d = strdup (domain);
-
-  if (!d)
-    return ENOMEM;
-
-  if (mu_user_email_domain)
-    free (mu_user_email_domain);
-
-  mu_user_email_domain = d;
-
-  return 0;
-}
-
-/* FIXME: must be called _sget_ */
-int
-mu_get_user_email_domain (const char **domain)
-{
-  int err = 0;
-
-  if (!mu_user_email_domain)
-    {
-      if ((err = mu_get_host_name (&mu_user_email_domain)))
-       return err;
-    }
-
-  *domain = mu_user_email_domain;
-
-  return 0;
-}
-
-int
-mu_aget_user_email_domain (char **pdomain)
-{
-  const char *domain;
-  int status = mu_get_user_email_domain (&domain);
-  if (status)
-    return status;
-  if (domain == NULL)
-    *pdomain = NULL;
-  else
-    {
-      *pdomain = strdup (domain);
-      if (*pdomain == NULL)
-       return ENOMEM;
-    }
-  return 0;
-}
-
-/* Note: allocates memory */
-char *
-mu_get_user_email (const char *name)
-{
-  int status = 0;
-  char *localpart = NULL;
-  const char *domainpart = NULL;
-  char *email = NULL;
-  char *tmpname = NULL;
-
-  if (!name && mu_user_email)
-    {
-      email = strdup (mu_user_email);
-      if (!email)
-       errno = ENOMEM;
-      return email;
-    }
-
-  if (!name)
-    {
-      struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
-      if (!auth)
-       {
-         errno = EINVAL;
-         return NULL;
-       }
-      name = tmpname = strdup(auth->name);
-      if (auth)
-       mu_auth_data_free (auth);
-    }
-
-  status = mu_get_user_email_domain (&domainpart);
-
-  if (status)
-    {
-      free(tmpname);
-      errno = status;
-      return NULL;
-    }
-
-  if ((status = mu_parse822_quote_local_part (&localpart, name)))
-    {
-      free(tmpname);
-      errno = status;
-      return NULL;
-    }
-
-
-  email = malloc (strlen (localpart) + 1
-                 + strlen (domainpart) + 1);
-  if (!email)
-    errno = ENOMEM;
-  else
-    sprintf (email, "address@hidden", localpart, domainpart);
-
-  free(tmpname);
-  free (localpart);
-
-  return email;
-}
-
-/* mu_normalize_path: convert pathname containig relative paths specs (../)
-   into an equivalent absolute path. Strip trailing delimiter if present,
-   unless it is the only character left. E.g.:
-
-         /home/user/../smith   -->   /home/smith
-        /home/user/../..      -->   /
-
-*/
-char *
-mu_normalize_path (char *path)
-{
-  int len;
-  char *p;
-
-  if (!path)
-    return path;
-
-  len = strlen (path);
-
-  /* Empty string is returned as is */
-  if (len == 0)
-    return path;
-
-  /* delete trailing delimiter if any */
-  if (len && path[len-1] == '/')
-    path[len-1] = 0;
-
-  /* Eliminate any /../ */
-  for (p = strchr (path, '.'); p; p = strchr (p, '.'))
-    {
-      if (p > path && p[-1] == '/')
-       {
-         if (p[1] == '.' && (p[2] == 0 || p[2] == '/'))
-           /* found */
-           {
-             char *q, *s;
-
-             /* Find previous delimiter */
-             for (q = p-2; *q != '/' && q >= path; q--)
-               ;
-
-             if (q < path)
-               break;
-             /* Copy stuff */
-             s = p + 2;
-             p = q;
-             while ((*q++ = *s++))
-               ;
-             continue;
-           }
-       }
-
-      p++;
-    }
-
-  if (path[0] == 0)
-    {
-      path[0] = '/';
-      path[1] = 0;
-    }
-
-  return path;
-}
-
-/* Create and open a temporary file. Be very careful about it, since we
-   may be running with extra privilege i.e setgid().
-   Returns file descriptor of the open file.
-   If namep is not NULL, the pointer to the malloced file name will
-   be stored there. Otherwise, the file is unlinked right after open,
-   i.e. it will disappear after close(fd). */
-
-#ifndef P_tmpdir
-# define P_tmpdir "/tmp"
-#endif
-
-int
-mu_tempfile (const char *tmpdir, char **namep)
-{
-  char *filename;
-  int fd;
-
-  if (!tmpdir)
-    tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : P_tmpdir;
-
-  filename = malloc (strlen (tmpdir) + /*'/'*/1 + /* "muXXXXXX" */8 + 1);
-  if (!filename)
-    return -1;
-  sprintf (filename, "%s/muXXXXXX", tmpdir);
-
-#ifdef HAVE_MKSTEMP
-  {
-    int save_mask = umask (077);
-    fd = mkstemp (filename);
-    umask (save_mask);
-  }
-#else
-  if (mktemp (filename))
-    fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600);
-  else
-    fd = -1;
-#endif
-
-  if (fd == -1)
-    {
-      mu_error (_("cannot open temporary file: %s"), mu_strerror (errno));
-      free (filename);
-      return -1;
-    }
-
-  if (namep)
-    *namep = filename;
-  else
-    {
-      unlink (filename);
-      free (filename);
-    }
-
-  return fd;
-}
-
-/* Create a unique temporary file name in tmpdir. The function
-   creates an empty file with this name to avoid possible race
-   conditions. Returns a pointer to the malloc'ed file name.
-   If tmpdir is NULL, the value of the environment variable
-   TMPDIR or the hardcoded P_tmpdir is used, whichever is defined. */
-
-char *
-mu_tempname (const char *tmpdir)
-{
-  char *filename = NULL;
-  int fd = mu_tempfile (tmpdir, &filename);
-  close (fd);
-  return filename;
-}
-
-/* See Advanced Programming in the UNIX Environment, Stevens,
- * program  10.20 for the rational for the signal handling. I
- * had to look it up, so if somebody else is curious, thats where
- * to find it.
- */
-int 
-mu_spawnvp (const char *prog, char *av[], int *stat)
-{
-  pid_t pid;
-  int err = 0;
-  int progstat;
-  struct sigaction ignore;
-  struct sigaction saveintr;
-  struct sigaction savequit;
-  sigset_t chldmask;
-  sigset_t savemask;
-
-  if (!prog || !av)
-    return EINVAL;
-
-  ignore.sa_handler = SIG_IGN; /* ignore SIGINT and SIGQUIT */
-  ignore.sa_flags = 0;
-  sigemptyset (&ignore.sa_mask);
-
-  if (sigaction (SIGINT, &ignore, &saveintr) < 0)
-    return errno;
-  if (sigaction (SIGQUIT, &ignore, &savequit) < 0)
-    {
-      sigaction (SIGINT, &saveintr, NULL);
-      return errno;
-    }
-
-  sigemptyset (&chldmask);     /* now block SIGCHLD */
-  sigaddset (&chldmask, SIGCHLD);
-
-  if (sigprocmask (SIG_BLOCK, &chldmask, &savemask) < 0)
-    {
-      sigaction (SIGINT, &saveintr, NULL);
-      sigaction (SIGQUIT, &savequit, NULL);
-      return errno;
-    }
-
-#ifdef HAVE_VFORK
-  pid = vfork ();
-#else
-  pid = fork ();
-#endif
-
-  if (pid < 0)
-    {
-      err = errno;
-    }
-  else if (pid == 0)
-    {                          /* child */
-      /* restore previous signal actions & reset signal mask */
-      sigaction (SIGINT, &saveintr, NULL);
-      sigaction (SIGQUIT, &savequit, NULL);
-      sigprocmask (SIG_SETMASK, &savemask, NULL);
-
-      execvp (prog, av);
-#ifdef HAVE__EXIT      
-      _exit (127);             /* exec error */
-#else
-      exit (127);
-#endif
-    }
-  else
-    {                          /* parent */
-      while (waitpid (pid, &progstat, 0) < 0)
-       if (errno != EINTR)
-         {
-           err = errno;        /* error other than EINTR from waitpid() */
-           break;
-         }
-      if (err == 0 && stat)
-       *stat = progstat;
-    }
-
-  /* restore previous signal actions & reset signal mask */
-  /* preserve first error number, but still try and reset the signals */
-  if (sigaction (SIGINT, &saveintr, NULL) < 0)
-    err = err ? err : errno;
-  if (sigaction (SIGQUIT, &savequit, NULL) < 0)
-    err = err ? err : errno;
-  if (sigprocmask (SIG_SETMASK, &savemask, NULL) < 0)
-    err = err ? err : errno;
-
-  return err;
-}
-
-/* The result of readlink() may be a path relative to that link, 
- * qualify it if necessary.
- */
-static void
-mu_qualify_link (const char *path, const char *link, char *qualified)
-{
-  const char *lb = NULL;
-  size_t len;
-
-  /* link is full path */
-  if (*link == '/')
-    {
-      mu_cpystr (qualified, link, _POSIX_PATH_MAX);
-      return;
-    }
-
-  if ((lb = strrchr (path, '/')) == NULL)
-    {
-      /* no path in link */
-      mu_cpystr (qualified, link, _POSIX_PATH_MAX);
-      return;
-    }
-
-  len = lb - path + 1;
-  memcpy (qualified, path, len);
-  mu_cpystr (qualified + len, link, _POSIX_PATH_MAX - len);
-}
-
-#ifndef _POSIX_SYMLOOP_MAX
-# define _POSIX_SYMLOOP_MAX 255
-#endif
-
-int
-mu_unroll_symlink (char *out, size_t outsz, const char *in)
-{
-  char path[_POSIX_PATH_MAX];
-  int symloops = 0;
-
-  while (symloops++ < _POSIX_SYMLOOP_MAX)
-    {
-      struct stat s;
-      char link[_POSIX_PATH_MAX];
-      char qualified[_POSIX_PATH_MAX];
-      int len;
-
-      if (lstat (in, &s) == -1)
-       return errno;
-
-      if (!S_ISLNK (s.st_mode))
-       {
-         mu_cpystr (path, in, sizeof (path));
-         break;
-       }
-
-      if ((len = readlink (in, link, sizeof (link))) == -1)
-       return errno;
-
-      link[(len >= sizeof (link)) ? (sizeof (link) - 1) : len] = '\0';
-
-      mu_qualify_link (in, link, qualified);
-
-      mu_cpystr (path, qualified, sizeof (path));
-
-      in = path;
-    }
-
-  mu_cpystr (out, path, outsz);
-
-  return 0;
-}
-
-/* Expand a PATTERN to the pathname. PATTERN may contain the following
-   macro-notations:
-   ---------+------------ 
-   notation |  expands to
-   ---------+------------
-   %u         user name
-   %h         user's home dir
-   ~          Likewise
-   ---------+------------
-
-   Allocates memory. 
-*/
-char *
-mu_expand_path_pattern (const char *pattern, const char *username)
-{
-  const char *p;
-  char *q;
-  char *path;
-  size_t len = 0;
-  struct mu_auth_data *auth = NULL;
-  
-  for (p = pattern; *p; p++)
-    {
-      if (*p == '~')
-        {
-          if (!auth)
-            {
-              auth = mu_get_auth_by_name (username);
-              if (!auth)
-                return NULL;
-            }
-          len += strlen (auth->dir);
-        }
-      else if (*p == '%')
-       switch (*++p)
-         {
-         case 'u':
-           len += strlen (username);
-           break;
-           
-         case 'h':
-           if (!auth)
-             {
-               auth = mu_get_auth_by_name (username);
-               if (!auth)
-                 return NULL;
-             }
-           len += strlen (auth->dir);
-           break;
-           
-         case '%':
-           len++;
-           break;
-           
-         default:
-           len += 2;
-         }
-      else
-       len++;
-    }
-  
-  path = malloc (len + 1);
-  if (!path)
-    return NULL;
-
-  p = pattern;
-  q = path;
-  while (*p)
-    {
-      size_t off = strcspn (p, "~%");
-      memcpy (q, p, off);
-      q += off;
-      p += off;
-      if (*p == '~')
-       {
-         strcpy (q, auth->dir);
-         q += strlen (auth->dir);
-         p++;
-       }
-      else if (*p == '%')
-       {
-         switch (*++p)
-           {
-           case 'u':
-             strcpy (q, username);
-             q += strlen (username);
-             break;
-           
-           case 'h':
-             strcpy (q, auth->dir);
-             q += strlen (auth->dir);
-             break;
-         
-           case '%':
-             *q++ = '%';
-             break;
-         
-           default:
-             *q++ = '%';
-             *q++ = *p;
-           }
-         p++;
-       }
-    }
-
-  *q = 0;
-  if (auth)
-    mu_auth_data_free (auth);
-  return path;
-}
-
-#define ST_INIT  0
-#define ST_MSGID 1
-
-static int
-strip_message_id (char *msgid, char **pval)
-{
-  char *p, *q;
-  int state;
-  
-  *pval = strdup (msgid);
-  if (!*pval)
-    return ENOMEM;
-  state = ST_INIT;
-  for (p = q = *pval; *p; p++)
-    {
-      switch (state)
-       {
-       case ST_INIT:
-         if (*p == '<')
-           {
-             *q++ = *p;
-             state = ST_MSGID;
-           }
-         else if (isspace (*p))
-           *q++ = *p;
-         break;
-
-       case ST_MSGID:
-         *q++ = *p;
-         if (*p == '>')
-           state = ST_INIT;
-         break;
-       }
-    }
-  *q = 0;
-  return 0;
-}
-
-int
-get_msgid_header (mu_header_t hdr, const char *name, char **val)
-{
-  char *p;
-  int status = mu_header_aget_value (hdr, name, &p);
-  if (status)
-    return status;
-  status = strip_message_id (p, val);
-  free (p);
-  return status;
-}
-
-static char *
-concat (const char *s1, const char *s2)
-{
-  int len = (s1 ? strlen (s1) : 0) + (s2 ? strlen (s2) : 0) + 2;
-  char *s = malloc (len);
-  if (s)
-    {
-      char *p = s;
-      
-      if (s1)
-       {
-         strcpy (p, s1);
-         p += strlen (s1);
-         *p++ = ' ';
-       }
-      if (s2)
-       strcpy (p, s2);
-    }
-  return s;
-}
-
-/* rfc2822:
-   
-   The "References:" field will contain the contents of the parent's
-   "References:" field (if any) followed by the contents of the parent's
-   "Message-ID:" field (if any).  If the parent message does not contain
-   a "References:" field but does have an "In-Reply-To:" field
-   containing a single message identifier, then the "References:" field
-   will contain the contents of the parent's "In-Reply-To:" field
-   followed by the contents of the parent's "Message-ID:" field (if
-   any).  If the parent has none of the "References:", "In-Reply-To:",
-   or "Message-ID:" fields, then the new message will have no
-   References:" field. */
-
-int
-mu_rfc2822_references (mu_message_t msg, char **pstr)
-{
-  char *ref = NULL, *msgid = NULL;
-  mu_header_t hdr;
-  int rc;
-  
-  rc = mu_message_get_header (msg, &hdr);
-  if (rc)
-    return rc;
-  get_msgid_header (hdr, MU_HEADER_MESSAGE_ID, &msgid);
-  if (get_msgid_header (hdr, MU_HEADER_REFERENCES, &ref))
-    get_msgid_header (hdr, MU_HEADER_IN_REPLY_TO, &ref);
-
-  if (ref || msgid)
-    {
-      *pstr = concat (ref, msgid);
-      free (ref);
-      free (msgid);
-      return 0;
-    }
-  return MU_ERR_FAILURE;
-}
-
-int
-mu_rfc2822_msg_id (int subpart, char **pval)
-{
-  char date[4+2+2+2+2+2+1];
-  time_t t = time (NULL);
-  struct tm *tm = localtime (&t);
-  char *host;
-  char *p;
-         
-  mu_strftime (date, sizeof date, "%Y%m%d%H%M%S", tm);
-  mu_get_host_name (&host);
-
-  if (subpart)
-    {
-      struct timeval tv;
-      gettimeofday (&tv, NULL);
-      mu_asprintf (&p, "<address@hidden>",
-                  date,
-                  (unsigned long) getpid (),
-                  subpart,
-                  host);
-    }
-  else
-    mu_asprintf (&p, "<address@hidden>", date, (unsigned long) getpid (), 
host);
-  free (host);
-  *pval = p;
-  return 0;
-}
-
-#define DATEBUFSIZE 128
-#define COMMENT "Your message of "
-
-/*
-   The "In-Reply-To:" field will contain the contents of the "Message-
-   ID:" field of the message to which this one is a reply (the "parent
-   message").  If there is more than one parent message, then the "In-
-   Reply-To:" field will contain the contents of all of the parents'
-   "Message-ID:" fields.  If there is no "Message-ID:" field in any of
-   the parent messages, then the new message will have no "In-Reply-To:"
-   field.
-*/
-int
-mu_rfc2822_in_reply_to (mu_message_t msg, char **pstr)
-{
-  const char *value = NULL;
-  char *s1 = NULL, *s2 = NULL;
-  mu_header_t hdr;
-  int rc;
-  
-  rc = mu_message_get_header (msg, &hdr);
-  if (rc)
-    return rc;
-  
-  if (mu_header_sget_value (hdr, MU_HEADER_DATE, &value))
-    {
-      mu_envelope_t envelope = NULL;
-      mu_message_get_envelope (msg, &envelope);
-      mu_envelope_sget_date (envelope, &value);
-    }
-
-  if (value)
-    {
-      s1 = malloc (sizeof (COMMENT) + strlen (value));
-      if (!s1)
-       return ENOMEM;
-      strcat (strcpy (s1, COMMENT), value);
-    }
-  
-  if (mu_header_sget_value (hdr, MU_HEADER_MESSAGE_ID, &value) == 0)
-    {
-      s2 = malloc (strlen (value) + 3);
-      if (!s2)
-       {
-         free (s1);
-         return ENOMEM;
-       }
-      strcat (strcpy (s2, "\n\t"), value);
-    }
-
-  if (s1 || s2)
-    {
-      *pstr = concat (s1, s2);
-      free (s1);
-      free (s2);
-      return 0;
-    }
-  return MU_ERR_FAILURE;
-}
-
-/* Based on strstr from GNU libc (Stephen R. van den Berg,
-   address@hidden) */
-
-char *
-mu_strcasestr (const char *a_haystack, const char *a_needle)
-{
-  register const unsigned char *haystack = (unsigned char*) a_haystack,
-    *needle = (unsigned char*) a_needle;
-  register unsigned int b, c;
-
-#define U(c) mu_toupper (c)
-  if ((b = U (*needle)))
-    {
-      haystack--;              
-      do
-       {
-         if (!(c = *++haystack))
-           goto ret0;
-       }
-      while (U (c) != b);
-
-      if (!(c = *++needle))
-       goto foundneedle;
-
-      c = U (c);
-      ++needle;
-      goto jin;
-
-      for (;;)
-        { 
-          register unsigned int a;
-         register const unsigned char *rhaystack, *rneedle;
-
-         do
-           {
-             if (!(a = *++haystack))
-               goto ret0;
-             if (U (a) == b)
-               break;
-             if (!(a = *++haystack))
-               goto ret0;
-shloop:       ;
-            }
-          while (U (a) != b);
-         
-jin:     if (!(a = *++haystack))
-           goto ret0;
-
-         if (U (a) != c)
-           goto shloop;
-
-         if (U (*(rhaystack = haystack-- + 1)) ==
-             (a = U (*(rneedle = needle))))
-           do
-             {
-               if (!a)
-                 goto foundneedle;
-               if (U (*++rhaystack) != (a = U (*++needle)))
-                 break;
-               if (!a)
-                 goto foundneedle;
-             }
-           while (U (*++rhaystack) == (a = U (*++needle)));
-
-         needle = rneedle;
-
-         if (!a)
-           break;
-        }
-    }
-foundneedle:
-  return (char*)haystack;
-ret0:
-  return NULL;
-
-#undef U
-}  
-
-int
-mu_string_unfold (char *text, size_t *plen)
-{
-  char *p, *q;
-  enum uf_state { uf_init, uf_nl, uf_fold } state = uf_init;
-#define ISSPACE(c) (c == '\r' || c == ' ' || c == '\t')
-  
-  if (!text)
-    return EINVAL;
-  
-  for (p = q = text; *q; q++)
-    {
-      switch (state)
-       {
-       case uf_init:
-         if (*q == '\n')
-           state = uf_nl;
-         else
-           *p++ = *q;
-         break;
-
-       case uf_nl:
-         if (ISSPACE (*q))
-           state = uf_fold;
-         else
-           {
-             state = uf_init;
-             *p++ = *q;
-           }
-         break;
-
-       case uf_fold:
-         if (!ISSPACE (*q))
-           {
-             *p++ = ' ';
-             *p++ = *q;
-             state = uf_init;
-           }
-         break;
-       }
-    }
-  
-  *p++ = 0;
-  if (plen)
-    *plen = p - text;
-  return 0;
-}
-
-int
-mu_true_answer_p (const char *p)
-{
-  if (!p)
-    return -1;
-
-  while (*p && isspace (*p))
-    p++;
-
-  if (*p)
-    {
-      /* TRANSLATORS: This is a list of characters which start
-        an affirmative answer. Whenever possible, please preserve
-        'yY' in your translation, e.g., for Euskara:
-
-        msgstr "yYbB";
-      */
-      if (strchr (_("yY"), *p))
-       return 1;
-
-      /* TRANSLATORS: This is a list of characters which start
-        a negative answer. Whenever possible, please preserve
-        'nN' in your translation, e.g., for Euskara:
-
-        msgstr "nNeE";
-      */
-      else if (strchr (_("nN"), *p))
-       return 0;
-    }
-  return -1;
-}
-
-/* Returns true if SCHEME represents a local (autodetect) mail folder.  */
-int
-mu_scheme_autodetect_p (mu_url_t url)
-{
-  if (mu_url_is_scheme (url, "file"))
-    {
-      mu_url_expand_path (url);
-      return 1;
-    }
-  return 0;
-}
-    
-int
-mu_fd_wait (int fd, int *pflags, struct timeval *tvp)
-{
-  fd_set rdset, wrset, exset;
-  int rc;
-
-  FD_ZERO (&rdset);
-  FD_ZERO (&wrset);
-  FD_ZERO (&exset);
-  if ((*pflags) & MU_STREAM_READY_RD)
-    FD_SET (fd, &rdset);
-  if ((*pflags) & MU_STREAM_READY_WR)
-    FD_SET (fd, &wrset);
-  if ((*pflags) & MU_STREAM_READY_EX)
-    FD_SET (fd, &exset);
-  
-  do
-    {
-      if (tvp)
-       {
-         struct timeval tv = *tvp; 
-         rc = select (fd + 1, &rdset, &wrset, &exset, &tv);
-       }
-      else
-       rc = select (fd + 1, &rdset, &wrset, &exset, NULL);
-    }
-  while (rc == -1 && errno == EINTR);
-
-  if (rc < 0)
-    return errno;
-  
-  *pflags = 0;
-  if (rc > 0)
-    {
-      if (FD_ISSET (fd, &rdset))
-       *pflags |= MU_STREAM_READY_RD;
-      if (FD_ISSET (fd, &wrset))
-       *pflags |= MU_STREAM_READY_WR;
-      if (FD_ISSET (fd, &exset))
-       *pflags |= MU_STREAM_READY_EX;
-    }
-  return 0;
-}
-
-enum mu_iconv_fallback_mode mu_default_fallback_mode = mu_fallback_copy_octal;
-
-int
-mu_set_default_fallback (const char *str)
-{
-  if (strcmp (str, "none") == 0)
-    mu_default_fallback_mode = mu_fallback_none;
-  else if (strcmp (str, "copy-pass") == 0)
-    mu_default_fallback_mode = mu_fallback_copy_pass;
-  else if (strcmp (str, "copy-octal") == 0)
-    mu_default_fallback_mode = mu_fallback_copy_octal;
-  else
-    return EINVAL;
-  return 0;
-}
-
-int
-mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
-                 const char *filter_type,
-                 const char *fromcode, const char *tocode)
-{
-  mu_stream_t filter;
-  
-  int status = mu_filter_create (&filter, input, filter_type,
-                                MU_FILTER_DECODE, MU_STREAM_READ);
-  if (status)
-    return status;
-
-  if (fromcode && tocode && mu_c_strcasecmp (fromcode, tocode))
-    {
-      mu_stream_t cvt;
-
-      status = mu_filter_iconv_create (&cvt, filter, fromcode, tocode,
-                                      0, mu_default_fallback_mode);
-      if (status == 0)
-       {
-          mu_stream_unref (filter);
-          filter = cvt;
-       }
-    }
-  *pfilter = filter;
-  return 0;
-}
 
 int
 mu_is_proto (const char *p)
@@ -1414,20 +55,13 @@ mu_mh_delim (const char *str)
   return str[0] == '\n';
 }
 
-char *
-__argp_base_name (const char *arg)
-{
-  char *p = strrchr (arg, '/');
-  return (char *)(p ? p + 1 : arg);
-}
-
 /* A locale-independent version of strftime */
 size_t
 mu_strftime (char *s, size_t max, const char *format, const struct tm *tm)
 {
   size_t size;
   mu_set_locale ("C");
-  size = strftime(s, max, format, tm);
+  size = strftime (s, max, format, tm);
   mu_restore_locale ();
   return size;
 }
diff --git a/libmailutils/base/parsedate.y b/libmailutils/base/parsedate.y
index 98c932b..90f0681 100644
--- a/libmailutils/base/parsedate.y
+++ b/libmailutils/base/parsedate.y
@@ -610,7 +610,7 @@ o_merid     : /* empty */
 # endif
 #endif
 
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 /* Month and day table. */
 static SYMBOL const month_day_tab[] = {
diff --git a/libmailutils/base/permstr.c b/libmailutils/base/permstr.c
index ae16ff6..f49b27b 100644
--- a/libmailutils/base/permstr.c
+++ b/libmailutils/base/permstr.c
@@ -19,7 +19,7 @@
 # include <config.h>
 #endif
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 
 #define FILE_PERM_READ 0x1
diff --git a/libmailutils/base/registrar.c b/libmailutils/base/registrar.c
index 33782e9..d24aac2 100644
--- a/libmailutils/base/registrar.c
+++ b/libmailutils/base/registrar.c
@@ -34,7 +34,7 @@
 #include <mailutils/nls.h>
 #include <mailutils/error.h>
 #include <mailutils/url.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/sys/registrar.h>
 
 /* NOTE: We will leak here since the monitor and the registrar will never
diff --git a/libmailutils/base/rfc2047.c b/libmailutils/base/rfc2047.c
index 32b0923..29b3c4c 100644
--- a/libmailutils/base/rfc2047.c
+++ b/libmailutils/base/rfc2047.c
@@ -28,7 +28,7 @@
 #include <mailutils/stream.h>
 #include <mailutils/filter.h>
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 static int
 realloc_buffer (char **bufp, size_t *bufsizep, size_t incr)
diff --git a/libmailutils/diag/dbgsyslog.c b/libmailutils/base/schemeauto.c
similarity index 68%
copy from libmailutils/diag/dbgsyslog.c
copy to libmailutils/base/schemeauto.c
index af6f2fe..c82faae 100644
--- a/libmailutils/diag/dbgsyslog.c
+++ b/libmailutils/base/schemeauto.c
@@ -1,5 +1,6 @@
+/* Returns true if SCHEME represents a local (autodetect) mail folder.  */
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 Free Software
+   Copyright (C) 1999, 2000, 2001, 2007, 2008, 2009, 2010 Free Software
    Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
@@ -20,14 +21,17 @@
 # include <config.h>
 #endif
 
-#include <mailutils/debug.h>
-#include <syslog.h>
+#include <mailutils/url.h>
 
+/* Returns true if SCHEME represents a local (autodetect) mail folder.  */
 int
-mu_debug_syslog_printer (void *unused, mu_log_level_t level, const char *str)
+mu_scheme_autodetect_p (mu_url_t url)
 {
-  syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str);
+  if (mu_url_is_scheme (url, "file"))
+    {
+      mu_url_expand_path (url);
+      return 1;
+    }
   return 0;
 }
-
-
+    
diff --git a/libmailutils/base/spawnvp.c b/libmailutils/base/spawnvp.c
new file mode 100644
index 0000000..25d7059
--- /dev/null
+++ b/libmailutils/base/spawnvp.c
@@ -0,0 +1,120 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+/* See Advanced Programming in the UNIX Environment, Stevens,
+ * program  10.20 for the rational for the signal handling. I
+ * had to look it up, so if somebody else is curious, thats where
+ * to find it.
+ */
+int 
+mu_spawnvp (const char *prog, char *av[], int *stat)
+{
+  pid_t pid;
+  int err = 0;
+  int progstat;
+  struct sigaction ignore;
+  struct sigaction saveintr;
+  struct sigaction savequit;
+  sigset_t chldmask;
+  sigset_t savemask;
+
+  if (!prog || !av)
+    return EINVAL;
+
+  ignore.sa_handler = SIG_IGN; /* ignore SIGINT and SIGQUIT */
+  ignore.sa_flags = 0;
+  sigemptyset (&ignore.sa_mask);
+
+  if (sigaction (SIGINT, &ignore, &saveintr) < 0)
+    return errno;
+  if (sigaction (SIGQUIT, &ignore, &savequit) < 0)
+    {
+      sigaction (SIGINT, &saveintr, NULL);
+      return errno;
+    }
+
+  sigemptyset (&chldmask);     /* now block SIGCHLD */
+  sigaddset (&chldmask, SIGCHLD);
+
+  if (sigprocmask (SIG_BLOCK, &chldmask, &savemask) < 0)
+    {
+      sigaction (SIGINT, &saveintr, NULL);
+      sigaction (SIGQUIT, &savequit, NULL);
+      return errno;
+    }
+
+#ifdef HAVE_VFORK
+  pid = vfork ();
+#else
+  pid = fork ();
+#endif
+
+  if (pid < 0)
+    {
+      err = errno;
+    }
+  else if (pid == 0)
+    {                          /* child */
+      /* restore previous signal actions & reset signal mask */
+      sigaction (SIGINT, &saveintr, NULL);
+      sigaction (SIGQUIT, &savequit, NULL);
+      sigprocmask (SIG_SETMASK, &savemask, NULL);
+
+      execvp (prog, av);
+#ifdef HAVE__EXIT      
+      _exit (127);             /* exec error */
+#else
+      exit (127);
+#endif
+    }
+  else
+    {                          /* parent */
+      while (waitpid (pid, &progstat, 0) < 0)
+       if (errno != EINTR)
+         {
+           err = errno;        /* error other than EINTR from waitpid() */
+           break;
+         }
+      if (err == 0 && stat)
+       *stat = progstat;
+    }
+
+  /* restore previous signal actions & reset signal mask */
+  /* preserve first error number, but still try and reset the signals */
+  if (sigaction (SIGINT, &saveintr, NULL) < 0)
+    err = err ? err : errno;
+  if (sigaction (SIGQUIT, &savequit, NULL) < 0)
+    err = err ? err : errno;
+  if (sigprocmask (SIG_SETMASK, &savemask, NULL) < 0)
+    err = err ? err : errno;
+
+  return err;
+}
+
diff --git a/libmailutils/base/symlink.c b/libmailutils/base/symlink.c
new file mode 100644
index 0000000..7551a46
--- /dev/null
+++ b/libmailutils/base/symlink.c
@@ -0,0 +1,103 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <mailutils/types.h>
+#include <mailutils/util.h>
+
+/* The result of readlink() may be a path relative to that link, 
+ * qualify it if necessary.
+ */
+static void
+mu_qualify_link (const char *path, const char *link, char *qualified)
+{
+  const char *lb = NULL;
+  size_t len;
+
+  /* link is full path */
+  if (*link == '/')
+    {
+      mu_cpystr (qualified, link, _POSIX_PATH_MAX);
+      return;
+    }
+
+  if ((lb = strrchr (path, '/')) == NULL)
+    {
+      /* no path in link */
+      mu_cpystr (qualified, link, _POSIX_PATH_MAX);
+      return;
+    }
+
+  len = lb - path + 1;
+  memcpy (qualified, path, len);
+  mu_cpystr (qualified + len, link, _POSIX_PATH_MAX - len);
+}
+
+#ifndef _POSIX_SYMLOOP_MAX
+# define _POSIX_SYMLOOP_MAX 255
+#endif
+
+int
+mu_unroll_symlink (char *out, size_t outsz, const char *in)
+{
+  char path[_POSIX_PATH_MAX];
+  int symloops = 0;
+
+  while (symloops++ < _POSIX_SYMLOOP_MAX)
+    {
+      struct stat s;
+      char link[_POSIX_PATH_MAX];
+      char qualified[_POSIX_PATH_MAX];
+      int len;
+
+      if (lstat (in, &s) == -1)
+       return errno;
+
+      if (!S_ISLNK (s.st_mode))
+       {
+         mu_cpystr (path, in, sizeof (path));
+         break;
+       }
+
+      if ((len = readlink (in, link, sizeof (link))) == -1)
+       return errno;
+
+      link[(len >= sizeof (link)) ? (sizeof (link) - 1) : len] = '\0';
+
+      mu_qualify_link (in, link, qualified);
+
+      mu_cpystr (path, qualified, sizeof (path));
+
+      in = path;
+    }
+
+  mu_cpystr (out, path, outsz);
+
+  return 0;
+}
+
diff --git a/libmailutils/base/tempfile.c b/libmailutils/base/tempfile.c
new file mode 100644
index 0000000..cbd6d96
--- /dev/null
+++ b/libmailutils/base/tempfile.c
@@ -0,0 +1,104 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <mailutils/nls.h>
+#include <mailutils/io.h>
+#include <mailutils/error.h>
+#include <mailutils/errno.h>
+
+/* Create and open a temporary file. Be very careful about it, since we
+   may be running with extra privilege i.e setgid().
+   Returns file descriptor of the open file.
+   If namep is not NULL, the pointer to the malloced file name will
+   be stored there. Otherwise, the file is unlinked right after open,
+   i.e. it will disappear after close(fd). */
+
+#ifndef P_tmpdir
+# define P_tmpdir "/tmp"
+#endif
+
+int
+mu_tempfile (const char *tmpdir, char **namep)
+{
+  char *filename;
+  int fd;
+  
+  if (!tmpdir)
+    tmpdir = (getenv ("TMPDIR")) ? getenv ("TMPDIR") : P_tmpdir;
+
+  if (mu_asprintf (&filename, "%s/muXXXXXX", tmpdir))
+    return -1;
+
+#ifdef HAVE_MKSTEMP
+  {
+    int save_mask = umask (077);
+    fd = mkstemp (filename);
+    umask (save_mask);
+  }
+#else
+  if (mktemp (filename))
+    fd = open (filename, O_CREAT|O_EXCL|O_RDWR, 0600);
+  else
+    fd = -1;
+#endif
+
+  if (fd == -1)
+    {
+      mu_error (_("cannot open temporary file: %s"), mu_strerror (errno));
+      free (filename);
+      return -1;
+    }
+
+  if (namep)
+    *namep = filename;
+  else
+    {
+      unlink (filename);
+      free (filename);
+    }
+
+  return fd;
+}
+
+/* Create a unique temporary file name in tmpdir. The function
+   creates an empty file with this name to avoid possible race
+   conditions. Returns a pointer to the malloc'ed file name.
+   If tmpdir is NULL, the value of the environment variable
+   TMPDIR or the hardcoded P_tmpdir is used, whichever is defined. */
+/* FIXME: Remove it. Use mu_tempfile instead. */
+char *
+mu_tempname (const char *tmpdir)
+{
+  char *filename = NULL;
+  int fd = mu_tempfile (tmpdir, &filename);
+  close (fd);
+  return filename;
+}
+
+
diff --git a/libmailutils/base/ticket.c b/libmailutils/base/ticket.c
index 4e12b56..1e26c26 100644
--- a/libmailutils/base/ticket.c
+++ b/libmailutils/base/ticket.c
@@ -28,7 +28,7 @@
 #include <stdio.h>
 #include <termios.h>
 
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 #include <mailutils/secret.h>
 #include <mailutils/sys/auth.h>
diff --git a/libmailutils/base/tilde.c b/libmailutils/base/tilde.c
new file mode 100644
index 0000000..87576b7
--- /dev/null
+++ b/libmailutils/base/tilde.c
@@ -0,0 +1,119 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/types.h>
+#include <mailutils/cctype.h>
+#include <mailutils/util.h>
+#include <mailutils/mu_auth.h>
+
+/* NOTE: Allocates Memory.  */
+/* Expand: ~ --> /home/user and to ~guest --> /home/guest.  */
+char *
+mu_tilde_expansion (const char *ref, const char *delim, const char *homedir)
+{
+  char *base = strdup (ref);
+  char *home = NULL;
+  char *proto = NULL;
+  size_t proto_len = 0;
+  char *p;
+
+  for (p = base; *p && mu_isascii (*p) && mu_isalnum (*p); p++)
+    ;
+  
+  if (*p == ':')
+    {
+      p++;
+      proto_len = p - base;
+      proto = malloc (proto_len + 1);
+      if (!proto)
+       return NULL;
+      memcpy (proto, base, proto_len);
+      proto[proto_len] = 0;
+      /* Allow for extra pair of slashes after the protocol specifier */
+      if (*p == delim[0])
+       p++;
+      if (*p == delim[0])
+       p++;
+    }
+  else
+    p = base;
+  
+  if (*p == '~')
+    {
+      p++;
+      if (*p == delim[0] || *p == '\0')
+        {
+         char *s;
+         if (!homedir)
+           {
+             home = mu_get_homedir ();
+             if (!home)
+               return base;
+             homedir = home;
+           }
+         s = calloc (proto_len + strlen (homedir) + strlen (p) + 1, 1);
+         if (proto_len)
+           strcpy (s, proto);
+         else
+           s[0] = 0;
+          strcat (s, homedir);
+          strcat (s, p);
+          free (base);
+          base = s;
+        }
+      else
+        {
+          struct mu_auth_data *auth;
+          char *s = p;
+          char *name;
+          while (*s && *s != delim[0])
+            s++;
+          name = calloc (s - p + 1, 1);
+          memcpy (name, p, s - p);
+          name[s - p] = '\0';
+         
+          auth = mu_get_auth_by_name (name);
+          free (name);
+          if (auth)
+            {
+              char *buf = calloc (proto_len + strlen (auth->dir)
+                                 + strlen (s) + 1, 1);
+             if (proto_len)
+               strcpy (buf, proto);
+             else
+               buf[0] = 0;
+             strcat (buf, auth->dir);
+              strcat (buf, s);
+              free (base);
+              base = buf;
+             mu_auth_data_free (auth);
+            }
+        }
+    }
+  if (home)
+    free (home);
+  return base;
+}
+
diff --git a/libmailutils/base/url.c b/libmailutils/base/url.c
index 554eb8a..d177fa7 100644
--- a/libmailutils/base/url.c
+++ b/libmailutils/base/url.c
@@ -28,7 +28,7 @@
 # include <strings.h>
 #endif
 
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 #include <mailutils/argcv.h>
 #include <mailutils/secret.h>
diff --git a/libmailutils/base/usremail.c b/libmailutils/base/usremail.c
new file mode 100644
index 0000000..3af6062
--- /dev/null
+++ b/libmailutils/base/usremail.c
@@ -0,0 +1,196 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <mailutils/types.h>
+#include <mailutils/address.h>
+#include <mailutils/mu_auth.h>
+#include <mailutils/util.h>
+#include <mailutils/parse822.h>
+
+/*
+ * Functions used to convert unix mailbox/user names into RFC822 addr-specs.
+ */
+
+static char *mu_user_email = 0;
+
+int
+mu_set_user_email (const char *candidate)
+{
+  int err = 0;
+  mu_address_t addr = NULL;
+  size_t emailno = 0;
+  char *email = NULL;
+  const char *domain = NULL;
+  
+  if ((err = mu_address_create (&addr, candidate)) != 0)
+    return err;
+
+  if ((err = mu_address_get_email_count (addr, &emailno)) != 0)
+    goto cleanup;
+
+  if (emailno != 1)
+    {
+      errno = EINVAL;
+      goto cleanup;
+    }
+
+  if ((err = mu_address_aget_email (addr, 1, &email)) != 0)
+    goto cleanup;
+
+  if (mu_user_email)
+    free (mu_user_email);
+
+  mu_user_email = email;
+
+  if ((err = mu_address_sget_domain (addr, 1, &domain)) == 0)
+    mu_set_user_email_domain (domain);
+  
+cleanup:
+  mu_address_destroy (&addr);
+
+  return err;
+}
+
+static char *mu_user_email_domain = 0;
+
+int
+mu_set_user_email_domain (const char *domain)
+{
+  char *d = NULL;
+  
+  if (!domain)
+    return EINVAL;
+  
+  d = strdup (domain);
+
+  if (!d)
+    return ENOMEM;
+
+  if (mu_user_email_domain)
+    free (mu_user_email_domain);
+
+  mu_user_email_domain = d;
+
+  return 0;
+}
+
+/* FIXME: must be called _sget_ */
+int
+mu_get_user_email_domain (const char **domain)
+{
+  int err = 0;
+
+  if (!mu_user_email_domain)
+    {
+      if ((err = mu_get_host_name (&mu_user_email_domain)))
+       return err;
+    }
+
+  *domain = mu_user_email_domain;
+
+  return 0;
+}
+
+int
+mu_aget_user_email_domain (char **pdomain)
+{
+  const char *domain;
+  int status = mu_get_user_email_domain (&domain);
+  if (status)
+    return status;
+  if (domain == NULL)
+    *pdomain = NULL;
+  else
+    {
+      *pdomain = strdup (domain);
+      if (*pdomain == NULL)
+       return ENOMEM;
+    }
+  return 0;
+}
+
+/* Note: allocates memory */
+char *
+mu_get_user_email (const char *name)
+{
+  int status = 0;
+  char *localpart = NULL;
+  const char *domainpart = NULL;
+  char *email = NULL;
+  char *tmpname = NULL;
+
+  if (!name && mu_user_email)
+    {
+      email = strdup (mu_user_email);
+      if (!email)
+       errno = ENOMEM;
+      return email;
+    }
+
+  if (!name)
+    {
+      struct mu_auth_data *auth = mu_get_auth_by_uid (getuid ());
+      if (!auth)
+       {
+         errno = EINVAL;
+         return NULL;
+       }
+      name = tmpname = strdup(auth->name);
+      if (auth)
+       mu_auth_data_free (auth);
+    }
+
+  status = mu_get_user_email_domain (&domainpart);
+
+  if (status)
+    {
+      free(tmpname);
+      errno = status;
+      return NULL;
+    }
+
+  if ((status = mu_parse822_quote_local_part (&localpart, name)))
+    {
+      free(tmpname);
+      errno = status;
+      return NULL;
+    }
+
+
+  email = malloc (strlen (localpart) + 1
+                 + strlen (domainpart) + 1);
+  if (!email)
+    errno = ENOMEM;
+  else
+    sprintf (email, "address@hidden", localpart, domainpart);
+
+  free(tmpname);
+  free (localpart);
+
+  return email;
+}
diff --git a/libmailutils/base/wicket.c b/libmailutils/base/wicket.c
index 1e6a657..705e69a 100644
--- a/libmailutils/base/wicket.c
+++ b/libmailutils/base/wicket.c
@@ -31,7 +31,7 @@
 #include <ctype.h>
 
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mu_auth.h>
 #include <mailutils/stream.h>
 
diff --git a/libmailutils/cfg/driver.c b/libmailutils/cfg/driver.c
index 33683d4..de34729 100644
--- a/libmailutils/cfg/driver.c
+++ b/libmailutils/cfg/driver.c
@@ -31,7 +31,7 @@
 #include <mailutils/cfg.h>
 #include <mailutils/errno.h>
 #include <mailutils/error.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/monitor.h>
 #include <mailutils/refcount.h>
 #include <mailutils/list.h>
diff --git a/libmailutils/cfg/gocs.c b/libmailutils/cfg/gocs.c
index e6b14b4..7976aa2 100644
--- a/libmailutils/cfg/gocs.c
+++ b/libmailutils/cfg/gocs.c
@@ -24,7 +24,7 @@
 #include <mailutils/gocs.h>
 #include <mailutils/mailbox.h>
 #include <mailutils/locker.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mailer.h>
 #include <mailutils/error.h>
 #include <mailutils/errno.h>
diff --git a/libmailutils/cfg/lexer.l b/libmailutils/cfg/lexer.l
index 83e8351..67c1199 100644
--- a/libmailutils/cfg/lexer.l
+++ b/libmailutils/cfg/lexer.l
@@ -37,7 +37,7 @@
 #include <mailutils/nls.h>
 #include <mailutils/cfg.h>
 #include <mailutils/list.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
   
 #include "parser.h"
 
diff --git a/libmailutils/cfg/parser.y b/libmailutils/cfg/parser.y
index 8c8e060..9fe5b1b 100644
--- a/libmailutils/cfg/parser.y
+++ b/libmailutils/cfg/parser.y
@@ -35,7 +35,7 @@
 #include <mailutils/list.h>
 #include <mailutils/iterator.h>
 #include <mailutils/debug.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cctype.h>
 
 int mu_cfg_parser_verbose;
diff --git a/libmailutils/filter/Makefile.am b/libmailutils/filter/Makefile.am
index 08082bb..3d459c6 100644
--- a/libmailutils/filter/Makefile.am
+++ b/libmailutils/filter/Makefile.am
@@ -22,6 +22,7 @@ libfilter_la_SOURCES =\
  binflt.c\
  crlfdot.c\
  crlfflt.c\
+ decode.c\
  dot.c\
  filter.c\
  filter_iconv.c\
diff --git a/libmailutils/filter/decode.c b/libmailutils/filter/decode.c
new file mode 100644
index 0000000..56e7a59
--- /dev/null
+++ b/libmailutils/filter/decode.c
@@ -0,0 +1,73 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <mailutils/stream.h>
+#include <mailutils/filter.h>
+#include <mailutils/cstr.h>
+
+enum mu_iconv_fallback_mode mu_default_fallback_mode = mu_fallback_copy_octal;
+
+int
+mu_set_default_fallback (const char *str)
+{
+  if (strcmp (str, "none") == 0)
+    mu_default_fallback_mode = mu_fallback_none;
+  else if (strcmp (str, "copy-pass") == 0)
+    mu_default_fallback_mode = mu_fallback_copy_pass;
+  else if (strcmp (str, "copy-octal") == 0)
+    mu_default_fallback_mode = mu_fallback_copy_octal;
+  else
+    return EINVAL;
+  return 0;
+}
+
+int
+mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
+                 const char *filter_type,
+                 const char *fromcode, const char *tocode)
+{
+  mu_stream_t filter;
+  
+  int status = mu_filter_create (&filter, input, filter_type,
+                                MU_FILTER_DECODE, MU_STREAM_READ);
+  if (status)
+    return status;
+
+  if (fromcode && tocode && mu_c_strcasecmp (fromcode, tocode))
+    {
+      mu_stream_t cvt;
+
+      status = mu_filter_iconv_create (&cvt, filter, fromcode, tocode,
+                                      0, mu_default_fallback_mode);
+      if (status == 0)
+       {
+          mu_stream_unref (filter);
+          filter = cvt;
+       }
+    }
+  *pfilter = filter;
+  return 0;
+}
+
diff --git a/libmailutils/mailbox/attribute.c b/libmailutils/mailbox/attribute.c
index 37e479a..c4e5808 100644
--- a/libmailutils/mailbox/attribute.c
+++ b/libmailutils/mailbox/attribute.c
@@ -30,7 +30,7 @@
 #endif
 
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 #include <mailutils/sys/attribute.h>
 
diff --git a/libmailutils/mailbox/body.c b/libmailutils/mailbox/body.c
index b4cf22b..e2c2bcd 100644
--- a/libmailutils/mailbox/body.c
+++ b/libmailutils/mailbox/body.c
@@ -30,7 +30,7 @@
 #include <fcntl.h>
 
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 #include <mailutils/sys/stream.h>
 #include <mailutils/sys/body.h>
diff --git a/libmailutils/mailbox/envelope.c b/libmailutils/mailbox/envelope.c
index 9546885..d50e4df 100644
--- a/libmailutils/mailbox/envelope.c
+++ b/libmailutils/mailbox/envelope.c
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/sys/envelope.h>
 
 int
diff --git a/libmailutils/mailbox/header.c b/libmailutils/mailbox/header.c
index 6de32d2..6ce70d1 100644
--- a/libmailutils/mailbox/header.c
+++ b/libmailutils/mailbox/header.c
@@ -42,7 +42,7 @@
 
 #include <mailutils/stream.h>
 #include <mailutils/address.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 #include <mailutils/cstr.h>
 #include <mailutils/sys/header_stream.h>
diff --git a/libmailutils/mailbox/mailbox.c b/libmailutils/mailbox/mailbox.c
index fcf2243..d95ce2d 100644
--- a/libmailutils/mailbox/mailbox.c
+++ b/libmailutils/mailbox/mailbox.c
@@ -38,7 +38,7 @@
 #include <mailutils/url.h>
 #include <mailutils/attribute.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #include <mailutils/sys/mailbox.h>
 #include <mailutils/sys/url.h>
diff --git a/libmailutils/mailbox/mbx_default.c 
b/libmailutils/mailbox/mbx_default.c
index 9069c6f..468230a 100644
--- a/libmailutils/mailbox/mbx_default.c
+++ b/libmailutils/mailbox/mbx_default.c
@@ -30,7 +30,7 @@
 #include <confpaths.h>
 
 #include <mailutils/mailbox.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/debug.h>
 #include <mailutils/error.h>
 #include <mailutils/errno.h>
diff --git a/libmailutils/mailbox/message.c b/libmailutils/mailbox/message.c
index b6f81b7..f415583 100644
--- a/libmailutils/mailbox/message.c
+++ b/libmailutils/mailbox/message.c
@@ -41,7 +41,7 @@
 #include <mailutils/folder.h>
 #include <mailutils/header.h>
 #include <mailutils/mailbox.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/observer.h>
 #include <mailutils/stream.h>
 #include <mailutils/mu_auth.h>
diff --git a/libmailutils/mailer/mailer.c b/libmailutils/mailer/mailer.c
index 35c9862..6c0ce9a 100644
--- a/libmailutils/mailer/mailer.c
+++ b/libmailutils/mailer/mailer.c
@@ -45,7 +45,7 @@
 #include <mailutils/mailbox.h>
 #include <mailutils/message.h>
 #include <mailutils/argcv.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mime.h>
 #include <mailutils/io.h>
 
diff --git a/libmailutils/mailer/progmailer.c b/libmailutils/mailer/progmailer.c
index 6411cf0..a433106 100644
--- a/libmailutils/mailer/progmailer.c
+++ b/libmailutils/mailer/progmailer.c
@@ -39,7 +39,7 @@
 #include <mailutils/body.h>
 #include <mailutils/message.h>
 #include <mailutils/progmailer.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 
 struct _mu_progmailer
diff --git a/libmailutils/mime/attachment.c b/libmailutils/mime/attachment.c
index e877cb7..e4a09e3 100644
--- a/libmailutils/mime/attachment.c
+++ b/libmailutils/mime/attachment.c
@@ -42,7 +42,7 @@
 #include <mailutils/message.h>
 #include <mailutils/stream.h>
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #define BUF_SIZE       2048
 
diff --git a/libmailutils/mime/mime.c b/libmailutils/mime/mime.c
index 17c5441..165d337 100644
--- a/libmailutils/mime/mime.c
+++ b/libmailutils/mime/mime.c
@@ -37,7 +37,7 @@
 #include <mailutils/body.h>
 #include <mailutils/header.h>
 #include <mailutils/errno.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #include <mailutils/sys/mime.h>
 #include <mailutils/sys/stream.h>
diff --git a/libmailutils/mime/mimehdr.c b/libmailutils/mime/mimehdr.c
index dd5eb34..7bc801b 100644
--- a/libmailutils/mime/mimehdr.c
+++ b/libmailutils/mime/mimehdr.c
@@ -33,7 +33,7 @@
                              be renamed! */
 #include <mailutils/mime.h>
 #include <mailutils/filter.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 /* See RFC 2045, 5.1.  Syntax of the Content-Type Header Field */
 #define _ISSPECIAL(c) !!strchr ("()<>@,;:\\\"/[]?=", c)
diff --git a/libmailutils/stream/file_stream.c 
b/libmailutils/stream/file_stream.c
index e6a6e67..6f9723a 100644
--- a/libmailutils/stream/file_stream.c
+++ b/libmailutils/stream/file_stream.c
@@ -35,7 +35,7 @@
 #include <mailutils/stream.h>
 #include <mailutils/sys/stream.h>
 #include <mailutils/sys/file_stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #define MU_FSTR_ERROR_NOREG (MU_ERR_LAST+1)
 
diff --git a/libmailutils/stream/memory_stream.c 
b/libmailutils/stream/memory_stream.c
index 67952bc..ed599dc 100644
--- a/libmailutils/stream/memory_stream.c
+++ b/libmailutils/stream/memory_stream.c
@@ -30,7 +30,7 @@
 #include <mailutils/nls.h>
 #include <mailutils/stream.h>
 #include <mailutils/sys/memory_stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 static void
 _memory_done (mu_stream_t stream)
diff --git a/libmailutils/stream/message_stream.c 
b/libmailutils/stream/message_stream.c
index 91bef83..a404ccd 100644
--- a/libmailutils/stream/message_stream.c
+++ b/libmailutils/stream/message_stream.c
@@ -35,7 +35,7 @@
 #include <mailutils/header.h>
 #include <mailutils/body.h>
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 #include <mailutils/error.h>
 #include <mailutils/cctype.h>
diff --git a/libmailutils/stream/prog_stream.c 
b/libmailutils/stream/prog_stream.c
index b789def..437bf01 100644
--- a/libmailutils/stream/prog_stream.c
+++ b/libmailutils/stream/prog_stream.c
@@ -35,7 +35,7 @@
 #include <mailutils/stream.h>
 #include <mailutils/sys/stream.h>
 #include <mailutils/sys/prog_stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 static mu_list_t prog_stream_list;
 
diff --git a/libmailutils/stream/tcp.c b/libmailutils/stream/tcp.c
index eafd40b..b53511a 100644
--- a/libmailutils/stream/tcp.c
+++ b/libmailutils/stream/tcp.c
@@ -37,7 +37,7 @@
 
 #include <mailutils/errno.h>
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 #include <mailutils/sys/stream.h>
 
diff --git a/libmailutils/stream/temp_file_stream.c 
b/libmailutils/stream/temp_file_stream.c
index fb178a5..29ca359 100644
--- a/libmailutils/stream/temp_file_stream.c
+++ b/libmailutils/stream/temp_file_stream.c
@@ -30,7 +30,7 @@
 #include <mailutils/stream.h>
 #include <mailutils/sys/stream.h>
 #include <mailutils/sys/file_stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 
 static int
diff --git a/libmailutils/string/Makefile.am b/libmailutils/string/Makefile.am
index 52452b9..3f11ade 100644
--- a/libmailutils/string/Makefile.am
+++ b/libmailutils/string/Makefile.am
@@ -18,13 +18,18 @@
 noinst_LTLIBRARIES = libstring.la
 
 libstring_la_SOURCES = \
+ cpystr.c\
  cstrcasecmp.c\
+ cstrcasestr.c\
  cstrlower.c\
  cstrupper.c\
+ hexstr.c\
  strltrim.c\
  strskip.c\
  stripws.c\
  strrtrim.c\
+ trueans.c\
+ unfold.c\
  asnprintf.c\
  asprintf.c\
  muctype.c\
diff --git a/libmailutils/diag/dbgsyslog.c b/libmailutils/string/cpystr.c
similarity index 60%
copy from libmailutils/diag/dbgsyslog.c
copy to libmailutils/string/cpystr.c
index af6f2fe..9671c70 100644
--- a/libmailutils/diag/dbgsyslog.c
+++ b/libmailutils/string/cpystr.c
@@ -1,6 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 Free Software
-   Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -16,18 +16,25 @@
    Public License along with this library.  If not, see 
    <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
+#if HAVE_CONFIG_H
 # include <config.h>
 #endif
 
-#include <mailutils/debug.h>
-#include <syslog.h>
+#include <string.h>
+#include <mailutils/util.h>
 
-int
-mu_debug_syslog_printer (void *unused, mu_log_level_t level, const char *str)
+/* Smart strncpy that always add the null and returns the number of bytes
+   written.  */
+size_t
+mu_cpystr (char *dst, const char *src, size_t size)
 {
-  syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str);
-  return 0;
+  size_t len = src ? strlen (src) : 0 ;
+  if (dst == NULL || size == 0)
+    return len;
+  if (len >= size)
+    len = size - 1;
+  memcpy (dst, src, len);
+  dst[len] = '\0';
+  return len;
 }
 
-
diff --git a/libmailutils/string/cstrcasestr.c 
b/libmailutils/string/cstrcasestr.c
new file mode 100644
index 0000000..7f20e08
--- /dev/null
+++ b/libmailutils/string/cstrcasestr.c
@@ -0,0 +1,101 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <unistd.h>
+#include <mailutils/cctype.h>
+
+/* Based on strstr from GNU libc (Stephen R. van den Berg,
+   address@hidden) */
+char *
+mu_c_strcasestr (const char *a_haystack, const char *a_needle)
+{
+  register const unsigned char *haystack = (unsigned char*) a_haystack,
+    *needle = (unsigned char*) a_needle;
+  register unsigned int b, c;
+
+#define U(c) mu_toupper (c)
+  if ((b = U (*needle)))
+    {
+      haystack--;              
+      do
+       {
+         if (!(c = *++haystack))
+           goto ret0;
+       }
+      while (U (c) != b);
+
+      if (!(c = *++needle))
+       goto foundneedle;
+
+      c = U (c);
+      ++needle;
+      goto jin;
+
+      for (;;)
+        { 
+          register unsigned int a;
+         register const unsigned char *rhaystack, *rneedle;
+
+         do
+           {
+             if (!(a = *++haystack))
+               goto ret0;
+             if (U (a) == b)
+               break;
+             if (!(a = *++haystack))
+               goto ret0;
+shloop:       ;
+            }
+          while (U (a) != b);
+         
+jin:     if (!(a = *++haystack))
+           goto ret0;
+
+         if (U (a) != c)
+           goto shloop;
+
+         if (U (*(rhaystack = haystack-- + 1)) ==
+             (a = U (*(rneedle = needle))))
+           do
+             {
+               if (!a)
+                 goto foundneedle;
+               if (U (*++rhaystack) != (a = U (*++needle)))
+                 break;
+               if (!a)
+                 goto foundneedle;
+             }
+           while (U (*++rhaystack) == (a = U (*++needle)));
+
+         needle = rneedle;
+
+         if (!a)
+           break;
+        }
+    }
+foundneedle:
+  return (char*)haystack;
+ret0:
+  return NULL;
+
+#undef U
+}  
diff --git a/libmailutils/diag/dbgsyslog.c b/libmailutils/string/hexstr.c
similarity index 52%
copy from libmailutils/diag/dbgsyslog.c
copy to libmailutils/string/hexstr.c
index af6f2fe..dd22fb8 100644
--- a/libmailutils/diag/dbgsyslog.c
+++ b/libmailutils/string/hexstr.c
@@ -1,6 +1,6 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 1999, 2000, 2001, 2004, 2005, 2007, 2010 Free Software
-   Foundation, Inc.
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -16,18 +16,44 @@
    Public License along with this library.  If not, see 
    <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
+#if HAVE_CONFIG_H
 # include <config.h>
 #endif
 
-#include <mailutils/debug.h>
-#include <syslog.h>
+#include <unistd.h>
 
-int
-mu_debug_syslog_printer (void *unused, mu_log_level_t level, const char *str)
+/* convert a sequence of hex characters into an integer */
+
+unsigned long
+mu_hex2ul (char hex)
 {
-  syslog ((level == MU_DEBUG_ERROR) ? LOG_ERR : LOG_DEBUG, "%s", str);
-  return 0;
+  if (hex >= '0' && hex <= '9')
+   return hex - '0';
+
+  if (hex >= 'a' && hex <= 'z')
+    return hex - 'a' + 10;
+
+  if (hex >= 'A' && hex <= 'Z')
+    return hex - 'A' + 10;
+
+  return -1;
 }
 
+size_t
+mu_hexstr2ul (unsigned long *ul, const char *hex, size_t len)
+{
+  size_t r;
 
+  *ul = 0;
+
+  for (r = 0; r < len; r++)
+    {
+      unsigned long v = mu_hex2ul (hex[r]);
+
+      if (v == (unsigned long)-1)
+       return r;
+
+      *ul = *ul * 16 + v;
+    }
+  return r;
+}
diff --git a/libmailutils/string/mkfilename.c b/libmailutils/string/mkfilename.c
index ecd6dee..7bf0665 100644
--- a/libmailutils/string/mkfilename.c
+++ b/libmailutils/string/mkfilename.c
@@ -22,7 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <mailutils/alloc.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 char *
 mu_make_file_name (const char *dir, const char *file)
diff --git a/libmailutils/string/trueans.c b/libmailutils/string/trueans.c
new file mode 100644
index 0000000..b57c45c
--- /dev/null
+++ b/libmailutils/string/trueans.c
@@ -0,0 +1,58 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+   2010 Free Software Foundation, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General
+   Public License along with this library.  If not, see 
+   <http://www.gnu.org/licenses/>. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <mailutils/cctype.h>
+#include <mailutils/nls.h>
+
+int
+mu_true_answer_p (const char *p)
+{
+  if (!p)
+    return -1;
+
+  while (*p && mu_isspace (*p))
+    p++;
+
+  if (*p)
+    {
+      /* TRANSLATORS: This is a list of characters which start
+        an affirmative answer. Whenever possible, please preserve
+        'yY' in your translation, e.g., for Euskara:
+
+        msgstr "yYbB";
+      */
+      if (strchr (_("yY"), *p))
+       return 1;
+
+      /* TRANSLATORS: This is a list of characters which start
+        a negative answer. Whenever possible, please preserve
+        'nN' in your translation, e.g., for Euskara:
+
+        msgstr "nNeE";
+      */
+      else if (strchr (_("nN"), *p))
+       return 0;
+    }
+  return -1;
+}
+
diff --git a/include/mailutils/cpp/secret.h b/libmailutils/string/unfold.c
similarity index 52%
copy from include/mailutils/cpp/secret.h
copy to libmailutils/string/unfold.c
index 20afdfb..4e37e28 100644
--- a/include/mailutils/cpp/secret.h
+++ b/libmailutils/string/unfold.c
@@ -15,34 +15,57 @@
    Public License along with this library.  If not, see 
    <http://www.gnu.org/licenses/>. */
 
-#ifndef _MUCPP_SECRET_H
-#define _MUCPP_SECRET_H
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
-#include <string>
+#include <unistd.h>
 #include <errno.h>
-#include <mailutils/secret.h>
-#include <mailutils/cpp/error.h>
 
-namespace mailutils
+int
+mu_string_unfold (char *text, size_t *plen)
 {
+  char *p, *q;
+  enum uf_state { uf_init, uf_nl, uf_fold } state = uf_init;
+#define ISSPACE(c) (c == '\r' || c == ' ' || c == '\t')
+  
+  if (!text)
+    return EINVAL;
+  
+  for (p = q = text; *q; q++)
+    {
+      switch (state)
+       {
+       case uf_init:
+         if (*q == '\n')
+           state = uf_nl;
+         else
+           *p++ = *q;
+         break;
 
-class Secret
-{
- protected:
-  mu_secret_t secret;
-  bool owner;
-
- public:
-  Secret (const std::string&);
-  Secret (const char* str, size_t len);
-  Secret (const mu_secret_t);
-  ~Secret ();
-
-  std::string password ();
-  void password_unref ();
-};
+       case uf_nl:
+         if (ISSPACE (*q))
+           state = uf_fold;
+         else
+           {
+             state = uf_init;
+             *p++ = *q;
+           }
+         break;
 
+       case uf_fold:
+         if (!ISSPACE (*q))
+           {
+             *p++ = ' ';
+             *p++ = *q;
+             state = uf_init;
+           }
+         break;
+       }
+    }
+  
+  *p++ = 0;
+  if (plen)
+    *plen = p - text;
+  return 0;
 }
-
-#endif // not _MUCPP_SECRET_H
-
diff --git a/libmailutils/tests/addr.c b/libmailutils/tests/addr.c
index 64eb884..4f397df 100644
--- a/libmailutils/tests/addr.c
+++ b/libmailutils/tests/addr.c
@@ -26,7 +26,7 @@
 #include <mailutils/address.h>
 #include <mailutils/errno.h>
 #include <mailutils/kwd.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 #include <mailutils/cctype.h>
 
diff --git a/libmu_auth/ldap.c b/libmu_auth/ldap.c
index f29472e..250aa40 100644
--- a/libmu_auth/ldap.c
+++ b/libmu_auth/ldap.c
@@ -37,7 +37,7 @@
 #include "mailutils/error.h"
 #include "mailutils/errno.h"
 #include "mailutils/nls.h"
-#include "mailutils/mutil.h"
+#include "mailutils/util.h"
 #include "mailutils/stream.h"
 #include "mailutils/filter.h"
 #include "mailutils/md5.h"
diff --git a/libmu_auth/sql.c b/libmu_auth/sql.c
index e84911a..744701f 100644
--- a/libmu_auth/sql.c
+++ b/libmu_auth/sql.c
@@ -47,7 +47,7 @@
 #include <mailutils/error.h>
 #include <mailutils/errno.h>
 #include <mailutils/nls.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/sql.h>
 #include <mailutils/vartab.h>
 #include <mailutils/cstr.h>
diff --git a/libmu_cfg/ldap.c b/libmu_cfg/ldap.c
index 953fa3e..12d239e 100644
--- a/libmu_cfg/ldap.c
+++ b/libmu_cfg/ldap.c
@@ -20,7 +20,7 @@
 #endif
 #include <stdlib.h>
 #include "mailutils/libcfg.h"
-#include "mailutils/mutil.h"
+#include "mailutils/util.h"
 #include "mailutils/ldap.h"
 
 static struct mu_ldap_module_config ldap_settings;
diff --git a/libmu_cfg/sql.c b/libmu_cfg/sql.c
index daf91e9..f29bd75 100644
--- a/libmu_cfg/sql.c
+++ b/libmu_cfg/sql.c
@@ -21,7 +21,7 @@
 #include <stdlib.h>
 #include "mailutils/libcfg.h"
 #include <mailutils/sql.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 static struct mu_sql_module_config sql_settings;
 
diff --git a/libmu_cpp/mutil.cc b/libmu_cpp/mutil.cc
index 165cfa4..56f76da 100644
--- a/libmu_cpp/mutil.cc
+++ b/libmu_cpp/mutil.cc
@@ -16,7 +16,7 @@
    <http://www.gnu.org/licenses/>. */
 
 #include <cstdlib>
-#include <mailutils/cpp/mutil.h>
+#include <mailutils/cpp/util.h>
 
 using namespace mailutils;
 
diff --git a/libmu_scm/mu_scm.h b/libmu_scm/mu_scm.h
index 22956cf..0dd49b6 100644
--- a/libmu_scm/mu_scm.h
+++ b/libmu_scm/mu_scm.h
@@ -37,7 +37,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/address.h>
 #include <mailutils/registrar.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/stream.h>
 #include <mailutils/debug.h>
 #include <mailutils/attribute.h>
diff --git a/libmu_sieve/comparator.c b/libmu_sieve/comparator.c
index b23ce8a..82aa843 100644
--- a/libmu_sieve/comparator.c
+++ b/libmu_sieve/comparator.c
@@ -420,7 +420,7 @@ i_ascii_casemap_is (const char *pattern, const char *text)
 static int
 i_ascii_casemap_contains (const char *pattern, const char *text)
 {
-  return mu_strcasestr (text, pattern) != NULL;
+  return mu_c_strcasestr (text, pattern) != NULL;
 }
 
 static int
diff --git a/libproto/imap/folder.c b/libproto/imap/folder.c
index 278294c..c95c930 100644
--- a/libproto/imap/folder.c
+++ b/libproto/imap/folder.c
@@ -49,7 +49,7 @@
 #include <mailutils/tls.h>
 #include <mailutils/nls.h>
 #include <mailutils/secret.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cctype.h>
 #include <mailutils/cstr.h>
 
diff --git a/libproto/imap/mbox.c b/libproto/imap/mbox.c
index 00e8859..9869339 100644
--- a/libproto/imap/mbox.c
+++ b/libproto/imap/mbox.c
@@ -40,7 +40,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/header.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/observer.h>
 #include <mailutils/property.h>
 #include <mailutils/stream.h>
diff --git a/libproto/maildir/folder.c b/libproto/maildir/folder.c
index 19ff4b3..4fef07b 100644
--- a/libproto/maildir/folder.c
+++ b/libproto/maildir/folder.c
@@ -31,7 +31,7 @@
 #include <mailutils/sys/registrar.h>
 
 #include <maildir.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/url.h>
 #include <mailutils/sys/amd.h>
 
diff --git a/libproto/maildir/mbox.c b/libproto/maildir/mbox.c
index c182958..02b090e 100644
--- a/libproto/maildir/mbox.c
+++ b/libproto/maildir/mbox.c
@@ -58,7 +58,7 @@
 #include <mailutils/error.h>
 #include <mailutils/header.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/property.h>
 #include <mailutils/stream.h>
 #include <mailutils/url.h>
diff --git a/libproto/mailer/mbox.c b/libproto/mailer/mbox.c
index 30130a7..635e137 100644
--- a/libproto/mailer/mbox.c
+++ b/libproto/mailer/mbox.c
@@ -28,7 +28,7 @@
 #include <mailutils/property.h>
 #include <mailutils/mailer.h>
 #include <mailutils/url.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/sys/mailbox.h>
 #include <mailutils/sys/mailer.h>
 
diff --git a/libproto/mailer/smtp.c b/libproto/mailer/smtp.c
index 4db4398..72e7c7c 100644
--- a/libproto/mailer/smtp.c
+++ b/libproto/mailer/smtp.c
@@ -40,7 +40,7 @@
 #include <mailutils/iterator.h>
 #include <mailutils/message.h>
 #include <mailutils/mime.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/observer.h>
 #include <mailutils/property.h>
 #include <mailutils/stream.h>
diff --git a/libproto/mailer/smtp_auth.c b/libproto/mailer/smtp_auth.c
index b31943c..48b5a91 100644
--- a/libproto/mailer/smtp_auth.c
+++ b/libproto/mailer/smtp_auth.c
@@ -25,7 +25,7 @@
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 #include <mailutils/mailbox.h> /* Strange, mu_ticket_file is declared here */
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/auth.h>
 #include <mailutils/url.h>
 
diff --git a/libproto/mailer/smtp_ehlo.c b/libproto/mailer/smtp_ehlo.c
index 1a7caf5..6c978cf 100644
--- a/libproto/mailer/smtp_ehlo.c
+++ b/libproto/mailer/smtp_ehlo.c
@@ -24,7 +24,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 
diff --git a/libproto/mailer/smtp_gsasl.c b/libproto/mailer/smtp_gsasl.c
index d43631f..b8e2638 100644
--- a/libproto/mailer/smtp_gsasl.c
+++ b/libproto/mailer/smtp_gsasl.c
@@ -26,7 +26,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/smtp.h>
 #include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
diff --git a/libproto/mailer/smtp_mail.c b/libproto/mailer/smtp_mail.c
index c3b02de..e24989a 100644
--- a/libproto/mailer/smtp_mail.c
+++ b/libproto/mailer/smtp_mail.c
@@ -25,7 +25,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/smtp.h>
 #include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
diff --git a/libproto/mailer/smtp_mech.c b/libproto/mailer/smtp_mech.c
index c8707b8..0067842 100644
--- a/libproto/mailer/smtp_mech.c
+++ b/libproto/mailer/smtp_mech.c
@@ -26,7 +26,7 @@
 #include <mailutils/cstr.h>
 #include <mailutils/list.h>
 #include <mailutils/iterator.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/smtp.h>
 #include <mailutils/sys/smtp.h>
 
diff --git a/libproto/mailer/smtp_rcpt.c b/libproto/mailer/smtp_rcpt.c
index 30962fe..461275b 100644
--- a/libproto/mailer/smtp_rcpt.c
+++ b/libproto/mailer/smtp_rcpt.c
@@ -24,7 +24,7 @@
 #include <mailutils/errno.h>
 #include <mailutils/cctype.h>
 #include <mailutils/list.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/smtp.h>
 #include <mailutils/stream.h>
 #include <mailutils/sys/smtp.h>
diff --git a/libproto/mbox/folder.c b/libproto/mbox/folder.c
index 84633d0..7697825 100644
--- a/libproto/mbox/folder.c
+++ b/libproto/mbox/folder.c
@@ -38,7 +38,7 @@
 #include <mailutils/auth.h>
 #include <mailutils/url.h>
 #include <mailutils/stream.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/errno.h>
 #include <mailutils/debug.h>
 
diff --git a/libproto/mbox/mbox0.h b/libproto/mbox/mbox0.h
index 382294f..81012fb 100644
--- a/libproto/mbox/mbox0.h
+++ b/libproto/mbox/mbox0.h
@@ -54,7 +54,7 @@
 #include <mailutils/header.h>
 #include <mailutils/locker.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/nls.h>
 #include <mailutils/observer.h>
 #include <mailutils/property.h>
diff --git a/libproto/mh/folder.c b/libproto/mh/folder.c
index 074273f..1743ca0 100644
--- a/libproto/mh/folder.c
+++ b/libproto/mh/folder.c
@@ -34,7 +34,7 @@
 #include <mailutils/sys/folder.h>
 #include <mailutils/sys/registrar.h>
 #include <mailutils/sys/amd.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cctype.h>
 
 static int
diff --git a/libproto/mh/mbox.c b/libproto/mh/mbox.c
index bb412b7..c3e550a 100644
--- a/libproto/mh/mbox.c
+++ b/libproto/mh/mbox.c
@@ -56,7 +56,7 @@
 #include <mailutils/header.h>
 #include <mailutils/locker.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/property.h>
 #include <mailutils/stream.h>
 #include <mailutils/url.h>
diff --git a/libproto/pop/mbox.c b/libproto/pop/mbox.c
index 5bd14ca..2c406de 100644
--- a/libproto/pop/mbox.c
+++ b/libproto/pop/mbox.c
@@ -46,7 +46,7 @@
 #include <mailutils/tls.h>
 #include <mailutils/md5.h>
 #include <mailutils/io.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/cstr.h>
 #include <mailutils/cctype.h>
 #include <mailutils/opool.h>
diff --git a/maidag/maidag.h b/maidag/maidag.h
index 424df8b..6c7224d 100644
--- a/maidag/maidag.h
+++ b/maidag/maidag.h
@@ -73,7 +73,7 @@
 #include <mailutils/locker.h>
 #include <mailutils/mailbox.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/registrar.h>
 #include <mailutils/stream.h>
 #include <mailutils/url.h>
diff --git a/mail/mail.h b/mail/mail.h
index 0efe8d3..cc2de6e 100644
--- a/mail/mail.h
+++ b/mail/mail.h
@@ -70,7 +70,7 @@
 #include <mailutils/mailbox.h>
 #include <mailutils/mailer.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/registrar.h>
 #include <mailutils/stream.h>
 #include <mailutils/url.h>
diff --git a/mail/util.c b/mail/util.c
index 683fdf9..ae6625f 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -16,7 +16,7 @@
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include "mail.h"
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mime.h>
 #include <pwd.h>
 #ifdef HAVE_TERMIOS_H
diff --git a/mh/mh.h b/mh/mh.h
index 3f4566f..4ebc589 100644
--- a/mh/mh.h
+++ b/mh/mh.h
@@ -40,7 +40,7 @@
 #include <mailutils/list.h>
 #include <mailutils/iterator.h>
 #include <mailutils/address.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/stream.h>
 #include <mailutils/filter.h>
 #include <mailutils/url.h>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 30c0f15..f07b4c5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -125,20 +125,30 @@ libmailutils/cfg/format.c
 libmailutils/cfg/lexer.l
 libmailutils/cfg/parser.y
 libmailutils/cfg/gocs.c
+
 libmailutils/diag/debug.c
 libmailutils/diag/diag.c
 libmailutils/diag/errors
 libmailutils/diag/gdebug.c
+
 libmailutils/stream/file_stream.c
+
 libmailutils/filter/filter_iconv.c
+
 libmailutils/server/ipsrv.c
 libmailutils/server/msrv.c
+
 libmailutils/mailbox/message.c
+
 libmailutils/auth/mu_auth.c
+
 libmailutils/base/mutil.c
 libmailutils/base/parsedate.y
 libmailutils/base/registrar.c
 libmailutils/base/version.c
+libmailutils/base/tempfile.c
+
+libmailutils/string/trueans.c
 
 messages/messages.c
 
diff --git a/pop3d/pop3d.h b/pop3d/pop3d.h
index b93284b..39ac438 100644
--- a/pop3d/pop3d.h
+++ b/pop3d/pop3d.h
@@ -107,7 +107,7 @@ extern int expire_on_exit;
 #include <mailutils/locker.h>
 #include <mailutils/mailbox.h>
 #include <mailutils/message.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/mu_auth.h>
 #include <mailutils/nls.h>
 #include <mailutils/registrar.h>
diff --git a/python/libmu_py/libmu_py.h b/python/libmu_py/libmu_py.h
index b637858..3b1d4cf 100644
--- a/python/libmu_py/libmu_py.h
+++ b/python/libmu_py/libmu_py.h
@@ -36,7 +36,7 @@
 #include <mailutils/message.h>
 #include <mailutils/mime.h>
 #include <mailutils/mu_auth.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/nls.h>
 #include <mailutils/registrar.h>
 #include <mailutils/tls.h>
diff --git a/readmsg/readmsg.h b/readmsg/readmsg.h
index 9b12c23..e0fde21 100644
--- a/readmsg/readmsg.h
+++ b/readmsg/readmsg.h
@@ -49,7 +49,7 @@
 #include <mailutils/error.h>
 #include <mailutils/envelope.h>
 #include <mailutils/argcv.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 
 int msglist (mu_mailbox_t mbox, int show_all, int argc, char **argv, int 
**set, int *n);
 
diff --git a/sieve/sieve.c b/sieve/sieve.c
index 91adfbc..93e467a 100644
--- a/sieve/sieve.c
+++ b/sieve/sieve.c
@@ -38,7 +38,7 @@
 #include <mailutils/folder.h>
 #include <mailutils/list.h>
 #include <mailutils/mailbox.h>
-#include <mailutils/mutil.h>
+#include <mailutils/util.h>
 #include <mailutils/registrar.h>
 #include <mailutils/stream.h>
 #include <mailutils/nls.h>


hooks/post-receive
-- 
GNU Mailutils



reply via email to

[Prev in Thread] Current Thread [Next in Thread]